Skip to content

Commit

Permalink
WIP for release 0.10 #5
Browse files Browse the repository at this point in the history
  • Loading branch information
jipipayo committed Jun 21, 2016
1 parent 4842e63 commit aaa0adb
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ perl:
- 5.14
- 5.16
- 5.18

- 5.20
6 changes: 3 additions & 3 deletions META.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"abstract" : "Simple utility to find perl modules dependencies recursively in your project.",
"abstract" : "Simple utility to find perl cpan modules dependencies recursively in your project.",
"author" : [
"dani remeseiro, <jipipayo at cpan dot org<gt>"
],
"dynamic_config" : 0,
"generated_by" : "Minilla/v3.0.1, CPAN::Meta::Converter version 2.150005",
"generated_by" : "Minilla/v3.0.2, CPAN::Meta::Converter version 2.150005",
"license" : [
"perl_5"
],
Expand Down Expand Up @@ -70,7 +70,7 @@
"web" : "https://github.com/jipipayo/Dependencio"
}
},
"version" : "0.09",
"version" : "0.10",
"x_contributors" : [
"natlibfi-arlehiko <[email protected]>",
"jipipayo <[email protected]>"
Expand Down
22 changes: 8 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
<a href="https://travis-ci.org/jipipayo/Dependencio"><img src="https://travis-ci.org/jipipayo/Dependencio.svg?branch=master"></a>


# NAME

Dependencio - Simple utility to find perl modules dependencies recursively in your project.
Dependencio - Simple utility to find perl cpan modules dependencies recursively in your project.

# SYNOPSIS
cd yourawesemeproject
now run...
now just type in the console...
dependencio

this will read recursively into your project evaluating all the modules, if they are not installed, dependecio will warn you.
if you run 'dependencio -c', automagically will try to install the missing modules via cpanm

# DESCRIPTION
Dependencio will scans recursively into your project evaluating all the cpan modules declared, if they are not installed, dependecio will warn you.
if you run 'dependencio -c', automagically will try to install the missing modules via cpanm

This module aims to autodetect all the module dependencies recursively in a project.
To be used as standalone application to be part of your continous integration to deploy.
Could be added the execution of Dependencio as a post hook git, jenkins, etc.
To be used as standalone application or as a part of your continuous integration flow.
Could be added the execution of Dependencio as a post hook git, jenkins, etc. If fails returns a non zero output to be properly handled from shell.

## EXPORT

Expand All @@ -29,7 +24,6 @@ dani remeseiro, &lt;jipipayo at cpan dot org&lt;gt>

# COPYRIGHT AND LICENSE

Copyright (C) 2015 by dani remeseiro
Copyright (C) by dani remeseiro
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
it under the same terms as Perl itself.
86 changes: 55 additions & 31 deletions lib/App/Dependencio.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,95 @@ use base qw(App::Cmd::Simple);
use strict;
use warnings;
use File::Find;
use IO::File;
use Cwd;
use Data::Printer;
use Term::ANSIColor;
use List::MoreUtils qw(uniq);
use Module::Extract::Use;
use Module::CPANfile;

our $VERSION = '0.09';
my @mods_list = ();
our $VERSION = '0.10';
my $cwd;
my $opts;
my @mods_required = ();
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
[ "install|i", "Automatic installs all the missing modules via cpanm"],
[ "cpanfile|c", "Reads if exists a cpanfile in the root dir of your project and checks if are installed.
\n Checks if the modules required are included on this cpanfile"],
[ "help|h", "This help menu. (i am dependencio version $VERSION)"],
);
}



sub validate_args {
my ($self, $opt, $args) = @_;
$self->usage_error("Bad command") if @$args;
$self->usage if $opt->{help};
}



sub execute {
my ($self, $opt, $args) = @_;
our $opts = $opt;
$opts = $opt;
$self->checkDeps;
}



sub checkDeps{
my ($self, $opt) = @_;
our $cwd = getcwd();
$cwd = getcwd();
$self->_detect_cpanfile if $opts->{cpanfile};
my @dirs = ();
our $opts;
push (@dirs,$cwd);

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

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

}

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


sub _detect_cpanfile{
my ($self) = @_;
my $cpanfile = $cwd.'/cpanfile';
if(-f $cpanfile){
print STDOUT colored ['bright_yellow'], "cpanfile found on $cwd/cpanfile \n";
$self->_parse_cpanfile(@mods_not_found, @mods_required, $cpanfile);
} else {
print STDOUT colored ['bright_white'], "cpanfile NOT found on $cwd/cpanfile \n";
}
}


sub _parse_cpanfile{
my ($self,$cpanfile) = @_;
my $filec = IO::File->new($cpanfile, O_RDONLY) or die 'I can not open file ', $cpanfile, ": $!";

sub _openFiles{
our $opts;
our $cwd;
while ( my $line = $filec->getline() ){
$line=~ s/\'([^']*)\'/$1/m;
$line=~s/^\s+//;
$line=~s/;//;
while( $line =~ m/requires/g ){
$line =~ s/requires //;
print STDOUT $line;
}
}
}


sub _scan_files{
my $dir = $cwd.'/t';
my $tests = 1;
if( $dir eq $File::Find::dir and $opts->{testdirs} ){ $tests = 0; };
Expand All @@ -76,10 +102,11 @@ sub _openFiles{
my $file = $File::Find::name;

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

foreach my $module (@mods_list) {
foreach my $module (@mods_required) {
if($module =~ /\p{Uppercase}/){ #do not eval things like "warnings","strict",etc (at least one uppercase)
print STDOUT colored ['bright_green'], "required module $module found\n" if $opts->{verbose};
my $path = $module. ".pm";
$path =~ s{::}{/}g;
eval {require $path } or
Expand All @@ -100,23 +127,22 @@ __END__
=head1 NAME
Dependencio - Simple utility to find perl modules dependencies recursively in your project.
Dependencio - Simple utility to find perl cpan modules dependencies recursively in your project.
=head1 SYNOPSIS
cd yourawesemeproject
now run...
now just type in the console...
dependencio
this will read recursively into your project evaluating all the modules, if they are not installed, dependecio will warn you.
if you run 'dependencio -c', automagically will try to install the missing modules via cpanm
=head1 DESCRIPTION
Dependencio will scans recursively into your project evaluating all the cpan modules declared, if they are not installed, dependecio will warn you.
if you run 'dependencio -c', automagically will try to install the missing modules via cpanm
This module aims to autodetect all the module dependencies recursively in a project.
To be used as standalone application to be part of your continous integration to deploy.
Could be added the execution of Dependencio as a post hook git, jenkins, etc.
To be used as standalone application or as a part of your continuous integration flow.
Could be added the execution of Dependencio as a post hook git, jenkins, etc. If fails returns a non zero output to be properly handled from shell.
Expand All @@ -131,11 +157,9 @@ dani remeseiro, E<lt>jipipayo at cpan dot org<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2015 by dani remeseiro
Copyright (C) by dani remeseiro
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
it under the same terms as Perl itself.
=cut
2 changes: 1 addition & 1 deletion minil.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name = "App-Dependencio"

[release]
do_not_upload_to_cpan=true
# badges = ["travis"]
badges = ["travis"]
1 change: 1 addition & 0 deletions t/Tests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use strict; #this should be removed on parsing
use warnings; #also removed on parsing
use Tests::Lol::Cat; #some unexistent modules
use Tests::Nyan::Cat;
use Tests::Nyan::Cat;#yes, twice to test if appears only once in the parsing
use Tests::Super::Powers;

#add some weird forms of modules to clean
Expand Down

0 comments on commit aaa0adb

Please sign in to comment.