lib/Dist/Build.pm

filter: Statementstmt 49.2% 69 / 140 Branchbran 14.2% 2 / 14 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 79.1% 19 / 24 Podpod 0.0% 0 / 5 totaltotal 48.3% 90 / 186 CC 16 SCAR 34.5
CC
16
Cov
46%
Build_PL
110.0
get_config
15.6
Build
2.9
CRAP 31.4
« blib/lib/Dist/Build/XS/Alien.pm ↑ Summary blib/lib/Dist/Build/XS/Import.pm »
1 package Dist::Build;
2 1 $Dist::Build::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 Exporter 5.57 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 our @EXPORT = qw/Build Build_PL/;
8  
9 1 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use CPAN::Meta;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use ExtUtils::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use ExtUtils::Helpers 0.007 qw/split_like_shell detildefy make_executable/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use ExtUtils::Manifest 'maniread';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use ExtUtils::InstallPaths;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use File::Spec::Functions qw/catfile catdir abs2rel /;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Getopt::Long 2.36 qw/GetOptionsFromArray/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Parse::CPAN::Meta;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use version ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use ExtUtils::Builder::Planner 0.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use ExtUtils::Builder::Util qw/get_perl unix_to_native_path/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Dist::Build::Serializer;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 my $json_backend = Parse::CPAN::Meta->json_backend;
25 1 my $json = $json_backend->new->canonical->pretty->utf8;
26 1 my $serializer = 'Dist::Build::Serializer';
27  
28 1 ▶sub load_json {
Subroutine load_json: called CC=1 SCAR=0.0
Pod undocumented
29 1 my $filename = shift;
30 1 open my $fh, '<:raw', $filename;
31 1 my $content = do { local $/; <$fh> };
32 1 return $json->decode($content);
33 }
34  
35 0 ▶sub save_json {
Subroutine save_json: not called CC=1 SCAR=6.9
Pod undocumented
36 0 my ($filename, $content) = @_;
37 0 open my $fh, '>:raw', $filename;
38 0 print $fh $json->encode($content);
39 0 return;
40 }
41  
42 1 my @options = qw/install_base=s install_path=s% installdirs=s destdir=s prefix=s
43 config=s% uninst:1 verbose:1 dry_run:1 pureperl_only|pureperl-only:1 create_packlist=i
44 jobs=i allow_mb_mismatch:1/;
45  
46 1 ▶sub get_config {
Subroutine get_config: called CC=6 SCAR=27.4
Pod undocumented
47 1 my ($meta_name, @arguments) = @_;
48 1 my %options;
49 1 ▶ GetOptionsFromArray($_, \%options, @options) or die "Could not parse arguments" for @arguments;
Branch: 1 branch
BranchTrueFalseTotal
&GetOptionsFromArray($_, \%options, @options) or die "Could not parse arguments" 2 1 3
50  
51 0 $options{$_} = detildefy($options{$_}) for grep { exists $options{$_} } qw/install_base destdir prefix/;
52 0 ▶ $_ = detildefy($_) for values %{ $options{install_path} // {} };
Condition0%0/2
$options{"install_path"} // {}
l!l
00
MC/DC0%0/1
$options{"install_path"} // {}
$options{"install_path"}
Truth table0%0/2
A
A= $options{"install_path"}
Aresult
11
00
53 0 $options{config} = ExtUtils::Config->new($options{config});
54 0 $options{install_paths} = ExtUtils::InstallPaths->new(%options, dist_name => $meta_name);
55  
56 0 return %options;
57 }
58  
59 0 ▶sub Build_PL {
Subroutine Build_PL: not called CC=10 SCAR=47.0
Pod undocumented
60 0 my ($args, $env) = @_;
61  
62 0 my $meta = CPAN::Meta->load_file('META.json', { lazy_validation => 0 });
63  
64 0 ▶ my @env = defined $env->{PERL_MB_OPT} ? split_like_shell($env->{PERL_MB_OPT}) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $env->{'PERL_MB_OPT'} ? : 0 0 0
65 0 my %options = get_config($meta->name, [ @{$args} ], [ @env ]);
66  
67 0 my $planner = ExtUtils::Builder::Planner->new;
68  
69 0 $planner->create_phony('code', 'config');
70 0 $planner->create_phony('manify', 'config');
71 0 $planner->create_phony('dynamic');
72 0 $planner->create_phony('pure_all', 'code', 'manify', 'dynamic');
73 0 $planner->create_phony('build', 'pure_all');
74  
75 0 $planner->load_extension('ExtUtils::Builder::CPAN::Tool');
76 0 ▶ $planner->add_delegate('meta', sub { $meta });
Subroutine __ANON__: not called CC=1 SCAR=6.9
77  
78 0 for my $variable (qw/config install_paths verbose uninst jobs pureperl_only/) {
79 0 ▶ $planner->add_delegate($variable, sub { $options{$variable} }) if exists $options{$variable};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{$variable} 0 0 0
80 }
81  
82 0 my @meta_fragments;
83 0 ▶ $planner->add_delegate('add_meta', sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 0 my (undef, @fragments) = @_;
85 0 push @meta_fragments, @fragments;
86 0 });
87  
88 0 my $core = $planner->new_scope;
89 0 $core->load_extension('Dist::Build::Core');
90  
91 0 my @blibs = map { catfile('blib', $_) } qw/lib arch bindoc libdoc script bin/;
92 0 $core->mkdir($_) for @blibs;
93 0 $core->create_phony('config', @blibs);
94 0 $core->lib_dir('lib');
95 0 $core->add_seen(unix_to_native_path($_)) for sort keys %{ maniread() };
96  
97 0 $core->tap_harness('test', dependencies => [ 'pure_all' ], test_dir => 't');
98 0 $core->install('install', dependencies => [ 'pure_all' ], install_map => $options{install_paths}->install_map);
99  
100 0 for my $file (glob 'planner/*.pl') {
101 0 $planner->new_scope->run_dsl($file);
102 }
103  
104 0 $core->autoclean;
105  
106 0 my $plan = $planner->materialize;
107  
108 0 ▶ mkdir '_build' if not -d '_build';
Branch: 1 branch
BranchTrueFalseTotal
unless -d "_build" 0 0 0
109 0 save_json(catfile(qw/_build graph/), $serializer->serialize_plan($plan));
110 0 save_json(catfile(qw/_build params/), [ $args, \@env ]);
111  
112 0 my $metahash = $meta->as_struct;
113 0 ▶ if (@meta_fragments) {
Branch: 1 branch
BranchTrueFalseTotal
if (@meta_fragments) 0 0 0
114 0 require CPAN::Meta::Merge;
115 0 my $merger = CPAN::Meta::Merge->new(default_version => '2');
116 0 $metahash = $merger->merge($metahash, @meta_fragments);
117 }
118 0 $metahash->{dynamic_config} = 0;
119 0 my $mymeta = CPAN::Meta->create($metahash, { lazy_validation => 0 });
120 0 $mymeta->save('MYMETA.json');
121  
122 0 printf "Creating new 'Build' script for '%s' version '%s'\n", $meta->name, $meta->version;
123 0 ▶ my $dir = $meta->name eq 'Dist-Build' ? 'lib' : 'inc';
Branch: 1 branch
BranchTrueFalseTotal
$meta->name eq 'Dist-Build' ? : 0 0 0
124 0 open my $fh, '>:utf8', 'Build';
125 0 print $fh "#!perl\nuse lib '$dir';\nuse Dist::Build;\nBuild(\\\@ARGV, \\\%ENV);\n";
126 0 close $fh;
127 0 make_executable('Build');
128  
129 0 return;
130 }
131  
132 1 ▶sub Build {
Subroutine Build: called CC=2 SCAR=10.8
Pod undocumented
133 1 my ($args, $env) = @_;
134 1 my $meta = CPAN::Meta->load_file('MYMETA.json', { lazy_validation => 0 });
135  
136 1 my ($bpl, $mbopts) = @{ load_json(catfile(qw/_build params/)) };
137 1 my %options = get_config($meta->name, $bpl, $mbopts, $args);
138 0 ▶ my $action = @{$args} ? shift @{$args} : 'build';
Branch: 1 branch
BranchTrueFalseTotal
@{$args;} ? : 0 0 0
139  
140 0 my $preplan = load_json(catfile(qw/_build graph/));
141 0 my $plan = $serializer->deserialize_plan($preplan, %options);
142 0 return $plan->run($action);
143 }
144  
145 1 1;
146  
147 # ABSTRACT: A modern module builder, author tools not included!
148  
149 __END__
« blib/lib/Dist/Build/XS/Alien.pm ↑ Summary blib/lib/Dist/Build/XS/Import.pm »