blib/lib/ExtUtils/Builder/Planner.pm

filter: Statementstmt 80.4% 160 / 199 Branchbran 44.4% 16 / 36 Conditioncond 30.0% 6 / 20 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 73.9% 34 / 46 Podpod 100% 14 / 14 totaltotal 70.3% 230 / 327 CC 29 SCAR 13.4
CC
29
Cov
71%
_make_pattern
9.2
add_node
8.6
create_filter
6.7
CRAP 3.8
« blib/lib/ExtUtils/Builder/Plan.pm ↑ Summary blib/lib/ExtUtils/Builder/Action/Function.pm »
1 package ExtUtils::Builder::Planner;
2 5 $ExtUtils::Builder::Planner::VERSION = '0.020';
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use List::Util 1.45 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 ▶use ExtUtils::Builder::Plan;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use ExtUtils::Builder::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use ExtUtils::Builder::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 6 ▶use ExtUtils::Builder::FileSet::Free;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶use ExtUtils::Builder::FileSet::Filter;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶use ExtUtils::Builder::FileSet::Subst;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 5 my $class_counter = 0;
21  
22 4 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
23 4 my $base_class = shift;
24 4 my $all_files = ExtUtils::Builder::FileSet::Free->new;
25 4 return $base_class->_new_scope($base_class, undef, {}, { 'all-files' => $all_files });
26 }
27  
28 4 ▶sub _new_scope {
Subroutine _new_scope: called CC=1 SCAR=0.1
29 4 my ($self, $base_class, $outer, $nodes, $filesets) = @_;
30  
31 4 my $class = __PACKAGE__ . '::Anon_' . ++$class_counter;
32 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 4 push @{ "$class\::ISA" }, $base_class;
34  
35 4 my $new = bless {
36 nodes => $nodes,
37 filesets => $filesets
38 }, $class;
39  
40 0 ▶ $new->add_delegate('self', sub { $new });
Subroutine __ANON__: not called CC=1 SCAR=2.6
Subroutine self: not called CC=1 SCAR=2.6
41 0 ▶ $new->add_delegate('outer', sub { $outer });
Subroutine __ANON__: not called CC=1 SCAR=1.2
42  
43 4 return $new;
44 }
45  
46 0 ▶sub new_scope {
Subroutine new_scope: not called CC=1 SCAR=6.9
Pod documented
47 0 my ($self) = @_;
48 0 return $self->_new_scope(ref($self), $self, $self->{nodes}, $self->{filesets});
49 }
50  
51 13 ▶sub add_node {
Subroutine add_node: called CC=5 SCAR=21.6
Pod documented
52 13 my ($self, $node) = @_;
53 13 my $target = $node->target;
54 13 ▶ if (exists $self->{nodes}{$target}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'nodes'}{$target}) { } 0 13 13
55 0 ▶ Carp::croak("Duplicate for target $target") if !$node->mergeable or !$self->{nodes}{$target}->mergeable;
Branch: 1 branch
BranchTrueFalseTotal
unless $node->mergeable and $self->{"nodes"}{$target}->mergeable 0 0 0
Condition0%0/3
$node->mergeable and $self->{"nodes"}{$target}->mergeable
!ll&&!rl&&r
000
MC/DC0%0/2
$node->mergeable and $self->{"nodes"}{$target}->mergeable
$node->mergeable $self->{"nodes"}{$target}->mergeable
Truth table0%0/3
A and B
A= $node->mergeableB= $self->{"nodes"}{$target}->mergeable
ABresult
0X0
100
111
56 0 my @dependencies = List::Util::uniq($self->{nodes}{$target}->dependencies, $node->dependencies);
57 0 my $new = ExtUtils::Builder::Node->new(target => $target, dependencies => \@dependencies, phony => 1);
58 0 $self->{nodes}{$target} = $new;
59 } else {
60 13 $self->{nodes}{$target} = $node;
61 13 ▶ $self->{filesets}{'all-files'}->add_input($target) if not $node->phony;
Branch: 1 branch
BranchTrueFalseTotal
unless $node->phony 10 3 13
62 }
63 13 return $node->target;
64 }
65  
66 13 ▶sub create_node {
Subroutine create_node: called CC=1 SCAR=0.0
Pod documented
67 13 my ($self, %args) = @_;
68 13 my $node = ExtUtils::Builder::Node->new(%args);
69 13 return $self->add_node($node);
70 }
71  
72 0 ▶sub create_phony {
Subroutine create_phony: not called CC=1 SCAR=6.9
Pod documented
73 0 my ($self, $target, @dependencies) = @_;
74 0 return $self->create_node(
75 target => $target,
76 dependencies => \@dependencies,
77 type => 'phony',
78 );
79 }
80  
81 5 my $counter = 0;
82  
83 2 ▶sub _create_callback {
Subroutine _create_callback: called CC=2 SCAR=11.6
84 2 my ($self, $add_to) = @_;
85 2 ▶ return undef unless $add_to;
Branch: 1 branch
BranchTrueFalseTotal
unless $add_to 2 0 2
86 0 my $this = $self;
87 0 Scalar::Util::weaken($this);
88 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
89 0 my ($entry) = @_;
90 0 $this->create_phony($add_to, $entry);
91 0 };
92 }
93  
94 1 ▶sub create_filter {
Subroutine create_filter: called CC=6 SCAR=19.0
Pod documented
95 1 my ($self, %args) = @_;
96 my $set = ExtUtils::Builder::FileSet::Filter->new(
97 condition => $args{condition},
98 1 callback => $self->_create_callback($args{add_to}),
99 );
100 1 ▶ my $on = $args{on} // 'all-files';
Condition50%1/2
$args{"on"} // "all-files"
l!l
01
MC/DC0%0/1
$args{"on"} // "all-files"
$args{"on"}
Truth table50%1/2
A
A= $args{"on"}
Aresult
11
00
101 0 ▶ my @sources = ref($on) eq 'ARRAY' ? @{$on} : $on;
Branch: 1 branch
BranchTrueFalseTotal
ref $on eq 'ARRAY' ? : 0 1 1
102 1 for my $source (@sources) {
103 1 ▶ my $object = $self->{filesets}{$source} or die "No such source $source";
Branch: 1 branch
BranchTrueFalseTotal
my $object = $self->{"filesets"}{$source} or die "No such source $source" 1 0 1
104 1 $object->add_dependent($set);
105 }
106 1 ▶ my $name = $args{name} // 'filter-' . $counter++;
Condition50%1/2
$args{"name"} // 'filter-' . $counter++
l!l
01
MC/DC0%0/1
$args{"name"} // 'filter-' . $counter++
$args{"name"}
Truth table50%1/2
A
A= $args{"name"}
Aresult
11
00
107 1 $self->{filesets}{$name} = $set;
108 1 return $name;
109 }
110  
111 1 ▶sub _make_pattern {
Subroutine _make_pattern: called CC=4 SCAR=22.2
112 1 my ($self, %options) = @_;
113 1 ▶ if ($options{file}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($options{'file'}) { } 1 0 1
elsif ($options{'dir'}) { } 0 0 0
114 1 my $file = ExtUtils::Builder::Util::glob_to_regex($options{file});
115 1 ▶ if ($options{dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'dir'}) { } 0 1 1
116 0 my $dir = ExtUtils::Builder::Util::native_to_unix_path($options{dir});
117 0 $dir =~ s{(?<!/)$}{/}ms;
118 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
119 0 my ($input) = @_;
120 0 my $filename = ExtUtils::Builder::Util::native_to_unix_path($input);
121 0 ▶ return if substr($filename, 0, length $dir) ne $dir;
Branch: 1 branch
BranchTrueFalseTotal
if substr($filename, 0, length $dir) ne $dir 0 0 0
122 0 return File::Basename::basename($filename) =~ $file;
123 0 };
124 } else {
125 5 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
126 5 my ($filename) = @_;
127 5 return File::Basename::basename($filename) =~ $file;
128 1 };
129 }
130 } elsif ($options{dir}) {
131 0 my $dir = ExtUtils::Builder::Util::native_to_unix_path($options{dir});
132 0 $dir =~ s{(?<!/)$}{/}ms;
133 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
134 0 my ($input) = @_;
135 0 my $filename = ExtUtils::Builder::Util::native_to_unix_path($input);
136 0 return substr($filename, 0, length $dir) eq $dir;
137 0 };
138 } else {
139 0 Carp::croak("Unknown pattern type");
140 }
141 }
142  
143 1 ▶sub create_pattern {
Subroutine create_pattern: called CC=2 SCAR=7.4
Pod documented
144 1 my ($self, %args) = @_;
145 1 my $positive = $self->_make_pattern(%args);
146 0 ▶ my $callback = $args{negate} ? sub { !$positive->($_[0]) } : $positive;
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
$args{'negate'} ? : 0 1 1
147 1 return $self->create_filter(%args, condition => $callback);
148 }
149  
150 1 ▶sub create_subst {
Subroutine create_subst: called CC=6 SCAR=19.0
Pod documented
151 1 my ($self, %args) = @_;
152 my $set = ExtUtils::Builder::FileSet::Subst->new(
153 subst => $args{subst},
154 1 callback => $self->_create_callback($args{add_to}),
155 );
156 1 ▶ my $on = $args{on} // 'all-files';
Condition50%1/2
$args{"on"} // "all-files"
l!l
10
MC/DC0%0/1
$args{"on"} // "all-files"
$args{"on"}
Truth table50%1/2
A
A= $args{"on"}
Aresult
11
00
157 0 ▶ my @sources = ref($on) eq 'ARRAY' ? @{$on} : $on;
Branch: 1 branch
BranchTrueFalseTotal
ref $on eq 'ARRAY' ? : 0 1 1
158 1 for my $source (@sources) {
159 1 ▶ my $object = $self->{filesets}{$source} or die "No such source $source";
Branch: 1 branch
BranchTrueFalseTotal
my $object = $self->{"filesets"}{$source} or die "No such source $source" 1 0 1
160 1 $object->add_dependent($set);
161 }
162 1 ▶ my $name = $args{name} // 'subst-' . $counter++;
Condition50%1/2
$args{"name"} // 'subst-' . $counter++
l!l
01
MC/DC0%0/1
$args{"name"} // 'subst-' . $counter++
$args{"name"}
Truth table50%1/2
A
A= $args{"name"}
Aresult
11
00
163 1 $self->{filesets}{$name} = $set;
164 1 return $name;
165 }
166  
167 4 ▶sub add_seen {
Subroutine add_seen: called CC=1 SCAR=0.0
Pod documented
168 4 my ($self, $entry) = @_;
169 4 $self->{filesets}{'all-files'}->add_input($entry);
170 4 return;
171 }
172  
173 0 ▶sub merge_plan {
Subroutine merge_plan: not called CC=2 SCAR=17.9
Pod documented
174 0 my ($self, $plan) = @_;
175 0 $self->add_node($_) for $plan->nodes;
176 0 return;
177 }
178  
179 0 ▶my $set_subname = eval { require Sub::Util; Sub::Util->VERSION('1.40'); \&Sub::Util::set_subname } // sub { $_[1] };
Subroutine __ANON__: not called CC=1 SCAR=0.4
Condition33%2/6
eval { do { require Sub::Util; "Sub::Util"->VERSION("1.40"); \&Sub::Util::set_subname } } // sub { $_[1]; }
l!l&&r!l&&!r
500
eval { do { require Sub::Util; "Sub::Util"->VERSION("1.40"); \&Sub::Util::set_subname } } // sub { $_[1]; }
l!l&&r!l&&!r
100
MC/DC0%0/2
eval { do { require Sub::Util; "Sub::Util"->VERSION("1.40"); \&Sub::Util::set_subname } } // sub { $_[1]; }
eval { do { require Sub::Util; "Sub::Util"->VERSION("1.40"); \&Sub::Util::set_subname } } sub { $_[1]; }
MC/DC0%0/2
eval { do { require Sub::Util; "Sub::Util"->VERSION("1.40"); \&Sub::Util::set_subname } } // sub { $_[1]; }
eval { do { require Sub::Util; "Sub::Util"->VERSION("1.40"); \&Sub::Util::set_subname } } sub { $_[1]; }
Truth table33%1/3
A // B
A= eval { do { require Sub::Util; "Sub::Util"->VERSION("1.40"); \&Sub::Util::set_subname } }B= sub { $_[1]; }
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= eval { do { require Sub::Util; "Sub::Util"->VERSION("1.40"); \&Sub::Util::set_subname } }B= sub { $_[1]; }
ABresult
1X1
011
000
180  
181 32 ▶sub add_delegate {
Subroutine add_delegate: called CC=1 SCAR=0.0
Pod documented
182 32 my ($self, $name, $sub) = @_;
183 32 my $full_name = ref($self) . '::' . $name;
184 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
185 6 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
186 32 *{$full_name} = $set_subname->($full_name, $sub);
187 32 return;
188 }
189  
190 4 ▶sub load_extension {
Subroutine load_extension: called CC=2 SCAR=7.0
Pod documented
191 4 my ($self, $plannable, $version, %options) = @_;
192 4 ExtUtils::Builder::Util::require_module($plannable);
193 4 ▶ $plannable->VERSION($version) if $version;
Branch: 1 branch
BranchTrueFalseTotal
if $version 0 4 4
194 4 return $plannable->add_methods($self, %options);
195 }
196 5 *load_module = \&load_extension;
197  
198 3 ▶sub materialize {
Subroutine materialize: called CC=1 SCAR=0.0
Pod documented
199 3 my $self = shift;
200 3 my %nodes = %{ $self->{nodes} };
201 3 return ExtUtils::Builder::Plan->new(nodes => \%nodes);
202 }
203  
204 5 my %dsl_commands = (
205 command => \&ExtUtils::Builder::Util::command,
206 code => \&ExtUtils::Builder::Util::code,
207 function => \&ExtUtils::Builder::Util::function,
208 );
209  
210 1 ▶sub run_dsl {
Subroutine run_dsl: called CC=6 SCAR=18.8
Pod documented
211 1 my ($self, $filename) = @_;
212  
213 1 my $dsl_module = ref($self) . '::DSL';
214  
215 1 ▶ if (not defined &{ "$dsl_module\::AUTOLOAD" }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &{"${dsl_module}::AUTOLOAD";}) 1 0 1
216 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
217 1 ▶ *{ "$dsl_module\::AUTOLOAD" } = sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
218 3 my $name = our $AUTOLOAD;
219 3 $name =~ s/.*:://;
220 3 ▶ if (my $method = $self->can($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $self->can($name)) { } 3 0 3
221 0 ▶ my $delegate = $set_subname->($name, sub {
Subroutine __ANON__: not called CC=1 SCAR=1.2
Subroutine add_foo: called CC=1 SCAR=1.2
222 0 $self->$method(@_);
223 3 });
224 3 *{ "$dsl_module\::$name" } = $delegate;
225 3 goto &$delegate;
226 }
227 else {
228 0 Carp::croak("No such subroutine $name");
229 }
230 1 };
231  
232 1 for my $name (keys %dsl_commands) {
233 3 ▶ *{ "$dsl_module\::$name" } = $dsl_commands{$name} if not $dsl_module->can($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $dsl_module->can($name) 3 0 3
234 }
235 }
236  
237 1 my $path = File::Spec->rel2abs($filename);
238 1 ▶ eval "package $dsl_module; my \$ret = do \$path; die \$@ if \$@; defined \$ret || !\$!" or die $@ // Carp::shortmess("Can't run $path: $!");
Branch: 1 branch
BranchTrueFalseTotal
eval "package $dsl_module; my \$ret = do \$path; die \$\@ if \$\@; defined \$ret || !\$!" or die $@ // Carp::shortmess("Can't run ${path}: $!") 1 0 1
Condition0%0/3
$@ // Carp::shortmess("Can't run ${path}: $!")
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ // Carp::shortmess("Can't run ${path}: $!")
$@ Carp::shortmess("Can't run ${path}: $!")
Truth table0%0/3
A // B
A= $@B= Carp::shortmess("Can't run ${path}: $!")
ABresult
1X1
011
000
239 1 return;
240 }
241  
242 5 1;
243  
244 # ABSTRACT: An ExtUtils::Builder Plan builder
245  
246 __END__
« blib/lib/ExtUtils/Builder/Plan.pm ↑ Summary blib/lib/ExtUtils/Builder/Action/Function.pm »