Skip to content

Instantly share code, notes, and snippets.

@dann
Created November 22, 2011 15:13
Show Gist options
  • Save dann/1385893 to your computer and use it in GitHub Desktop.
Save dann/1385893 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Carton::CLI;
our $is_depended = 0;
main();
exit;
sub main {
my $dist = $ARGV[0];
my $dependency = $ARGV[1];
check_dependency( $dist, $dependency );
report_dependency_check_result( $dist, $dependency );
}
sub check_dependency {
my ( $dist, $dependency ) = @_;
my $cli = Carton::CLI->new;
my $lock = $cli->find_lock
or $cli->error(
"Can't find carton.lock: Run `carton install` to rebuild the lock file.¥n"
);
my $tree = $cli->carton->build_tree( $lock->{modules} );
$cli->carton->walk_down_tree(
$tree,
sub {
my ( $module, $depth ) = @_;
if ( $module->{name} =‾ /$dependency/ ) {
$is_depended = 1;
}
}
);
}
sub report_dependency_check_result {
my ( $dist, $dependency ) = @_;
if ($is_depended) {
print "${dist} depends ${dependency}";
}
else {
print "${dist} doesn't depend ${dependency}";
}
}
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment