App-Dependencio

 view release on metacpan or  search on metacpan

lib/App/Dependencio.pm  view on Meta::CPAN

use warnings;
use File::Find;
use Cwd;
use Data::Printer;
use Term::ANSIColor;
use List::MoreUtils qw(uniq);
use Module::Extract::Use;

our $VERSION = '0.09';
my @mods_list = ();
my @mods_not_found = ();

sub opt_spec {
    return (
        [ "testdirs|t",  "Exclude dir named t (tests)" ],
        [ "verbose|v",  "Verbose output"],
        [ "cpanm|c",  "Automatic cpanm install missing modules"],
        # [ "cpanfile|f",  "outputs a list of modules to a cpanfile file"], #TODO
        [ "help|h",  "This help menu. (i am dependencio version $VERSION)"],
    );
}

lib/App/Dependencio.pm  view on Meta::CPAN

sub checkDeps{
    my ($self, $opt) = @_;
    our $cwd  = getcwd();
    my @dirs = ();
    our $opts;
    push (@dirs,$cwd);

    print STDOUT colored ['bright_blue'], "Searching modules dependencies recursively from $cwd \n";
    find(\&_openFiles, @dirs);

    #p(@mods_not_found);
    foreach my $mod_not_found (uniq(@mods_not_found)){
        print STDOUT colored ['bright_red'], "module $mod_not_found not found\n";
        system "cpanm $mod_not_found" if $opts->{cpanm};

    }

    exit -1 if @mods_not_found or print STDOUT colored ['bright_green'], "success! all dependencies met...\n";
}



sub _openFiles{
    our $opts;
    our $cwd;
    my $dir = $cwd.'/t';
    my $tests = 1;
    if( $dir eq $File::Find::dir and $opts->{testdirs} ){ $tests = 0; };

lib/App/Dependencio.pm  view on Meta::CPAN

        my $extractor = Module::Extract::Use->new;
        @mods_list = $extractor->get_modules($file);

        foreach my $module  (@mods_list) {
            if($module =~ /\p{Uppercase}/){ #do not eval things like "warnings","strict",etc (at least one uppercase)
                my $path = $module. ".pm";
                $path =~ s{::}{/}g;
                eval {require $path } or
                do {
                   my $error = $@;
                   push( @mods_not_found, $module) unless grep{$_ eq $module} @mods_not_found;
                }
            }

        }
    }
}
1;



minil.toml  view on Meta::CPAN

name = "App-Dependencio"

[release]
do_not_upload_to_cpan=true
# badges = ["travis"]



( run in 0.283 second using v1.01-cache-2.11-cpan-4d4bc49f3ae )