blib/lib/App/af.pm

filter: Statementstmt 86.4% 134 / 155 Branchbran 65.7% 25 / 38 Conditioncond 46.1% 6 / 13 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 86.6% 26 / 30 Podpod 0.0% 0 / 5 totaltotal 77.5% 193 / 249 CC 28 SCAR 17.8
CC
28
Cov
80%
build
13.8
BUILDARGS
10.5
__ANON__
6.0
CRAP 5.9
« bin/af ↑ Summary corpus/lib/Alien/foo.pm »
1 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 8 package App::af 0.18 {
6  
7 8 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶ use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶ use Getopt::Long qw( GetOptionsFromArray );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶ use Pod::Usage qw( pod2usage );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: Command line tool for alienfile
13  
14  
15 has args => (
16 is => 'ro',
17 isa => 'ArrayRef[Str]',
18 0 ▶ default => sub { [] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
19 8 );
20  
21 sub BUILDARGS
22 33 ▶ {
Subroutine BUILDARGS: called CC=9 SCAR=23.5
Pod undocumented
23 33 my($class, @args) = @_;
24  
25 33 my($subcommand) = $class =~ /App::af::(.*)/;
26 33 my %args = ( args => \@args );
27  
28 my @options = (
29 0 ▶ 'help' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
30 0 ▶ pod2usage({
Branch: 1 branch
BranchTrueFalseTotal
$subcommand eq 'default' ? : 0 0 0
31 -verbose => 99,
32 -sections => $subcommand eq 'default' ? "SYNOPSIS|DESCRIPTION" : "SUBCOMMANDS/$subcommand",
33 -exitval => 0,
34 }) },
35 0 ▶ 'version' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
36 0 ▶ say "App::af version ", ($App::af::VERSION // 'dev');
Condition0%0/2
$App::af::VERSION // "dev"
l!l
00
MC/DC0%0/1
$App::af::VERSION // "dev"
$App::af::VERSION
Truth table0%0/2
A
A= $App::af::VERSION
Aresult
11
00
37 0 exit;
38 },
39 33 );
40  
41 33 foreach my $attr ($class->meta->get_all_attributes)
42 {
43 171 ▶ next unless $attr->does("App::af::opt");
Branch: 1 branch
BranchTrueFalseTotal
unless $attr->does("App::af::opt") 33 138 171
44 138 my $name = $attr->name;
45 138 $name =~ s/_/-/g;
46 138 ▶ $name .= '|' . $attr->short if $attr->short;
Branch: 1 branch
BranchTrueFalseTotal
if $attr->short 70 68 138
47 138 ▶ $name .= "=" . $attr->opt_type if $attr->opt_type;
Branch: 1 branch
BranchTrueFalseTotal
if $attr->opt_type 82 56 138
48 138 ▶ if($attr->is_array)
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->is_array) { } 6 132 138
49 {
50 6 my @array;
51 6 $args{$attr->name} = \@array;
52 6 push @options, $name => \@array;
53 }
54 else
55 {
56 132 push @options, $name => \$args{$attr->name};
57 }
58 }
59  
60 33 ▶ GetOptionsFromArray(\@args, @options)
Branch: 2 branches
BranchTrueFalseTotal
&GetOptionsFromArray(\@args, @options) or pod2usage({"-exitval", 1, "-verbose", 99, "-sections", $subcommand eq "default" ? "SYNOPSIS" : "SUBCOMMANDS/$subcommand/Usage"}) 33 0 33
$subcommand eq 'default' ? : 0 0 0
61 || pod2usage({
62 -exitval => 1,
63 -verbose => 99,
64 -sections => $subcommand eq 'default' ? 'SYNOPSIS' : "SUBCOMMANDS/$subcommand/Usage",
65 });
66  
67 33 delete $args{$_} for grep { ! defined $args{$_} } keys %args;
68  
69 33 \%args,
70 }
71  
72 sub compute_class
73 3 ▶ {
Subroutine compute_class: called CC=3 SCAR=11.0
Pod undocumented
74 3 ▶ defined $ARGV[0] && $ARGV[0] !~ /^-/
Branch: 1 branch
BranchTrueFalseTotal
defined $ARGV[0] && !($ARGV[0] =~ /^-/u) ? : 1 2 3
Condition100%3/3
defined $ARGV[0] and not $ARGV[0] =~ /^-/u
!ll&&!rl&&r
111
MC/DC100%2/2
defined $ARGV[0] and not $ARGV[0] =~ /^-/u
defined $ARGV[0] not $ARGV[0] =~ /^-/u
Truth table100%3/3
A and not(B)
A= defined $ARGV[0]B= not $ARGV[0] =~ /^-/u
ABresult
0X0
100
111
75 ? 'App::af::' . shift @ARGV
76 : 'App::af::default';
77 }
78  
79 8 requires 'main';
80 }
81  
82 8 package App::af::default 0.18 {
83  
84 8 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 8 with 'App::af';
86  
87 sub main
88 0 ▶ {
Subroutine main: not called CC=2 SCAR=17.9
Pod undocumented
89 0 ▶ say "App::af version @{[ $App::af::VERSION || 'dev' ]}";
Condition0%0/2
$App::af::VERSION || 'dev'
l!l
00
MC/DC0%0/1
$App::af::VERSION || 'dev'
$App::af::VERSION
Truth table0%0/2
A
A= $App::af::VERSION
Aresult
11
00
90 0 say " af --help for usage information";
91 0 0;
92 }
93  
94 8 __PACKAGE__->meta->make_immutable;
95 }
96  
97 8 package App::af::role::alienfile 0.18 {
98  
99 8 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 8 ▶ use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 8 ▶ use MooseX::Types::Path::Tiny qw( AbsPath );
Subroutine BEGIN: called CC=1 SCAR=0.0
102 8 ▶ use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
103 8 ▶ use File::Temp qw( tempdir );
Subroutine BEGIN: called CC=1 SCAR=0.0
104  
105 8 has file => (
106 is => 'ro',
107 isa => AbsPath,
108 traits => ['App::af::opt'],
109 short => 'f',
110 opt_type => 's',
111 default => 'alienfile',
112 coerce => 1,
113 );
114  
115 8 has class => (
116 is => 'ro',
117 isa => 'Str',
118 traits => ['App::af::opt'],
119 short => 'c',
120 opt_type => 's',
121 );
122  
123 sub build
124 23 ▶ {
Subroutine build: called CC=11 SCAR=26.3
Pod undocumented
125 23 my($self, %args) = @_;
126  
127 23 my $alienfile;
128  
129 my $prefix;
130  
131 23 ▶ $args{root} ||= tempdir( CLEANUP => 1);
Condition66%2/3
$args{"root"} ||= tempdir("CLEANUP", 1)
l!l&&r!l&&!r
2210
MC/DC0%0/2
$args{"root"} ||= tempdir("CLEANUP", 1)
$args{"root"} tempdir("CLEANUP", 1)
Truth table66%2/3
A ||= B
A= $args{"root"}B= tempdir("CLEANUP", 1)
ABresult
1X1
011
000
132  
133 23 ▶ if($self->class)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->class) { } 4 19 23
134 {
135 4 ▶ my $class = $self->class =~ /::/ ? $self->class : "Alien::" . $self->class;
Branch: 1 branch
BranchTrueFalseTotal
$self->class =~ /::/u ? : 2 2 4
136 4 my $pm = $class . '.pm';
137 4 $pm =~ s/::/\//g;
138 4 require $pm;
139 4 ▶ if($class->can('runtime_prop') && $class->runtime_prop)
Branch: 1 branch
BranchTrueFalseTotal
if ($class->can('runtime_prop') and $class->runtime_prop) { } 4 0 4
Condition33%1/3
$class->can("runtime_prop") and $class->runtime_prop
!ll&&!rl&&r
004
MC/DC0%0/2
$class->can("runtime_prop") and $class->runtime_prop
$class->can("runtime_prop") $class->runtime_prop
Truth table33%1/3
A and B
A= $class->can("runtime_prop")B= $class->runtime_prop
ABresult
0X0
100
111
140 {
141 4 my $dist = path($class->dist_dir);
142 4 $alienfile = $dist->child('_alien/alienfile');
143 4 my $patch = $dist->child('_alien/patch');
144 4 ▶ $args{patch} = $patch->stringify if -d $patch;
Branch: 1 branch
BranchTrueFalseTotal
if -d $patch 0 4 4
145 4 $prefix = $dist->stringify;
146 }
147 else
148 {
149 0 say STDERR "class @{[ $self->class ]} does not appear to have been installed using Alien::Build";
150 0 exit 2;
151 }
152 }
153 else
154 {
155 19 $alienfile = $self->file;
156 }
157  
158 23 ▶ unless(-r $alienfile)
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $alienfile) 0 23 23
159 {
160 0 say STDERR "unable to read $alienfile";
161 0 exit 2;
162 }
163  
164 23 ▶ if(my $patch = $alienfile->parent->child('patch'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $patch = $alienfile->parent->child("patch")) 23 0 23
165 {
166 23 ▶ if(-d $patch)
Branch: 1 branch
BranchTrueFalseTotal
if (-d $patch) 0 23 23
167 {
168 0 $args{patch} = "$patch";
169 }
170 }
171  
172 23 require Alien::Build;
173 23 my $build = Alien::Build->load("$alienfile", %args);
174  
175 23 ▶ wantarray ? ($build, $prefix) : $build; ## no critic (Community::Wantarray)
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 16 23
176  
177 }
178 }
179  
180 8 package App::af::role::phase 0.18 {
181  
182 8 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
183 8 ▶ use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
184  
185 8 has phase => (
186 is => 'ro',
187 isa => 'Str',
188 default => 'all',
189 traits => ['App::af::opt'],
190 opt_type => 's',
191 short => 'p',
192 );
193  
194 sub check_phase
195 10 ▶ {
Subroutine check_phase: called CC=2 SCAR=10.1
Pod undocumented
196 10 my($self) = @_;
197  
198 10 ▶ if($self->phase !~ /^(configure|any|all|share|system)$/)
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->phase =~ /^(configure|any|all|share|system)$/u) 0 10 10
199 {
200 0 say STDERR "unknown phase: @{[ $self->phase ]}";
201 0 exit 2;
202 }
203 }
204  
205 }
206  
207 8 package App::af::role::libandblib 0.18 {
208  
209 8 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
210 8 ▶ use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
211 8 ▶ use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
212  
213 8 has I => (
214 is => 'ro',
215 isa => 'ArrayRef[Str]',
216 traits => ['App::af::opt'],
217 opt_type => 's',
218 is_array => 1,
219 );
220  
221 8 has blib => (
222 is => 'ro',
223 isa => 'Int',
224 traits => ['App::af::opt'],
225 );
226  
227 2 ▶ around main => sub {
Subroutine __ANON__: called CC=4 SCAR=15.2
228 2 my $orig = shift;
229 2 my $self = shift;
230 2 my @args = @_;
231  
232 2 local @INC = @INC;
233  
234 2 foreach my $inc (reverse @{ $self->I })
235 {
236 0 require lib;
237 0 lib->import($inc);
238 }
239  
240 2 ▶ if($self->blib)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->blib) 0 2 2
241 {
242 0 require blib;
243 0 blib->import;
244 }
245  
246 # make sure @INC entries are absolute, since $build
247 # may do a lot of directory changes
248 2 ▶ @INC = map { ref $_ ? $_ : path($_)->absolute->stringify } @INC;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 16 16
249  
250 2 $orig->($self, @args);
251  
252 8 };
253  
254 }
255  
256 8 package App::af::opt 0.18 {
257  
258 8 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
259 8 ▶ use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
260  
261 8 has short => (
262 is => 'rw',
263 isa => 'Str',
264 default => '',
265 );
266  
267 8 has opt_type => (
268 is => 'rw',
269 isa => 'Str',
270 default => '',
271 );
272  
273 has is_array => (
274 is => 'rw',
275 isa => 'Int',
276 lazy => 1,
277 30 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
278 30 my($self) = @_;
279 30 int $self->opt_type =~ /\{/;
280 },
281 8 );
282  
283 }
284  
285 8 1;
286  
287 __END__
« bin/af ↑ Summary corpus/lib/Alien/foo.pm »