Submodules.pm

filter: Statementstmt 97.9% 96 / 98 Branchbran 69.2% 18 / 26 Conditioncond 58.3% 7 / 12 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 100% 16 / 16 Podpod 25.0% 1 / 4 totaltotal 85.8% 140 / 163 CC 20 SCAR 20.2
CC
20
Cov
89%
submodules
15.6
import
4.0
process_file
4.0
CRAP 7.5
↑ Summary Submodules/Result.pm »
1 package Submodules;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Submodules::Result ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use File::Find qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 our $VERSION = '1.0015';
10
11 2 my $names;
12
13 2 ▶sub import {
Subroutine import: called CC=4 SCAR=13.9
14 2 my $self = shift;
15 2 my $pack = caller;
16 2 my $name = shift;
17 2 ▶ if (defined($name) and length $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and length $name) 1 1 2
Condition66%2/3
defined $name and length $name
!ll&&!rl&&r
101
MC/DC50%1/2
defined $name and length $name
defined $name length $name
Truth table66%2/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
18 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶ croak "Cannot export symbol '&${pack}::$name' because it's already defined" if defined &{"${pack}::$name"};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"${pack}::$name";} 0 1 1
20 1 *{"${pack}::$name"} = \&submodules;
21 1 $names->{$pack} = $name;
22 }
23 }
24
25 2 ▶sub submodules (;*) {
Subroutine submodules: called CC=14 SCAR=27.5
Pod undocumented
26 2 my @caller = caller(0);
27 2 my $name = 'submodules';
28 2 ▶ if (exists $names->{$caller[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$names{$caller[0]}) 2 0 2
29 2 ▶ $name = $names->{$caller[0]} if length $names->{$caller[0]};
Branch: 1 branch
BranchTrueFalseTotal
if length $$names{$caller[0]} 2 0 2
30 }
31 2 my $usage = "Usage:\n $name name::space\n";
32 2 ▶ croak $usage if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 2 2
33 2 ▶ if (not defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 2 2
34 0 carp "Useless call of '$name' in void context";
35 0 return;
36 }
37 2 my $query = shift;
38 2 ▶ $query = $caller[0] unless defined $query;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $query 1 1 2
39 2 my $self = {
40 list => [],
41 caller_abs => File::Spec->rel2abs($caller[1]),
42 query => $query,
43 seen_paths => {},
44 };
45 2 bless $self, __PACKAGE__;
46 2 my @members = split /(?:::|')/, $query;
47 2 my @inc;
48 2 for my $i (@INC) {
49 20 my $abs = File::Spec->rel2abs($i);
50 20 ▶ unless (exists $self->{seen_paths}->{$abs}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"seen_paths"}{$abs}) 20 0 20
51 20 push @inc, $abs;
52 20 $self->{seen_paths}->{$abs} = 1;
53 }
54 }
55 2 for my $i (@inc) {
56 20 my $inc_dir = File::Spec->rel2abs($i);
57 20 ▶ if (-f (my $file = File::Spec->catfile($inc_dir, @members).'.pm')) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f (my $file = "File::Spec"->catfile($inc_dir, @members) . '.pm')) 4 16 20
58 4 $file = _get_abs_path($file);
59 4 my $caller = _get_abs_path($caller[1]);
60 4 ▶ $self->process_file($inc_dir, $file) unless $file eq $caller;
Branch: 1 branch
BranchTrueFalseTotal
unless $file eq $caller 4 0 4
61 }
62 20 ▶ return $self->{list}->[0] if @{$self->{list}} and not wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"list"};} and not wantarray 0 20 20
Condition33%1/3
@{$self->{"list"};} and not wantarray
!ll&&!rl&&r
0200
MC/DC0%0/2
@{$self->{"list"};} and not wantarray
@{$self->{"list"};} not wantarray
Truth table33%1/3
A and not(B)
A= @{$self->{"list"};}B= not wantarray
ABresult
0X0
100
111
63 20 ▶ if (-d (my $path = File::Spec->catfile($inc_dir, @members))) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d (my $path = "File::Spec"->catfile($inc_dir, @members))) 4 16 20
64 4 $self->process_path($inc_dir, $path);
65 }
66 }
67 2 @{$self->{list}};
68 };
69
70 1 ▶sub find {
Subroutine find: called CC=1 SCAR=0.0
Pod documented
71 1 my $self = shift;
72 1 goto &submodules;
73 }
74
75 4 ▶sub process_path {
Subroutine process_path: called CC=1 SCAR=0.0
Pod undocumented
76 4 my $self = shift;
77 4 my $path_abs = shift;
78 4 my $path = shift;
79 File::Find::find (
80 {
81 no_chdir => 1,
82 8 ▶ preprocess => sub { # Introduced after seeing the directory contents order behave unexpectedly on some file systems
Subroutine __ANON__: called CC=1 SCAR=0.0
83 8 my @items = sort {$a cmp $b} @_;
84 },
85 28 ▶ wanted => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
86 28 $self->process_file($path_abs, $File::Find::name)
87 },
88 },
89 4 $path,
90 );
91 }
92
93 32 ▶sub process_file {
Subroutine process_file: called CC=4 SCAR=13.9
Pod undocumented
94 32 my $self = shift;
95 32 my $path_abs = shift;
96 32 my $file = shift;
97 32 ▶ return unless $file =~ /(\.pm)$/i and -f $file and my $extension = $1;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /(\.pm)$/i and -f $file and my $extension = $1 8 24 32
Condition66%4/6
$file =~ /(\.pm)$/i and -f $file and my $extension = $1
!ll&&!rl&&r
8024
$file =~ /(\.pm)$/i and -f $file
!ll&&!rl&&r
8024
MC/DC33%1/3
$file =~ /(\.pm)$/i and -f $file and my $extension = $1
$file =~ /(\.pm)$/i -f $file my $extension = $1
Truth table50%2/4
A and B and C
A= $file =~ /(\.pm)$/iB= -f $fileC= my $extension = $1
ABCresult
0XX0
10X0
1100
1111
98 24 my $file_abs = File::Spec->rel2abs($file);
99 24 my $file_rel = File::Spec->abs2rel($file_abs);
100 24 my $filename = basename $file_abs;
101 24 my @parts_path = File::Spec->splitdir($path_abs);
102 24 my @parts = File::Spec->splitdir($file_abs);
103 24 splice @parts, 0, scalar @parts_path;
104 24 $parts[$#parts] = substr $parts[$#parts], 0, - length $extension;
105 24 my $code_path = join '::', @parts;
106 24 my $perl_path = join('/', @parts).$extension;
107 24 my $name = $parts[$#parts];
108 24 push @{$self->{list}}, Submodules::Result->new (
109 Name => $name,
110 AbsPath => $file_abs,
111 RelPath => $file_rel,
112 Path => $perl_path,
113 24 Clobber => $self->{seen_paths}->{$name},
114 Module => $code_path,
115 );
116 24 $self->{seen_paths}->{$name} = $file_abs;
117 }
118
119 8 ▶sub _get_abs_path {
Subroutine _get_abs_path: called CC=1 SCAR=0.0
120 8 my $path = shift;
121 8 my @parts = File::Spec->splitdir($path);
122 8 my $file = File::Spec->catfile(@parts);
123 8 File::Spec->rel2abs($file);
124 }
125
126 2 1;
127
128 __END__
↑ Summary Submodules/Result.pm »