blib/lib/Dependencies/Searcher.pm

filter: Statementstmt 81.9% 145 / 177 Branchbran 65.0% 26 / 40 Conditioncond 85.1% 23 / 27 MC/DCmcdc 66.6% 8 / 12 Subroutinesub 92.8% 26 / 28 Podpod 100% 11 / 11 totaltotal 81.0% 239 / 295 CC 36 SCAR 17.6
CC
36
Cov
80%
dissociate
13.3
uniq
12.0
avoid_superfluous
10.0
CRAP 5.8
↑ Summary
1 package Dependencies::Searcher;
2  
3 8 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use Data::Printer;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use feature qw(say);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # Be careful, even if the Module::Corelist module is available since v5.8.9
7 # the is_core() method is only available since 2.99 module's version :)
8 # http://neilb.org/2013/09/21/adding-is-core.html
9 8 ▶use Module::CoreList;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use Module::Version 'get_version';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use IO::File; # This comment creates a bug
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use File::HomeDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use Version::Compare;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 8 ▶use ExtUtils::Installed;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 8 ▶use File::Next;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 8 ▶use PPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶use Term::ANSIColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 # For test only during dev
22 #use Dependencies::Searcher;
23  
24 8 our $VERSION = '0.066_005';
25  
26 =head1 NAME
27  
28 Dependencies::Searcher - Search for modules used by a distribution.
29  
30 =cut
31  
32 =head1 SYNOPSIS
33  
34 use Dependencies::Searcher;
35  
36 my $searcher = Dependencies::Searcher->new();
37 my @elements = $searcher->get_files();
38 my @uses = $searcher->get_modules($path, "use");
39 my @uniq_modules = $searcher->uniq(@uses);
40  
41 $searcher->dissociate(@uniq_modules);
42  
43 $searcher->generate_report($searcher->non_core_modules);
44  
45 # Prints to cpanfile
46 # requires 'Data::Printer', '0.35';
47 # requires Moose, '2.0602';
48 # requires IPC::Cmd;
49 # requires Module::Version;
50 # ...
51  
52 Synopsis from Dependencies::Searcher::AckRequester
53  
54 # Places to search...
55 my @path = ("./lib", "./Makefile.PL", "./script");
56  
57 # Params for Ack
58 my @params = ('--perl', '-hi', $pattern, @path);
59  
60 # Absolute path to the Ack binary
61 my $ack_path = $requester->get_path();
62  
63 # Build the command for IPC::Cmd
64 my $cmd_use = $requester->build_cmd(@params);
65  
66 # Execute the command and retrieve the output
67 my @moduls = $requester->search($cmd_use);
68  
69 =cut
70  
71 =head1 DESCRIPTION
72  
73 Maybe you don't want to have to list all the dependencies of your Perl
74 application by hand and want an automated way to retrieve this
75 list. It can also be handy sometimes to check if your Makefile.PL
76 contains all the prerequisite that are needed for your distribution.
77  
78 This module's aim is to keep track of the list of modules your
79 distribution need, under the form of a L<cpanfile|cpanfile>.
80  
81 Dependencies::Searcher will check for any I<requires> or I<use> in
82 your module repository, and report it into a cpanfile. Any duplicated
83 entry will be removed and modules versions will be checked and made
84 available. Core modules will be ommited because you don't need to
85 install them (except in some special cases, see C<dissociate()>
86 documentation).
87  
88 This project has begun because I was sometimes forgetting to keep
89 track of my dependencies, and I just wanted to run a simple script
90 that updated the list in a convenient way.
91  
92 =cut
93  
94 =head1 Not a dependencies-tree tool
95  
96 Dependencies::Searcher only finds direct dependencies, not
97 dependencies of dependencies, it scans recursively directories of your
98 module to find declared dependencies.
99  
100 Once you generated a cpanfile with Dependencies::Searcher, it's
101 possible to pass this list to the Perl toolchain (cpanminus)
102 that will take care of any recursive dependencies.
103  
104 =cut
105  
106 # Init parameters
107 has 'non_core_modules' => (
108 traits => ['Array'],
109 is => 'rw',
110 isa => 'ArrayRef[Str]',
111 6 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
112 8 handles => {
113 add_non_core_module => 'push',
114 count_non_core_modules => 'count',
115 },
116 );
117  
118 has 'core_modules' => (
119 traits => ['Array'],
120 is => 'rw',
121 isa => 'ArrayRef[Str]',
122 6 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
123 8 handles => {
124 add_core_module => 'push',
125 count_core_modules => 'count',
126 },
127 );
128  
129 8 has 'full_path' => (
130 is => 'rw',
131 isa => 'Str',
132 );
133  
134  
135 2 ▶sub get_modules {
Subroutine get_modules: called CC=4 SCAR=14.5
Pod documented
136 # @path contains files and directories
137 2 my ($self, $pattern, @path) = @_;
138  
139 2 say("Search pattern : " . $pattern);
140  
141 2 my @moduls = $self->search($pattern, @path);
142 2 say("Found $pattern modules : " . @moduls);
143  
144 2 ▶ if ( defined $moduls[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $moduls[0]) { } 1 1 2
145 1 ▶ if ($moduls[0] =~ m/^use/ or $moduls[0] =~ m/^require/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($moduls[0] =~ /^use/ or $moduls[0] =~ /^require/) { } 1 0 1
Condition33%1/3
$moduls[0] =~ /^use/ or $moduls[0] =~ /^require/
l!l&&r!l&&!r
100
MC/DC0%0/2
$moduls[0] =~ /^use/ or $moduls[0] =~ /^require/
$moduls[0] =~ /^use/ $moduls[0] =~ /^require/
Truth table33%1/3
A or B
A= $moduls[0] =~ /^use/B= $moduls[0] =~ /^require/
ABresult
1X1
011
000
146 1 return @moduls;
147 } else {
148 # Not really useful since we don't use ack no more
149 0 die "Failed to retrieve modules with Ack";
150 }
151 } else {
152 1 say "No use or require found !";
153 }
154 }
155  
156 3 ▶sub get_files {
Subroutine get_files: called CC=4 SCAR=14.6
Pod documented
157 3 my $self = shift;
158 # Path::Class functions allows a more portable module
159 3 my $lib_dir = dir('lib');
160 3 my $make_file = file('Makefile.PL');
161 3 my $script_dir = dir('script');
162 # note1 t/ is ignored
163 # note2 any type of interesting file or dir should be listed here
164  
165 3 my @structure;
166  
167 3 ▶ if (-d $lib_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $lib_dir) { } 3 0 3
168 3 $structure[0] = $lib_dir;
169 } else {
170 # TODO : TEST IF THE PATH IS OK ???
171 # What can you do if a module don't have a lib/ dir ?
172 0 die "Don't look like we are working on a Perl module";
173 }
174  
175 3 ▶ if (-f $make_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $make_file) 3 0 3
176 3 $structure[1] = $make_file;
177 }
178  
179 3 ▶ if (-d $script_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $script_dir) 0 3 3
180 0 $structure[2] = $script_dir;
181 }
182  
183 3 return @structure;
184 }
185  
186 # Generate a "1" when merging if one of both is empty
187 # Will be clean in avoid_superfluous() method
188 0 ▶sub merge_dependencies {
Subroutine merge_dependencies: not called CC=1 SCAR=6.9
Pod documented
189 0 my ($self, @uses, @requires) = @_;
190 0 my @merged_dependencies = (@uses, @requires);
191 0 say("Merged use and require dependencies");
192 0 return @merged_dependencies;
193 }
194  
195 # Remove special cases that aren't need at all
196 1 ▶sub avoid_superfluous {
Subroutine avoid_superfluous: called CC=10 SCAR=23.0
Pod documented
197 1 my ($self, @merged) = @_;
198 1 my @real_modules;
199 # Push everything except the special cases that are totally useless
200 1 foreach my $module ( @merged ) {
201 9 ▶ push(@real_modules, $module) unless
Branch: 1 branch
BranchTrueFalseTotal
unless $module =~ /say/ or $module =~ /^use\s[0-9]\.[0-9]+?/ or $module =~ /^use\sautodie?/ or $module =~ /^use\swarnings/ or $module =~ /^1$/ or $module =~ /^use\sDependencies::Searcher/ or $module =~ m[/\^use\\s] or $module =~ /^use\s\\s/ 1 8 9
Condition100%21/21
$module =~ /say/ or $module =~ /^use\s[0-9]\.[0-9]+?/ or $module =~ /^use\sautodie?/ or $module =~ /^use\swarnings/ or $module =~ /^1$/ or $module =~ /^use\sDependencies::Searcher/ or $module =~ m[/\^use\\s] or $module =~ /^use\s\\s/
l!l&&r!l&&!r
711
$module =~ /say/ or $module =~ /^use\s[0-9]\.[0-9]+?/ or $module =~ /^use\sautodie?/ or $module =~ /^use\swarnings/ or $module =~ /^1$/ or $module =~ /^use\sDependencies::Searcher/ or $module =~ m[/\^use\\s]
l!l&&r!l&&!r
612
$module =~ /say/ or $module =~ /^use\s[0-9]\.[0-9]+?/ or $module =~ /^use\sautodie?/ or $module =~ /^use\swarnings/ or $module =~ /^1$/ or $module =~ /^use\sDependencies::Searcher/
l!l&&r!l&&!r
513
$module =~ /say/ or $module =~ /^use\s[0-9]\.[0-9]+?/ or $module =~ /^use\sautodie?/ or $module =~ /^use\swarnings/ or $module =~ /^1$/
l!l&&r!l&&!r
414
$module =~ /say/ or $module =~ /^use\s[0-9]\.[0-9]+?/ or $module =~ /^use\sautodie?/ or $module =~ /^use\swarnings/
l!l&&r!l&&!r
315
$module =~ /say/ or $module =~ /^use\s[0-9]\.[0-9]+?/ or $module =~ /^use\sautodie?/
l!l&&r!l&&!r
216
$module =~ /say/ or $module =~ /^use\s[0-9]\.[0-9]+?/
l!l&&r!l&&!r
117
MC/DC100%8/8
$module =~ /say/ or $module =~ /^use\s[0-9]\.[0-9]+?/ or $module =~ /^use\sautodie?/ or $module =~ /^use\swarnings/ or $module =~ /^1$/ or $module =~ /^use\sDependencies::Searcher/ or $module =~ m[/\^use\\s] or $module =~ /^use\s\\s/
$module =~ /say/ $module =~ /^use\s[0-9]\.[0-9]+?/ $module =~ /^use\sautodie?/ $module =~ /^use\swarnings/ $module =~ /^1$/ $module =~ /^use\sDependencies::Searcher/ $module =~ m[/\^use\\s] $module =~ /^use\s\\s/
Truth table100%9/9
A or B or C or D or E or F or G or H
A= $module =~ /say/B= $module =~ /^use\s[0-9]\.[0-9]+?/C= $module =~ /^use\sautodie?/D= $module =~ /^use\swarnings/E= $module =~ /^1$/F= $module =~ /^use\sDependencies::Searcher/G= $module =~ m[/\^use\\s]H= $module =~ /^use\s\\s/
ABCDEFGHresult
1XXXXXXX1
01XXXXXX1
001XXXXX1
0001XXXX1
00001XXX1
000001XX1
0000001X1
000000011
000000000
202  
203 $module =~ m/say/
204  
205 # Describes a minimal Perl version
206 # BUG #76, see above
207 or $module =~ m/^use\s[0-9]\.[0-9]+?/
208 or $module =~ m/^use\sautodie?/
209 or $module =~ m/^use\swarnings/
210 # Kind of bug generated by merge_dependencies() when there is
211 # only one array to merge
212 or $module =~ m/^1$/
213 or $module =~ m/^use\sDependencies::Searcher/
214 # Bug #76, a regex in this module created a match ("\s" module) in the
215 # patterns search
216 # https://git.framasoft.org/smonff/dependencies-searcher/issues/76
217 or $module =~ m/\/\^use\\s/
218 or $module =~m/^use\s\\s/;
219 }
220 1 return @real_modules;
221 }
222  
223 # Clean correct lines that can't be removed
224 1 ▶sub clean_everything {
Subroutine clean_everything: called CC=2 SCAR=6.9
Pod documented
225 1 my ($self, @dirty_modules) = @_;
226 1 my @clean_modules = ();
227  
228 1 foreach my $module ( @dirty_modules ) {
229  
230 26 say("Dirty module : " . $module);
231  
232 # remove the 'use' and the space next
233 26 $module =~ s{
234 use \s
235 }
236 {}xi; # Empty subtitution
237  
238 # remove the require, quotes and the space next
239 # but returns the captured module name (non-greedy)
240 # i = not case-sensitive
241 26 $module =~ s{
242 requires \s
243 '
244 (.*?)
245 '
246 }{$1}xi; # Note -> don't insert spaces here
247  
248 # Remove the ';' at the end of the line
249 26 $module =~ s/ ; //xi;
250  
251 # Remove any qw(xxxxx xxxxx) or qw[xxx xxxxx]
252 # '\(' are for real 'qw()' parenthesis not for grouping
253 # Also removes empty qw()
254  
255 # With spaces and parenthesis e.g. qw( foo bar )
256 26 $module =~ s{
257 \s qw
258 \(
259 (\s*[A-Za-z]+(\s*[A-Za-z]*))*\s*
260 \)
261 }{}xi;
262  
263 # Without spaces, with parenthesis e.g. qw(foo bar) and optionnal [method_names
264 26 $module =~ s{
265 \s qw
266 \(
267 ([A-Za-z]+(_[A-Za-z]+)*(\s*[A-Za-z]*))*
268 \)
269 }{}xi;
270  
271 # With square brackets e.g. qw[foo bar] and optionnal [method_names]
272 26 $module =~ s{
273 \s qw
274 \[
275 ([A-Za-z]+(_[A-Za-z]+)*(\s*[A-Za-z]*))*
276 \]
277 }
278 {}xi; # Empty subtitution
279 # With spaces and parenthesis e.g. qw/ foo bar /
280 26 $module =~ s{
281 \s qw
282 \/
283 (\s[A-Za-z]+(_[A-Za-z]+)*(\s*[A-Za-z]*))*\s
284 \/
285 }
286 {}xi; # Empty subtitution
287  
288 # Remove method names between quotes (those that can be used
289 # without class instantiation)
290 26 $module =~ s{
291 \s
292 '
293 [A-Za-z]+(_[A-Za-z]+)*
294 '
295 }
296 {}xi; # Empty subtitution
297  
298 # Remove dirty bases and quotes.
299 # This regex that substitute My::Module::Name
300 # to a "base 'My::Module::Name'" by capturing
301 # the name in a non-greedy way
302 26 $module =~ s{
303 base \s
304 '
305 (.*?)
306 '
307 }
308 {$1}xi;
309  
310 # Remove some warning sugar
311 26 $module =~ s{
312 ([a-z]+)
313 \s FATAL
314 \s =>
315 \s 'all'
316 }
317 {$1}xi;
318  
319 # Remove version numbers
320 # See "a-regex-for-version-number-parsing" :
321 # http://stackoverflow.com/questions/82064/
322 26 $module =~ s{
323 \s
324 (\*|\d+(\.\d+)
325 {0,2}
326 (\.\*)?)$
327 }
328 {}x;
329  
330 # Remove configuration stuff like env_debug => 'LM_DEBUG' but
331 # the quoted words have been removed before
332 26 $module =~ s{
333 \s
334 ([A-Za-z]+(_[A-Za-z]+)*( \s*[A-Za-z]*))*
335 \s
336 =>
337 }
338 {}xi;
339  
340  
341 26 say("Clean module : " . $module);
342 26 push @clean_modules, $module;
343 }
344 1 return @clean_modules;
345 }
346  
347  
348 0 ▶sub uniq {
Subroutine uniq: not called CC=3 SCAR=24.8
Pod documented
349 0 my ($self, @many_modules) = @_;
350 0 my @unique_modules = ();
351 0 my %seen = ();
352 0 foreach my $element ( @many_modules ) {
353 0 ▶ next if $seen{ $element }++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$element}++ 0 0 0
354 0 say("Uniq element added : " . $element);
355 0 push @unique_modules, $element;
356 }
357 0 return @unique_modules;
358 }
359  
360 1 ▶sub dissociate {
Subroutine dissociate: called CC=5 SCAR=25.9
Pod documented
361 1 my ($self, @common_modules) = @_;
362  
363 1 foreach my $nc_module (@common_modules) {
364  
365 6 my $core_list_answer = Module::CoreList::is_core($nc_module);
366  
367 6 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Module::CoreList::version{$]}{"$nc_module"} or $core_list_answer == 1) { } 0 6 6
Condition33%1/3
exists $Module::CoreList::version{$]}{"$nc_module"} or $core_list_answer == 1
l!l&&r!l&&!r
006
MC/DC0%0/2
exists $Module::CoreList::version{$]}{"$nc_module"} or $core_list_answer == 1
exists $Module::CoreList::version{$]}{"$nc_module"} $core_list_answer == 1
Truth table33%1/3
A or B
A= exists $Module::CoreList::version{$]}{"$nc_module"}B= $core_list_answer == 1
ABresult
1X1
011
000
368 # "$]" is Perl version
369 (exists $Module::CoreList::version{ $] }{"$nc_module"})
370 or
371 # In case module don't have a version number
372 ($core_list_answer == 1)
373 ) {
374  
375 # A module can be in core but the wanted version can be
376 # more fresh than the core one...
377 # Return the most recent version
378 0 my $mversion_version = get_version($nc_module);
379 # Return the corelist version
380 0 my $corelist_version = $Module::CoreList::version{ $] }{"$nc_module"};
381  
382 0 say("Mversion version : " . $mversion_version);
383 0 say("Corelist version : " . $corelist_version);
384  
385 # Version::Compare warns about versions numbers with '_'
386 # are 'non-numeric values'
387 0 $corelist_version =~ s/_/./;
388 0 $mversion_version =~ s/_/./;
389  
390 # It's a fix for this bug
391 # https://github.com/smonff/dependencies-searcher/issues/25
392 # Recent versions of corelist modules are not include in
393 # all Perl versions corelist
394 0 ▶ if (&Version::Compare::version_compare(
Branch: 1 branch
BranchTrueFalseTotal
if (&Version::Compare::version_compare($mversion_version, $corelist_version) == 1) 0 0 0
395 $mversion_version, $corelist_version
396 ) == 1) {
397 0 say(
398 $nc_module . " version " . $mversion_version .
399 " is in use but " .
400 $corelist_version .
401 " is in core list"
402 );
403 0 $self->add_non_core_module($nc_module);
404 0 say(
405 $nc_module .
406 " is in core but has been added to non core " .
407 "because it's a fresh core"
408 );
409 0 next;
410 }
411  
412 # Add to core_module
413  
414 # The "Moose" trait way
415 # http://metacpan.org/module/Moose::Meta::Attribute::Native::Trait::Array
416 0 $self->add_core_module($nc_module);
417 0 say($nc_module . " is core");
418  
419 } else {
420 6 $self->add_non_core_module($nc_module);
421 6 say($nc_module . " is not in core");
422 }
423 }
424 }
425  
426 # Open a file handle to > cpanfile
427 1 ▶sub generate_report {
Subroutine generate_report: called CC=5 SCAR=18.9
Pod documented
428  
429 1 my $self = shift;
430  
431 #
432 # TODO !!! Check if the module is installed already with
433 # ExtUtils::Installed. If it it not, cry that
434 # Dependencies::Searcher is designed to be used in the complete env
435 #
436  
437 1 ▶ open my $cpanfile_fh, '>', 'cpanfile' or die "Can't open cpanfile : $:!";
Branch: 1 branch
BranchTrueFalseTotal
&Dependencies::Searcher::open(my $cpanfile_fh, ">", "cpanfile") or die "Can't open cpanfile : $main:::!" 1 0 1
438  
439 1 foreach my $module_name ( @{$self->non_core_modules} ) {
440  
441 6 my $version = get_version($module_name);
442  
443 # if not undef
444 6 ▶ if ($version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version) { } 0 6 6
445 0 say("Module + version : " . $module_name . " " . $version);
446  
447 # Add the "requires $module_name\n" to the next line of the file
448 0 chomp($module_name, $version);
449  
450 0 ▶ if ($version =~ m/[0-9]\.[0-9]+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version =~ /[0-9]\.[0-9]+/) 0 0 0
451 0 say $cpanfile_fh "requires '$module_name', '$version';";
452 } # else : other case ?
453  
454 } else {
455 6 say("Module + version : " . $module_name);
456 6 say $cpanfile_fh "requires '$module_name';";
457 }
458  
459 }
460  
461 1 close $cpanfile_fh;
462 1 say("File has been generated and is waiting for you");
463 }
464  
465  
466 # under rewriting since we removed Dependencies::Searcher::AckRequester
467 3 ▶sub search {
Subroutine search: called CC=8 SCAR=20.8
Pod documented
468 3 my ($self, $pattern, @paths) = @_;
469  
470 3 my @modules;
471  
472 3 my $iter = File::Next::files(@paths);
473  
474 # Each path is a file in the chosen hierarchy
475 3 ▶ while ( defined ( my $path = $iter->() )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $path = &$iter())) 6 3 9
476  
477 6 my $namespace;
478 6 my $file = file($path);
479  
480 # We have to test that we don't include namespaces of the
481 # analyzed module
482 6 my $document = PPI::Document->new($file->stringify);
483 # Testing that the file is actually a module, not for example Makefile.PL
484 6 my $is_module = $document->find_first('PPI::Statement::Package');
485 6 ▶ if ($is_module) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_module) 3 3 6
486 3 $namespace = $is_module->namespace;
487 }
488  
489 6 my @lines = $file->slurp;
490  
491 6 for my $line (@lines) {
492  
493 # if ( $line =~ /use\\s/m ) {
494 # say "$line !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
495 #}
496  
497 # Remove carriage return
498 2742 chomp $line;
499 # Remove tabs
500 2742 $line =~ s/^\t+//;
501  
502 2742 ▶ if ($is_module) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_module) 2583 159 2742
503 # We jump to the next line if we found the analyzed
504 # package in the array of lines
505 2583 ▶ if ($line =~ /use $namespace/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /use $namespace/) 6 2577 2583
506 6 $self->coucou("Module namespace ($line) has been ommited ")
507 }
508 2583 ▶ next if $line =~ $namespace;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /$namespace/ 42 2541 2583
509 }
510  
511 2700 ▶ if ($line =~ /^$pattern\s/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^$pattern\s/) 40 2660 2700
512 40 say($line);
513  
514 # Clean the result
515 40 $line = $self->rm_comments($line);
516  
517 40 push(@modules, $line);
518 }
519 }
520 }
521  
522 # TODO retrieve modules from Makefile.PL (it cannot be based on
523 # the use of a "pattern" in this case)
524  
525 3 p @modules;
526 3 return @modules;
527 }
528  
529 # It could be a simplist implementation, but I didn't find something
530 # more clever. Comments appreciated.
531 40 ▶sub rm_comments {
Subroutine rm_comments: called CC=2 SCAR=6.9
Pod documented
532  
533 40 my ($self, $dirt) = @_;
534  
535 # Case #1: "use" declaration line with a comment after
536 # The regex add the terminal semicolon at the end of the line to
537 # make the difference between comments and code, because "use" is
538 # a word that you can find often in a POD section, more much in
539 # the beginning of line than you could think
540 40 ▶ if ( $dirt =~ /#.+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirt =~ /#.+/) 2 38 40
541 2 say("Entered rm_comment for $dirt");
542 2 $dirt =~ s/#(.*)//;
543 # Delete spaces
544 2 $dirt =~ s/\s*//xi;
545 }
546  
547 # $pattern = "$pattern" . qr/.+;$/; # <= This is an horrible bug,
548 # because we could have a
549 # comment here
550  
551 # Case #2 pod
552 # TODO
553  
554  
555 40 my $clean = $dirt;
556  
557 40 return $clean;
558 }
559  
560 6 ▶sub coucou {
Subroutine coucou: called CC=2 SCAR=7.0
Pod documented
561 6 my ($self, $thing, $color) = @_;
562 6 ▶ if (not $color) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($color) 6 0 6
563 6 $color = 'red';
564 }
565 6 say(color("$color"), $thing);
566 }
567  
568  
569 8 1;
570  
571 __END__
↑ Summary