blib/lib/FFI/Build/MM.pm

filter: Statementstmt 94.5% 156 / 165 Branchbran 63.4% 33 / 52 Conditioncond 42.8% 12 / 28 MC/DCmcdc 11.7% 2 / 17 Subroutinesub 100% 33 / 33 Podpod 21.4% 3 / 14 totaltotal 77.3% 239 / 309 CC 43 SCAR 22.9
CC
43
Cov
82%
mm_args
29.8
load_build
18.2
clean
4.2
CRAP 9.8
« blib/lib/FFI/Platypus/Bundle.pm ↑ Summary lib/FFI/Build.pm »
1 package FFI::Build::MM;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use FFI::Build;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use File::Glob ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use File::Basename ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use File::Path ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use File::Copy ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use ExtUtils::MakeMaker 7.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # ABSTRACT: FFI::Build installer code for ExtUtils::MakeMaker
16 3 our $VERSION = '2.12'; # VERSION
17  
18  
19 sub new
20 9 ▶{
Subroutine new: called CC=2 SCAR=6.9
Pod documented
21 9 my($class, %opt) = @_;
22  
23 9 ▶ my $save = defined $opt{save} ? $opt{save} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{'save'} ? : 4 5 9
24  
25 9 my $self = bless { save => $save }, $class;
26 9 $self->load_prop;
27  
28 9 $self;
29 }
30  
31  
32 sub mm_args
33 6 ▶{
Subroutine mm_args: called CC=13 SCAR=34.0
Pod documented
34 6 my($self, %args) = @_;
35  
36 6 ▶ if($args{DISTNAME})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'DISTNAME'}) { } 6 0 6
37 {
38 6 ▶ $self->{prop}->{distname} ||= $args{DISTNAME};
Condition33%1/3
$self->{"prop"}{"distname"} ||= $args{"DISTNAME"}
l!l&&r!l&&!r
060
MC/DC0%0/2
$self->{"prop"}{"distname"} ||= $args{"DISTNAME"}
$self->{"prop"}{"distname"} $args{"DISTNAME"}
Truth table33%1/3
A ||= B
A= $self->{"prop"}{"distname"}B= $args{"DISTNAME"}
ABresult
1X1
011
000
39 6 ▶ $self->{prop}->{share} ||= "blib/lib/auto/share/dist/@{[ $self->distname ]}";
Condition50%1/2
$self->{"prop"}{"share"} ||= "blib/lib/auto/share/dist/@{[$self->distname];}"
l!l
06
MC/DC0%0/1
$self->{"prop"}{"share"} ||= "blib/lib/auto/share/dist/@{[$self->distname];}"
$self->{"prop"}{"share"}
Truth table50%1/2
A
A= $self->{"prop"}{"share"}
Aresult
11
00
40 6 ▶ $self->{prop}->{arch} ||= "blib/arch/auto/@{[ join '/', split /-/, $self->distname ]}";
Condition50%1/2
$self->{"prop"}{"arch"} ||= qq[blib/arch/auto/@{[join("/", split(/-/, $self->distname, 0))];}]
l!l
06
MC/DC0%0/1
$self->{"prop"}{"arch"} ||= qq[blib/arch/auto/@{[join("/", split(/-/, $self->distname, 0))];}]
$self->{"prop"}{"arch"}
Truth table50%1/2
A
A= $self->{"prop"}{"arch"}
Aresult
11
00
41 6 $self->save_prop;
42 }
43 else
44 {
45 0 Carp::croak "DISTNAME is required";
46 }
47  
48  
49 6 ▶ if(my $build = $self->build)
Branch: 1 branch
BranchTrueFalseTotal
if (my $build = $self->build) 6 0 6
50 {
51 6 foreach my $alien (@{ $build->alien })
52 {
53 0 ▶ next if ref $alien;
Branch: 1 branch
BranchTrueFalseTotal
if ref $alien 0 0 0
54 0 ▶ $args{BUILD_REQUIRES}->{$alien} ||= 0;
Condition0%0/2
$args{"BUILD_REQUIRES"}{$alien} ||= 0
l!l
00
MC/DC0%0/1
$args{"BUILD_REQUIRES"}{$alien} ||= 0
$args{"BUILD_REQUIRES"}{$alien}
Truth table0%0/2
A
A= $args{"BUILD_REQUIRES"}{$alien}
Aresult
11
00
55 }
56 }
57  
58 6 ▶ if(my $test = $self->test)
Branch: 1 branch
BranchTrueFalseTotal
if (my $test = $self->test) 3 3 6
59 {
60 3 foreach my $alien (@{ $test->alien })
61 {
62 0 ▶ next if ref $alien;
Branch: 1 branch
BranchTrueFalseTotal
if ref $alien 0 0 0
63 0 ▶ $args{TEST_REQUIRES}->{$alien} ||= 0;
Condition0%0/2
$args{"TEST_REQUIRES"}{$alien} ||= 0
l!l
00
MC/DC0%0/1
$args{"TEST_REQUIRES"}{$alien} ||= 0
$args{"TEST_REQUIRES"}{$alien}
Truth table0%0/2
A
A= $args{"TEST_REQUIRES"}{$alien}
Aresult
11
00
64 }
65 }
66  
67 6 %args;
68 }
69  
70 21 ▶sub distname { shift->{prop}->{distname} }
Subroutine distname: called CC=1 SCAR=0.0
Pod undocumented
71  
72 sub sharedir
73 11 ▶{
Subroutine sharedir: called CC=2 SCAR=6.9
Pod undocumented
74 11 my($self, $new) = @_;
75  
76 11 ▶ if(defined $new)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) 1 10 11
77 {
78 1 $self->{prop}->{share} = $new;
79 1 $self->save_prop;
80 }
81  
82 11 $self->{prop}->{share};
83 }
84  
85 sub archdir
86 7 ▶{
Subroutine archdir: called CC=2 SCAR=6.9
Pod undocumented
87 7 my($self, $new) = @_;
88  
89 7 ▶ if(defined $new)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) 1 6 7
90 {
91 1 $self->{prop}->{arch} = $new;
92 1 $self->save_prop;
93 }
94  
95 7 $self->{prop}->{arch};
96 }
97  
98 sub load_build
99 22 ▶{
Subroutine load_build: called CC=14 SCAR=29.0
Pod undocumented
100 22 my($self, $dir, $name, $install) = @_;
101 22 ▶ return unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 3 19 22
102 19 my($fbx) = File::Glob::bsd_glob("./$dir/*.fbx");
103  
104 19 my $options;
105 19 my $platform = FFI::Build::Platform->default;
106  
107 19 ▶ if($fbx)
Branch: 1 branch
BranchTrueFalseTotal
if ($fbx) { } 6 13 19
108 {
109 6 $name = File::Basename::basename($fbx);
110 6 $name =~ s/\.fbx$//;
111 6 $options = do {
112 package FFI::Build::MM::FBX;
113 6 our $DIR = $dir;
114 6 our $PLATFORM = $platform;
115  
116 # make sure we catch all of the errors
117 # code copied from `perldoc -f do`
118 6 my $return = do $fbx;
119 6 ▶ unless ( $return ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($return) 1 5 6
120 1 ▶ Carp::croak( "couldn't parse $fbx: $@" ) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 0 1
121 0 ▶ Carp::croak( "couldn't do $fbx: $!" ) unless defined $return;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $return 0 0 0
122 0 ▶ Carp::croak( "couldn't run $fbx" ) unless $return;
Branch: 1 branch
BranchTrueFalseTotal
unless $return 0 0 0
123 }
124  
125 5 $return;
126 };
127 }
128 else
129 {
130 13 ▶ $name ||= $self->distname;
Condition66%2/3
$name ||= $self->distname
l!l&&r!l&&!r
580
MC/DC0%0/2
$name ||= $self->distname
$name $self->distname
Truth table66%2/3
A ||= B
A= $nameB= $self->distname
ABresult
1X1
011
000
131 13 $options = {
132 source => ["$dir/*.c", "$dir/*.cxx", "$dir/*.cpp"],
133 };
134 # if we see a Go, V, Rust or Zig control file then we assume the
135 # ffi mod is written in that language.
136 13 foreach my $control_file ("$dir/Cargo.toml", "$dir/go.mod", "$dir/v.mod", "$dir/build.zig")
137 {
138 52 ▶ if(-f $control_file)
Branch: 1 branch
BranchTrueFalseTotal
if (-f $control_file) 0 52 52
139 {
140 0 $options->{source} = [$control_file];
141 0 last;
142 }
143 }
144 }
145  
146 18 ▶ $options->{platform} ||= $platform;
Condition33%1/3
$options->{"platform"} ||= $platform
l!l&&r!l&&!r
0180
MC/DC0%0/2
$options->{"platform"} ||= $platform
$options->{"platform"} $platform
Truth table33%1/3
A ||= B
A= $options->{"platform"}B= $platform
ABresult
1X1
011
000
147 18 ▶ $options->{dir} ||= ref $install ? $install->($options) : $install;
Branch: 1 branch
BranchTrueFalseTotal
ref $install ? : 5 13 18
Condition66%2/3
$options->{"dir"} ||= ref $install ? &$install($options) : $install
l!l&&r!l&&!r
0162
MC/DC50%1/2
$options->{"dir"} ||= ref $install ? &$install($options) : $install
$options->{"dir"} ref $install ? &$install($options) : $install
Truth table66%2/3
A ||= B
A= $options->{"dir"}B= ref $install ? &$install($options) : $install
ABresult
1X1
011
000
148 18 ▶ $options->{verbose} = 1 unless defined $options->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options->{"verbose"} 18 0 18
149 18 FFI::Build->new($name, %$options);
150 }
151  
152 sub build
153 8 ▶{
Subroutine build: called CC=2 SCAR=8.1
Pod undocumented
154 8 my($self) = @_;
155 8 ▶ $self->{build} ||= $self->load_build('ffi', undef, $self->sharedir . "/lib");
Condition33%1/3
$self->{"build"} ||= $self->load_build("ffi", undef, $self->sharedir . '/lib')
l!l&&r!l&&!r
080
MC/DC0%0/2
$self->{"build"} ||= $self->load_build("ffi", undef, $self->sharedir . '/lib')
$self->{"build"} $self->load_build("ffi", undef, $self->sharedir . '/lib')
Truth table33%1/3
A ||= B
A= $self->{"build"}B= $self->load_build("ffi", undef, $self->sharedir . '/lib')
ABresult
1X1
011
000
156 }
157  
158 sub test
159 8 ▶{
Subroutine test: called CC=2 SCAR=7.1
Pod undocumented
160 8 my($self) = @_;
161 5 ▶ $self->{test} ||= $self->load_build('t/ffi', 'test', sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
162 5 my($opt) = @_;
163 5 ▶ my $buildname = $opt->{buildname} || '_build';
Condition50%1/2
$opt->{'buildname'} || '_build'
l!l
05
MC/DC0%0/1
$opt->{'buildname'} || '_build'
$opt->{'buildname'}
Truth table50%1/2
A
A= $opt->{'buildname'}
Aresult
11
00
164 5 "t/ffi/$buildname";
165 8 ▶ });
Condition66%2/3
$self->{"test"} ||= $self->load_build("t/ffi", "test", sub { my($opt) = @_; my $buildname = $opt->{"buildname"} || "_build"; "t/ffi/$buildname"; } )
l!l&&r!l&&!r
053
MC/DC50%1/2
$self->{"test"} ||= $self->load_build("t/ffi", "test", sub { my($opt) = @_; my $buildname = $opt->{"buildname"} || "_build"; "t/ffi/$buildname"; } )
$self->{"test"} $self->load_build("t/ffi", "test", sub { my($opt) = @_; my $buildname = $opt->{"buildname"} || "_build"; "t/ffi/$buildname"; } )
Truth table66%2/3
A ||= B
A= $self->{"test"}B= $self->load_build("t/ffi", "test", sub { my($opt) = @_; my $buildname = $opt->{"buildname"} || "_build"; "t/ffi/$buildname"; } )
ABresult
1X1
011
000
166 }
167  
168 sub save_prop
169 5 ▶{
Subroutine save_prop: called CC=2 SCAR=6.9
170 5 my($self) = @_;
171 5 ▶ return unless $self->{save};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"save"} 4 1 5
172 1 open my $fh, '>', 'fbx.json';
173 1 print $fh JSON::PP::encode_json($self->{prop});
174 1 close $fh;
175 }
176  
177 sub load_prop
178 9 ▶{
Subroutine load_prop: called CC=3 SCAR=11.0
Pod undocumented
179 9 my($self) = @_;
180 9 ▶ return unless $self->{save};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"save"} 4 5 9
181 5 ▶ unless(-f 'fbx.json')
Branch: 1 branch
BranchTrueFalseTotal
unless (-f "fbx.json") 2 3 5
182 {
183 2 $self->{prop} = {};
184 2 return;
185 }
186 3 open my $fh, '<', 'fbx.json';
187 3 $self->{prop} = JSON::PP::decode_json(do { local $/; <$fh> });
188 3 close $fh;
189 }
190  
191 sub clean
192 1 ▶{
Subroutine clean: called CC=4 SCAR=14.3
Pod undocumented
193 1 my($self) = @_;
194 1 foreach my $stage (qw( build test ))
195 {
196 2 my $build = $self->$stage;
197 2 ▶ $build->clean if $build;
Branch: 1 branch
BranchTrueFalseTotal
if $build 2 0 2
198 }
199 1 ▶ unlink 'fbx.json' if -f 'fbx.json';
Branch: 1 branch
BranchTrueFalseTotal
if -f "fbx.json" 1 0 1
200 }
201  
202  
203 sub mm_postamble
204 1 ▶{
Subroutine mm_postamble: called CC=1 SCAR=0.0
Pod documented
205 1 my($self) = @_;
206  
207 1 my $postamble = ".PHONY: fbx_build ffi fbx_test ffi-test fbx_clean ffi-clean\n\n";
208  
209 # make fbx_realclean ; make clean
210 1 $postamble .= "realclean :: fbx_clean\n" .
211 "\n" .
212 "fbx_clean ffi-clean:\n" .
213 "\t\$(FULLPERL) -MFFI::Build::MM=cmd -e fbx_clean\n\n";
214  
215 # make fbx_build; make
216 1 $postamble .= "pure_all :: fbx_build\n" .
217 "\n" .
218 "fbx_build ffi:\n" .
219 "\t\$(FULLPERL) -MFFI::Build::MM=cmd -e fbx_build\n\n";
220  
221 # make fbx_test; make test
222 1 $postamble .= "subdirs-test_dynamic subdirs-test_static subdirs-test :: fbx_test\n" .
223 "\n" .
224 "fbx_test ffi-test:\n" .
225 "\t\$(FULLPERL) -MFFI::Build::MM=cmd -e fbx_test\n\n";
226  
227 1 $postamble;
228 }
229  
230 sub action_build
231 1 ▶{
Subroutine action_build: called CC=3 SCAR=11.0
Pod undocumented
232 1 my($self) = @_;
233 1 my $build = $self->build;
234 1 ▶ if($build)
Branch: 1 branch
BranchTrueFalseTotal
if ($build) 1 0 1
235 {
236 1 my $lib = $build->build;
237 1 ▶ if($self->archdir)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->archdir) 1 0 1
238 {
239 1 File::Path::mkpath($self->archdir, 0, oct(755));
240 1 my $archfile = File::Spec->catfile($self->archdir, File::Basename::basename($self->archdir) . ".txt");
241 1 open my $fh, '>', $archfile;
242 1 my $lib_path = $lib->path;
243 1 $lib_path =~ s/^blib\/lib\///;
244 1 print $fh "FFI::Build\@$lib_path\n";
245 1 close $fh;
246 }
247 }
248 1 return;
249 }
250  
251 sub action_test
252 1 ▶{
Subroutine action_test: called CC=2 SCAR=7.1
Pod undocumented
253 1 my($self) = @_;
254 1 my $build = $self->test;
255 1 ▶ $build->build if $build;
Branch: 1 branch
BranchTrueFalseTotal
if $build 1 0 1
256 }
257  
258 sub action_clean
259 1 ▶{
Subroutine action_clean: called CC=1 SCAR=0.0
Pod undocumented
260 1 my($self) = @_;
261 1 my $build = $self->clean;
262 1 ();
263 }
264  
265 sub import
266 2 ▶{
Subroutine import: called CC=3 SCAR=11.0
267 2 my(undef, @args) = @_;
268 2 foreach my $arg (@args)
269 {
270 1 ▶ if($arg eq 'cmd')
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq "cmd") 1 0 1
271 {
272 package main;
273  
274 3 ▶ my $mm = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
275 3 my($action) = @_;
276 3 my $build = FFI::Build::MM->new;
277 3 $build->$action;
278 1 };
279  
280 3 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
281  
282 1 ▶ *fbx_build = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
283 1 $mm->('action_build');
284 1 };
285  
286 1 ▶ *fbx_test = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
287 1 $mm->('action_test');
288 1 };
289  
290 1 ▶ *fbx_clean = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
291 1 $mm->('action_clean');
292 1 };
293 }
294 }
295 }
296  
297 3 1;
298  
299 __END__
« blib/lib/FFI/Platypus/Bundle.pm ↑ Summary lib/FFI/Build.pm »