CLI/Base.pm

filter: Statementstmt 15.7% 12 / 76 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 22.2% 4 / 18 Podpod n/a totaltotal 11.2% 16 / 142 CC 21 SCAR 35.7
CC
21
Cov
11%
file_in_dir
90.0
build_from_opts
56.0
files_from_dirs
20.0
CRAP 35.6
↑ Summary CLI/Command/compile.pm »
1 #!/usr/bin/perl
2  
3 package MooseX::Compile::CLI::Base;
4 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 extends qw(MooseX::App::Cmd::Command);
7  
8 2 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use MooseX::AttributeHelpers;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use MooseX::Types::Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 has verbose => (
13 documentation => "Print additional information while running.",
14 metaclass => "Getopt",
15 cmd_aliases => ["v"],
16 isa => "Bool",
17 is => "rw",
18 default => 0,
19 );
20  
21 has force => (
22 documentation => "Process without asking.",
23 metaclass => "Getopt",
24 cmd_aliases => ["f"],
25 isa => "Bool",
26 is => "rw",
27 default => 0,
28 );
29  
30 has dirs => (
31 documentation => "Directories to process recursively.",
32 #traits => [qw(Getopt Collection::Array)],
33 metaclass => "Getopt",
34 cmd_aliases => ["d"],
35 isa => "ArrayRef",
36 is => "rw",
37 auto_deref => 1,
38 coerce => 1,
39 default => sub { [] },
40 #provides => {
41 # push => "add_to_dirs",
42 #},
43 );
44  
45 0 ▶sub add_to_dirs {
Subroutine add_to_dirs: not called CC=1 SCAR=6.9
46 0 my ( $self, @blah ) = @_;
47 0 push @{ $self->dirs }, @blah;
48 }
49  
50 has classes => (
51 documentation => "Specific classes to process in 'inc'",
52 #traits => [qw(Getopt Collection::Array)],
53 metaclass => "Getopt",
54 cmd_aliases => ["c"],
55 isa => "ArrayRef[Str]",
56 is => "rw",
57 auto_deref => 1,
58 coerce => 1,
59 default => sub { [] },
60 provides => {
61 push => "add_to_classes",
62 },
63 );
64  
65 0 ▶sub add_to_classes {
Subroutine add_to_classes: not called CC=1 SCAR=6.9
66 0 my ( $self, @blah ) = @_;
67 0 push @{ $self->classes }, @blah;
68 }
69  
70 override usage_desc => sub {
71 super() . " [classes and dirs...]"
72 };
73  
74 has perl_inc => (
75 documentation => "Also include '\@INC' in the 'inc' dirs. Defaults to true.",
76 isa => "Bool",
77 is => "rw",
78 default => 1,
79 );
80  
81 has local_lib => (
82 documentation => "Like specifying '-I lib'",
83 metaclass => "Getopt",
84 cmd_aliases => ["l"],
85 isa => "Bool",
86 is => "rw",
87 default => 0,
88 );
89  
90 has local_test_lib => (
91 documentation => "Like specifying '-I t/lib'",
92 metaclass => "Getopt",
93 cmd_aliases => ["t"],
94 isa => "Bool",
95 is => "rw",
96 default => 0,
97 );
98  
99 has inc => (
100 documentation => "Library include paths in which specified classes are searched.",
101 #traits => [qw(Getopt Collection::Array)],
102 metaclass => "Getopt",
103 cmd_aliases => ["I"],
104 isa => "ArrayRef",
105 is => "rw",
106 auto_deref => 1,
107 coerce => 1,
108 default => sub { [] },
109 #provides => {
110 # push => "add_to_inc",
111 #},
112 );
113  
114 0 ▶sub add_to_inc {
Subroutine add_to_inc: not called CC=1 SCAR=6.9
115 0 my ( $self, @blah ) = @_;
116 0 push @{ $self->inc }, @blah;
117 }
118  
119 0 ▶sub file_in_dir {
Subroutine file_in_dir: not called CC=9 SCAR=45.0
120 0 my ( $self, %args ) = @_;
121  
122 0 ▶ my $dir = $args{dir} || die "dir is required";
Condition0%0/2
$args{'dir'} || die('dir is required')
l!l
00
MC/DC0%0/1
$args{'dir'} || die('dir is required')
$args{'dir'}
Truth table0%0/2
A
A= $args{'dir'}
Aresult
11
00
123  
124 0 ▶ my $file = $args{file} ||= ($args{rel} || die "either 'file' or 'rel' is required")->absolute($dir);
Condition0%0/5
$args{"file"} ||= ($args{"rel"} || die("either 'file' or 'rel' is required"))->absolute($dir)
l!l&&r!l&&!r
000
$args{'rel'} || die(q[either 'file' or 'rel' is required])
l!l
00
MC/DC0%0/2
$args{"file"} ||= ($args{"rel"} || die("either 'file' or 'rel' is required"))->absolute($dir)
$args{"file"} ($args{"rel"} || die("either 'file' or 'rel' is required"))->absolute($dir)
MC/DC0%0/1
$args{'rel'} || die(q[either 'file' or 'rel' is required])
$args{'rel'}
Truth table0%0/3
A ||= B
A= $args{"file"}B= ($args{"rel"} || die("either 'file' or 'rel' is required"))->absolute($dir)
ABresult
1X1
011
000
Truth table0%0/2
A
A= $args{'rel'}
Aresult
11
00
125 0 ▶ -f $file or die "file '$file' does not exist";
Branch: 1 branch
BranchTrueFalseTotal
-f $file or die "file '${file}' does not exist" 0 0 0
126  
127 0 ▶ my $rel = $args{rel} ||= $args{file}->relative($dir);
Condition0%0/3
$args{"rel"} ||= $args{"file"}->relative($dir)
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"rel"} ||= $args{"file"}->relative($dir)
$args{"rel"} $args{"file"}->relative($dir)
Truth table0%0/3
A ||= B
A= $args{"rel"}B= $args{"file"}->relative($dir)
ABresult
1X1
011
000
128 0 ▶ $rel->is_absolute and die "rel is not relative";
Branch: 1 branch
BranchTrueFalseTotal
$rel->is_absolute and die "rel is not relative" 0 0 0
129  
130 0 ▶ $args{class} ||= do {
Condition0%0/3
$args{"class"} ||= do { my $basename = $rel->basename; $basename =~ s/\.(?:pmc?|mopc)$//; $rel->dir->cleanup eq dir() ? $basename : join("::", $rel->dir->dir_list, $basename) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"class"} ||= do { my $basename = $rel->basename; $basename =~ s/\.(?:pmc?|mopc)$//; $rel->dir->cleanup eq dir() ? $basename : join("::", $rel->dir->dir_list, $basename) }
$args{"class"} do { my $basename = $rel->basename; $basename =~ s/\.(?:pmc?|mopc)$//; $rel->dir->cleanup eq dir() ? $basename : join("::", $rel->dir->dir_list, $basename) }
Truth table0%0/3
A ||= B
A= $args{"class"}B= do { my $basename = $rel->basename; $basename =~ s/\.(?:pmc?|mopc)$//; $rel->dir->cleanup eq dir() ? $basename : join("::", $rel->dir->dir_list, $basename) }
ABresult
1X1
011
000
131 0 my $basename = $rel->basename;
132 0 $basename =~ s/\.(?:pmc?|mopc)$//;
133  
134 0 ▶ $rel->dir->cleanup eq dir()
Branch: 1 branch
BranchTrueFalseTotal
$rel->dir->cleanup eq dir() ? : 0 0 0
135 ? $basename
136 : join( "::", $rel->dir->dir_list, $basename );
137 };
138  
139 0 return \%args;
140 }
141  
142 0 ▶sub filter_file {
Subroutine filter_file: not called CC=1 SCAR=6.9
143 0 die "abstract method";
144 }
145  
146 0 ▶sub class_to_filename {
Subroutine class_to_filename: not called CC=1 SCAR=6.9
147 0 my ( $self, $class ) = @_;
148  
149 0 ( my $file = "$class.pm" ) =~ s{::}{/}g;
150  
151 0 return $file;
152 }
153  
154 0 ▶sub run {
Subroutine run: not called CC=1 SCAR=6.9
155 0 my ( $self, $opts, $args ) = @_;
156  
157 0 $self->build_from_opts( $opts, $args );
158  
159 0 inner();
160 }
161  
162 0 ▶sub build_from_opts {
Subroutine build_from_opts: not called CC=7 SCAR=40.3
163 0 my ( $self, $opts, $args ) = @_;
164  
165 0 foreach my $arg ( @$args ) {
166 0 ▶ if ( -d $arg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $arg) { } 0 0 0
167 0 $self->add_to_dirs($arg);
168 } else {
169 0 $self->add_to_classes($arg);
170 }
171 }
172  
173 0 @$args = ();
174  
175 0 ▶ $self->add_to_inc( dir("lib") ) if $self->local_lib;
Branch: 1 branch
BranchTrueFalseTotal
if $self->local_lib 0 0 0
176 0 ▶ $self->add_to_inc( dir(qw(t lib)) ) if $self->local_test_lib;
Branch: 1 branch
BranchTrueFalseTotal
if $self->local_test_lib 0 0 0
177  
178 0 ▶ $self->add_to_inc( @INC ) if $self->perl_inc;
Branch: 1 branch
BranchTrueFalseTotal
if $self->perl_inc 0 0 0
179  
180 0 inner();
181  
182 0 $_ = dir($_) for @{ $self->dirs }, @{ $self->inc };
183 };
184  
185 0 ▶sub all_files {
Subroutine all_files: not called CC=1 SCAR=6.9
186 0 my $self = shift;
187  
188 return (
189 0 $self->files_from_dirs( $self->dirs ),
190 $self->files_from_classes( $self->classes ),
191 );
192 }
193  
194  
195 0 ▶sub files_from_dirs {
Subroutine files_from_dirs: not called CC=4 SCAR=30.0
196 0 my ( $self, @dirs ) = @_;
197 0 ▶ return unless @dirs;
Branch: 1 branch
BranchTrueFalseTotal
unless @dirs 0 0 0
198  
199 0 my @files;
200  
201 0 foreach my $dir ( @dirs ) {
202 0 ▶ warn "Searching recursively in $dir\n" if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
203 $dir->recurse(
204 0 ▶ callback => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
205 0 my $file = shift;
206 0 ▶ push @files, $self->file_in_dir( file => $file, dir => $dir ) if !$file->is_dir and $self->filter_file($file);
Branch: 1 branch
BranchTrueFalseTotal
if not $file->is_dir and $self->filter_file($file) 0 0 0
Condition0%0/3
not $file->is_dir and $self->filter_file($file)
!ll&&!rl&&r
000
MC/DC0%0/2
not $file->is_dir and $self->filter_file($file)
not $file->is_dir $self->filter_file($file)
Truth table0%0/3
not(A) and B
A= not $file->is_dirB= $self->filter_file($file)
ABresult
0X0
100
111
207 },
208 0 );
209 }
210  
211 0 return @files;
212 }
213  
214 0 ▶sub files_from_classes {
Subroutine files_from_classes: not called CC=1 SCAR=6.9
215 0 my ( $self, @classes ) = @_;
216  
217 0 my @files = map { { class => $_, rel => file($self->class_to_filename($_)) } } @classes;
218  
219 0 $self->files_in_includes(@files);
220 }
221  
222 0 ▶sub files_in_includes {
Subroutine files_in_includes: not called CC=1 SCAR=6.9
223 0 my ( $self, @files ) = @_;
224  
225 0 map { $self->file_in_includes($_) } @files;
226 }
227  
228 0 ▶sub file_in_includes {
Subroutine file_in_includes: not called CC=2 SCAR=17.9
229 0 my ( $self, $file ) = @_;
230  
231 0 my @matches = grep { $self->filter_file( $_->file($file->{rel}) ) } $self->inc;
232  
233 0 ▶ die "No file found for $file->{class}\n" unless @matches;
Branch: 1 branch
BranchTrueFalseTotal
unless @matches 0 0 0
234  
235 0 map { $self->file_in_dir( %$file, dir => $_ ) } @matches;
236 }
237  
238 __PACKAGE__
239  
240 __END__
↑ Summary CLI/Command/compile.pm »