line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Dependencio; |
2
|
1
|
|
|
1
|
|
15335
|
use base qw(App::Cmd::Simple); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
644
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
35708
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
19
|
|
6
|
1
|
|
|
1
|
|
3
|
use File::Find; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
7
|
1
|
|
|
1
|
|
3
|
use Cwd; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
8
|
1
|
|
|
1
|
|
631
|
use Data::Dumper; |
|
1
|
|
|
|
|
5524
|
|
|
1
|
|
|
|
|
54
|
|
9
|
1
|
|
|
1
|
|
450
|
use IO::File; |
|
1
|
|
|
|
|
7404
|
|
|
1
|
|
|
|
|
98
|
|
10
|
1
|
|
|
1
|
|
32203
|
use Term::ANSIColor; |
|
1
|
|
|
|
|
68930
|
|
|
1
|
|
|
|
|
119
|
|
11
|
1
|
|
|
1
|
|
886
|
use Text::Trim; |
|
1
|
|
|
|
|
711
|
|
|
1
|
|
|
|
|
74
|
|
12
|
1
|
|
|
1
|
|
749
|
use Module::Load; |
|
1
|
|
|
|
|
2273
|
|
|
1
|
|
|
|
|
11
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
14
|
|
|
|
|
|
|
my @mods_not_found = (); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub opt_spec { |
17
|
|
|
|
|
|
|
return ( |
18
|
0
|
|
|
0
|
1
|
|
[ "testdirs|t", "Exclude dir named t (tests)" ], |
19
|
|
|
|
|
|
|
[ "verbose|v", "Verbose output"], |
20
|
|
|
|
|
|
|
[ "cpanm|c", "Automatic cpanm install missing modules"], |
21
|
|
|
|
|
|
|
# [ "cpanfile|f", "outputs a list of modules to a cpanfile file"], |
22
|
|
|
|
|
|
|
[ "help|h", "This help menu. (i am dependencio version $VERSION)"], |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub validate_args { |
29
|
0
|
|
|
0
|
1
|
|
my ($self, $opt, $args) = @_; |
30
|
0
|
0
|
|
|
|
|
$self->usage_error("Bad command") if @$args; |
31
|
0
|
0
|
|
|
|
|
$self->usage if $opt->{help}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub execute { |
37
|
0
|
|
|
0
|
1
|
|
my ($self, $opt, $args) = @_; |
38
|
0
|
|
|
|
|
|
our $opts = $opt; |
39
|
0
|
|
|
|
|
|
$self->checkDeps; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub checkDeps{ |
45
|
0
|
|
|
0
|
0
|
|
my ($self, $opt) = @_; |
46
|
0
|
|
|
|
|
|
our $cwd = getcwd(); |
47
|
0
|
|
|
|
|
|
my @dirs = (); |
48
|
0
|
|
|
|
|
|
our $opts; |
49
|
0
|
|
|
|
|
|
push (@dirs,$cwd); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#print Dumper(@mods_not_found); |
52
|
0
|
|
|
|
|
|
print STDOUT colored ['bright_blue'], "Dependencio says: searching modules...\n"; |
53
|
0
|
|
|
|
|
|
find(\&_openFiles, @dirs); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
foreach my $mod_not_found (@mods_not_found){ |
58
|
0
|
|
|
|
|
|
print STDOUT colored ['bright_red'], "Dependencio says: module $mod_not_found not found\n"; |
59
|
0
|
0
|
|
|
|
|
system "cpanm $mod_not_found" if $opts->{cpanm}; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
exit -1 if @mods_not_found; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _openFiles{ |
70
|
0
|
|
|
0
|
|
|
our $opts; |
71
|
0
|
|
|
|
|
|
our $cwd; |
72
|
0
|
|
|
|
|
|
my $dir = $cwd.'/t'; |
73
|
0
|
|
|
|
|
|
my $tests = 1; |
74
|
0
|
0
|
0
|
|
|
|
if( $dir eq $File::Find::dir and $opts->{testdirs} ){ |
75
|
0
|
|
|
|
|
|
$tests = 0; |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#only open file types to search module declarations (.pm and .pl) |
80
|
0
|
0
|
0
|
|
|
|
if(-f && m/\.(pm|pl)$/ and $tests == 1){ |
|
|
|
0
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
print STDOUT "* checking dependecies on $File::Find::name\n" if $opts->{verbose}; |
82
|
0
|
|
|
|
|
|
my $file = $File::Find::name; |
83
|
0
|
0
|
|
|
|
|
my $fh = IO::File->new($file, O_RDONLY) or die 'I can not open file ', $file, ": $!"; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
while ( my $line = $fh->getline() ){ |
87
|
|
|
|
|
|
|
#remove comments at the end of line like: use Foo::Bar; #this is foo |
88
|
0
|
|
|
|
|
|
$line=~s/#.*$//; |
89
|
|
|
|
|
|
|
#remove exports of func modules like: use Foo::Bar qw(meh) |
90
|
0
|
|
|
|
|
|
$line=~s/qw\(.*$//; |
91
|
|
|
|
|
|
|
#remove spaces at beginning and end of line and semicolon |
92
|
0
|
|
|
|
|
|
$line=~s/^\s+//; |
93
|
0
|
|
|
|
|
|
$line=~s/\s+$//; |
94
|
0
|
|
|
|
|
|
$line=~s/;//; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
while( $line =~ m/(use |require )[A-Z]{1}/g ){ |
97
|
0
|
|
|
|
|
|
$line=~s/(use |require )//; |
98
|
0
|
|
|
|
|
|
$line = trim($line); |
99
|
0
|
|
|
|
|
|
eval{ load $line }; |
|
0
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
if($@) { |
101
|
0
|
0
|
|
|
|
|
push( @mods_not_found, $line) unless grep{$_ eq $line} @mods_not_found; |
|
0
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
$fh->close; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |