lib/Dist/Build/Core.pm

filter: Statementstmt 24.2% 49 / 202 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 31.1% 14 / 45 Podpod 54.5% 6 / 11 totaltotal 22.7% 69 / 304 CC 18 SCAR 20.9
CC
18
Cov
21%
tap_harness
42.0
__ANON__
12.0
__ANON__
12.0
CRAP 8.1
« blib/lib/Dist/Build/Util.pm ↑ Summary blib/lib/Dist/Build/XS/WriteConstants.pm »
1 package Dist::Build::Core;
2 1 $Dist::Build::Core::VERSION = '0.028';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use parent 'ExtUtils::Builder::Planner::Extension';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Exporter 5.57 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 our @EXPORT_OK = qw/copy make_executable manify tap_harness install dump_binary dump_text dump_json/;
10  
11 1 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use ExtUtils::Helpers 0.028 qw/make_executable man1_pagename man3_pagename/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use ExtUtils::Install ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use File::Basename qw/basename dirname/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use File::Copy ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use File::Find ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use File::Path qw/make_path remove_tree/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use File::Spec::Functions qw/catdir catfile abs2rel rel2abs/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Parse::CPAN::Meta;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use ExtUtils::Builder::Util qw/get_perl command function/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 0 ▶sub new_action {
Subroutine new_action: not called CC=1 SCAR=6.9
Pod undocumented
24 0 my ($name, @args) = @_;
25 0 return function(
26 function => $name,
27 module => __PACKAGE__,
28 arguments => \@args,
29 exports => 'explicit',
30 );
31 }
32  
33 0 ▶sub find {
Subroutine find: not called CC=2 SCAR=17.9
Pod undocumented
34 0 my ($pattern, $dir) = @_;
35 0 my @ret;
36 0 ▶ File::Find::find(sub { push @ret, abs2rel($File::Find::name) if /$pattern/ && -f }, $dir) if -d $dir;
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
if -d $dir 0 0 0
if /$pattern/ and -f $_ 0 0 0
Condition0%0/3
/$pattern/ and -f $_
!ll&&!rl&&r
000
MC/DC0%0/2
/$pattern/ and -f $_
/$pattern/ -f $_
Truth table0%0/3
A and B
A= /$pattern/B= -f $_
ABresult
0X0
100
111
37 0 return @ret;
38 }
39  
40 0 ▶sub contains_pod {
Subroutine contains_pod: not called CC=2 SCAR=17.9
Pod undocumented
41 0 my ($file) = @_;
42 0 ▶ return 0 if not -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
43 0 open my $fh, '<:utf8', $file;
44 0 my $content = do { local $/; <$fh> };
45 0 return $content =~ /^\=(?:head|pod|item)/m;
46 }
47  
48 0 ▶sub add_methods {
Subroutine add_methods: not called CC=1 SCAR=6.9
Pod undocumented
49 0 my ($self, $planner) = @_;
50  
51 0 ▶ $planner->add_delegate('copy_file', sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 0 my ($planner, $source, $destination) = @_;
53 0 my $copy = new_action('copy', $source, $destination);
54 0 $planner->create_node(
55 target => $destination,
56 dependencies => [ $source ],
57 actions => [ $copy ],
58 );
59 0 return $destination;
60 0 });
61  
62 0 ▶ $planner->add_delegate('copy_executable', sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
63 0 my ($planner, $source, $destination) = @_;
64 0 my $copy = new_action('copy', $source, $destination);
65 0 my $make_executable = new_action('make_executable', $destination);
66 0 $planner->create_node(
67 target => $destination,
68 dependencies => [ $source ],
69 actions => [ $copy, $make_executable ],
70 );
71 0 return $destination;
72 0 });
73  
74 0 ▶ $planner->add_delegate('manify', sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 0 my ($planner, $source, $destination, $section) = @_;
76 0 my $manify = new_action('manify', $source, $destination, $section);
77 0 my $dirname = dirname($destination);
78 0 $planner->create_node(
79 target => $destination,
80 dependencies => [ $source, $dirname ],
81 actions => [ $manify ],
82 );
83 0 return $destination;
84 0 });
85  
86 0 ▶ $planner->add_delegate('mkdir', sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
87 0 my ($planner, $target, %options) = @_;
88 0 my $action = function(
89 function => 'make_path',
90 module => 'File::Path',
91 arguments => [ $target, %options ],
92 exports => 'explicit',
93 message => "mkdir $target",
94 );
95 0 $planner->create_node(
96 target => $target,
97 actions => [ $action ],
98 );
99 0 return $target;
100 0 });
101  
102 0 ▶ $planner->add_delegate('tap_harness', sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
103 0 my ($planner, $target, %options) = @_;
104 $planner->create_node(
105 target => $target,
106 dependencies => $options{dependencies},
107 phony => 1,
108 actions => [
109 0 new_action('tap_harness', test_dir => $options{test_dir} ),
110 ],
111 );
112 0 return $target;
113 0 });
114  
115 0 ▶ $planner->add_delegate('install', sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
116 0 my ($planner, $target, %options) = @_;
117 $planner->create_node(
118 target => $target,
119 dependencies => $options{dependencies},
120 phony => 1,
121 actions => [
122 0 new_action('install', install_map => $options{install_map}),
123 ]
124 );
125 0 return $target;
126 0 });
127  
128 0 ▶ $planner->add_delegate('dump_binary', sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
129 0 my ($planner, $target, $content, %options) = @_;
130 $planner->create_node(
131 target => $target,
132 dependencies => $options{dependencies},
133 0 actions => [
134 new_action('dump_binary', $target, $content),
135 ]
136 );
137 0 });
138  
139 0 ▶ $planner->add_delegate('dump_text', sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
140 0 my ($planner, $target, $content, %options) = @_;
141 $planner->create_node(
142 target => $target,
143 dependencies => $options{dependencies},
144 actions => [
145 0 ▶ new_action('dump_text', $target, $content, $options{encoding} // 'utf-8'),
Condition0%0/2
$options{"encoding"} // "utf-8"
l!l
00
MC/DC0%0/1
$options{"encoding"} // "utf-8"
$options{"encoding"}
Truth table0%0/2
A
A= $options{"encoding"}
Aresult
11
00
146 ]
147 );
148 0 });
149  
150 0 ▶ $planner->add_delegate('dump_json', sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
151 0 my ($planner, $target, $content, %options) = @_;
152 $planner->create_node(
153 target => $target,
154 dependencies => $options{dependencies},
155 0 actions => [
156 new_action('dump_json', $target, $content),
157 ]
158 );
159 0 });
160  
161 0 ▶ $planner->add_delegate('script_dir', sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
162 0 my ($planner, $base) = @_;
163 0 (my $prefix = $base) =~ s/\W/-/g;
164  
165 0 my $script_files = $planner->create_pattern(
166 dir => $base,
167 );
168 0 my $script_pod_files = $planner->create_pattern(
169 name => "$prefix-pod-files",
170 on => $script_files,
171 file => '*.pod',
172 );
173 0 my $script_script_files = $planner->create_pattern(
174 name => "$prefix-script-files",
175 on => $script_files,
176 file => '*.pod',
177 negate => 1,
178 );
179  
180 $planner->create_subst(
181 on => $script_script_files,
182 add_to => 'code',
183 0 ▶ subst => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
184 0 my ($source) = @_;
185 0 my $destination = catfile('blib', 'script', abs2rel($source, $base));
186 0 return $planner->copy_executable($source, $destination);
187 },
188 0 );
189  
190 $planner->create_subst(
191 on => $script_pod_files,
192 add_to => 'code',
193 0 ▶ subst => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
194 0 my ($source) = @_;
195 0 my $destination = catfile('blib', 'script', basename($source));
196 0 return $planner->copy_file($source, $destination);
197 },
198 0 );
199  
200 0 my $install_paths = $planner->install_paths;
201 0 ▶ if ($install_paths->is_default_installable('bindoc') && $install_paths->install_destination('bindoc')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($install_paths->is_default_installable("bindoc") and $install_paths->install_destination("bindoc")) 0 0 0
Condition0%0/3
$install_paths->is_default_installable("bindoc") and $install_paths->install_destination("bindoc")
!ll&&!rl&&r
000
MC/DC0%0/2
$install_paths->is_default_installable("bindoc") and $install_paths->install_destination("bindoc")
$install_paths->is_default_installable("bindoc") $install_paths->install_destination("bindoc")
Truth table0%0/3
A and B
A= $install_paths->is_default_installable("bindoc")B= $install_paths->install_destination("bindoc")
ABresult
0X0
100
111
202 0 my $script_doc_files = $planner->create_filter(on => $script_script_files, condition => \&contains_pod);
203  
204 0 my $section1 = $planner->config->get('man1ext');
205 my $blib_doc_files = $planner->create_subst(
206 on => [ $script_pod_files, $script_doc_files ],
207 add_to => 'manify',
208 0 ▶ subst => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
209 0 my ($source) = @_;
210 0 my $destination = catfile('blib', 'bindoc', man1_pagename($source, $section1));
211 0 return $planner->manify($source, $destination, $section1);
212 },
213 0 );
214 }
215 0 });
216  
217 0 ▶ $planner->add_delegate('lib_dir', sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
218 0 my ($planner, $base) = @_;
219 0 (my $prefix = $base) =~ s/\W/-/g;
220  
221 0 my $files = $planner->create_pattern(
222 dir => $base,
223 );
224 0 my $pm_files = $planner->create_pattern(
225 name => "${prefix}-pm-files",
226 on => $files,
227 file => '*.pm',
228 );
229 0 my $pod_files = $planner->create_pattern(
230 name => "{$prefix}-pod-files",
231 on => $files,
232 file => '*.pod',
233 );
234  
235 my $blib_files = $planner->create_subst(
236 on => [ $pm_files, $pod_files ],
237 add_to => 'code',
238 0 ▶ subst => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
239 0 my ($source) = @_;
240 0 my $destination = catfile('blib', 'lib', abs2rel($source, $base));
241 0 return $planner->copy_file($source, $destination);
242 },
243 0 );
244  
245 0 my $install_paths = $planner->install_paths;
246 0 ▶ if ($install_paths->is_default_installable('libdoc') && $install_paths->install_destination('libdoc')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($install_paths->is_default_installable("libdoc") and $install_paths->install_destination("libdoc")) 0 0 0
Condition0%0/3
$install_paths->is_default_installable("libdoc") and $install_paths->install_destination("libdoc")
!ll&&!rl&&r
000
MC/DC0%0/2
$install_paths->is_default_installable("libdoc") and $install_paths->install_destination("libdoc")
$install_paths->is_default_installable("libdoc") $install_paths->install_destination("libdoc")
Truth table0%0/3
A and B
A= $install_paths->is_default_installable("libdoc")B= $install_paths->install_destination("libdoc")
ABresult
0X0
100
111
247 0 my $pm_doc_files = $planner->create_filter(
248 on => $pm_files,
249 condition => \&contains_pod,
250 );
251 0 my $section3 = $planner->config->get('man3ext');
252 my $blib_doc_files = $planner->create_subst(
253 on => [ $pm_doc_files, $pod_files ],
254 add_to => 'manify',
255 0 ▶ subst => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
256 0 my ($source) = @_;
257 0 my $destination = catfile('blib', 'libdoc', man3_pagename($source, $base, $section3));
258 0 return $planner->manify($source, $destination, $section3);
259 }
260 0 );
261 }
262 0 });
263  
264 0 ▶ $planner->add_delegate('auto_PL' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
265 0 my ($planner, $dir, %args) = @_;
266 0 ▶ $dir //= 'lib';
Condition0%0/2
$dir //= "lib"
l!l
00
MC/DC0%0/1
$dir //= "lib"
$dir
Truth table0%0/2
A
A= $dir
Aresult
11
00
267 0 my $pattern = $planner->create_pattern(dir => $dir, file => '*.PL');
268 $planner->create_subst(
269 on => $pattern,
270 0 ▶ subst => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
271 0 my ($source) = @_;
272 0 (my $target = $source) =~ s/\.PL\z//;
273 0 $planner->create_node(
274 target => $target,
275 dependencies => [ $source ],
276 actions => [
277 command(get_perl(%args), $source, $target),
278 ],
279 );
280 },
281 0 );
282 0 });
283  
284 0 ▶ $planner->add_delegate('autoclean', sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
285 0 my ($planner) = @_;
286 0 my @targets = grep { !/^blib\b/ } map { $_->target } grep { ! $_->phony } $planner->materialize->nodes;
287  
288 0 my $clean_action = function(
289 function => 'remove_tree',
290 module => 'File::Path',
291 arguments => [ 'blib', @targets ],
292 exports => 'explicit',
293 message => "rm_r @targets",
294 );
295 0 $planner->create_node(
296 target => 'clean',
297 phony => 1,
298 actions => [ $clean_action ],
299 );
300  
301 0 my @real_targets = qw/Build _build MYMETA.json MYMETA.yml/;
302 0 my $realclean_action = function(
303 function => 'remove_tree',
304 module => 'File::Path',
305 arguments => \@real_targets,
306 exports => 'explicit',
307 message => "rm_r @real_targets",
308 );
309 0 $planner->create_node(
310 target => 'realclean',
311 phony => 1,
312 dependencies => [ 'clean' ],
313 actions => [ $realclean_action ],
314 );
315 0 });
316 }
317  
318 0 ▶sub copy {
Subroutine copy: not called CC=3 SCAR=24.8
Pod undocumented
319 0 my ($source, $target, %options) = @_;
320  
321 0 make_path(dirname($target));
322 0 ▶ unlink $target if -f $target;
Branch: 1 branch
BranchTrueFalseTotal
if -f $target 0 0 0
323 0 ▶ File::Copy::copy($source, $target) or croak "Could not copy: $!";
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::copy($source, $target) or croak("Could not copy: $!") 0 0 0
324  
325 0 my ($atime, $mtime) = (stat $source)[8,9];
326 0 utime $atime, $mtime, $target;
327 0 chmod 0444 & ~umask, $target;
328  
329 0 return;
330 }
331  
332 0 ▶sub manify {
Subroutine manify: not called CC=1 SCAR=6.9
Pod documented
333 0 my ($input_file, $output_file, $section) = @_;
334 0 require Pod::Man;
335 0 Pod::Man->new(section => $section)->parse_from_file($input_file, $output_file);
336 0 return;
337 }
338  
339 1 my @default_libs = map { catdir('blib', $_) } qw/arch lib/;
340  
341 0 ▶sub tap_harness {
Subroutine tap_harness: not called CC=6 SCAR=37.4
Pod documented
342 0 my (%args) = @_;
343 0 my @test_files;
344 0 ▶ if ($args{test_files}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'test_files'}) { } 0 0 0
345 0 @test_files = @{ delete $args{test_files} };
346 } else {
347 0 ▶ my $dir = delete $args{test_dir} // 't';
Condition0%0/2
delete $args{"test_dir"} // "t"
l!l
00
MC/DC0%0/1
delete $args{"test_dir"} // "t"
delete $args{"test_dir"}
Truth table0%0/2
A
A= delete $args{"test_dir"}
Aresult
11
00
348 0 @test_files = sort +find(qr/\.t$/, $dir);
349 }
350 0 ▶ my @libs = $args{libs} ? @{ $args{libs} } : @default_libs;
Branch: 1 branch
BranchTrueFalseTotal
$args{'libs'} ? : 0 0 0
351 my %test_args = (
352 (color => 1) x !!-t STDOUT,
353 %args,
354 0 lib => [ map { rel2abs($_) } @libs ],
355 );
356 0 ▶ $test_args{verbosity} = delete $test_args{verbose} if exists $test_args{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if exists $test_args{"verbose"} 0 0 0
357 0 require TAP::Harness::Env;
358 0 my $tester = TAP::Harness::Env->create(\%test_args);
359 0 my $results = $tester->runtests(@test_files);
360 0 ▶ croak "Errors in testing. Cannot continue.\n" if $results->has_errors;
Branch: 1 branch
BranchTrueFalseTotal
if $results->has_errors 0 0 0
361 }
362  
363 0 ▶sub install {
Subroutine install: not called CC=1 SCAR=6.9
Pod documented
364 0 my (%args) = @_;
365 0 ExtUtils::Install::install($args{install_map}, $args{verbose}, $args{dry_run}, $args{uninst});
366 0 return;
367 }
368  
369 0 ▶sub dump_binary {
Subroutine dump_binary: not called CC=1 SCAR=6.9
Pod documented
370 0 my ($filename, $content) = @_;
371 0 open my $fh, '>:raw', $filename;
372 0 print $fh $content;
373 }
374  
375 0 ▶sub dump_text {
Subroutine dump_text: not called CC=1 SCAR=6.9
Pod documented
376 0 my ($filename, $content, $encoding) = @_;
377 0 open my $fh, ">:encoding($encoding)", $filename;
378 0 print $fh $content;
379 }
380  
381 1 my $json_backend = Parse::CPAN::Meta->json_backend;
382 1 my $json = $json_backend->new->canonical->pretty->utf8;
383  
384 0 ▶sub dump_json {
Subroutine dump_json: not called CC=1 SCAR=6.9
Pod documented
385 0 my ($filename, $content) = @_;
386 0 open my $fh, '>:raw', $filename;
387 0 print $fh $json->encode($content);
388 }
389  
390 1 1;
391  
392 # ABSTRACT: core functions for Dist::Build
393  
394 __END__
« blib/lib/Dist/Build/Util.pm ↑ Summary blib/lib/Dist/Build/XS/WriteConstants.pm »