blib/lib/Alien/Build/Plugin/Test/Mock.pm

filter: Statementstmt 94.0% 94 / 100 Branchbran 78.5% 33 / 42 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 23 / 23 Podpod 100% 1 / 1 totaltotal 90.9% 151 / 166 CC 25 SCAR 18.5
CC
25
Cov
89%
init
14.5
_fs
7.2
__ANON__
4.9
CRAP 6.4
« blib/lib/Alien/Build/Plugin/Fetch/LocalDir.pm ↑ Summary blib/lib/Alien/Build/Plugin/Probe/CBuilder.pm »
1 package Alien::Build::Plugin::Test::Mock;
2  
3 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 19 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 19 ▶use Alien::Build::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 19 ▶use Path::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 19 ▶use File::chdir;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # ABSTRACT: Mock plugin for testing
12 19 our $VERSION = '2.88'; # VERSION
13  
14  
15 19 has 'probe';
16  
17  
18 19 has 'download';
19  
20  
21 19 has 'extract';
22  
23  
24 19 has 'build';
25  
26  
27 19 has 'gather';
28  
29  
30 19 has check_digest => 1;
31  
32 sub init
33 65 ▶{
Subroutine init: called CC=14 SCAR=26.7
Pod documented
34 65 my($self, $meta) = @_;
35  
36 65 ▶ if(my $probe = $self->probe)
Branch: 1 branch
BranchTrueFalseTotal
if (my $probe = $self->probe) 48 17 65
37 {
38 48 ▶ if($probe =~ /^(share|system)$/)
Branch: 2 branches
BranchTrueFalseTotal
if ($probe =~ /^(share|system)$/) { } 47 1 48
elsif ($probe eq 'die') { } 1 0 1
39 {
40 $meta->register_hook(
41 34 ▶ probe => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
42 34 $probe;
43 },
44 47 );
45 }
46 elsif($probe eq 'die')
47 {
48 $meta->register_hook(
49 1 ▶ probe => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
50 1 die "fail";
51 },
52 1 );
53 }
54 else
55 {
56 0 Carp::croak("usage: plugin 'Test::Mock' => ( probe => $probe ); where $probe is one of share, system or die");
57 }
58 }
59  
60 65 ▶ if(my $download = $self->download)
Branch: 1 branch
BranchTrueFalseTotal
if (my $download = $self->download) 41 24 65
61 {
62 41 ▶ $download = { 'foo-1.00.tar.gz' => _tarball() } unless ref $download eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $download eq "HASH" 36 5 41
63 $meta->register_hook(
64 30 ▶ download => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
65 30 my($build) = @_;
66 30 _fs($build, $download, 1);
67 },
68 41 );
69 }
70  
71 65 ▶ if(my $extract = $self->extract)
Branch: 1 branch
BranchTrueFalseTotal
if (my $extract = $self->extract) 34 31 65
72 {
73 34 ▶ $extract = {
Branch: 1 branch
BranchTrueFalseTotal
unless ref $extract eq "HASH" 24 10 34
74 'foo-1.00' => {
75 'configure' => _tarball_configure(),
76 'foo.c' => _tarball_foo_c(),
77 },
78 } unless ref $extract eq 'HASH';
79 $meta->register_hook(
80 47 ▶ extract => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
81 47 my($build) = @_;
82 47 _fs($build, $extract);
83 },
84 34 );
85 }
86  
87 65 ▶ if(my $build = $self->build)
Branch: 1 branch
BranchTrueFalseTotal
if (my $build = $self->build) 11 54 65
88 {
89 $build = [
90 {
91 'foo.o', => _build_foo_o(),
92 'libfoo.a' => _build_libfoo_a(),
93 },
94 {
95 'lib' => {
96 'libfoo.a' => _build_libfoo_a(),
97 'pkgconfig' => {
98 6 ▶ 'foo.pc' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
99 6 my($build) = @_;
100 6 "prefix=$CWD\n" .
101 "exec_prefix=\${prefix}\n" .
102 "libdir=\${prefix}/lib\n" .
103 "includedir=\${prefix}/include\n" .
104 "\n" .
105 "Name: libfoo\n" .
106 "Description: libfoo\n" .
107 "Version: 1.0.0\n" .
108 "Cflags: -I\${includedir}\n" .
109 "Libs: -L\${libdir} -lfoo\n";
110 },
111 },
112 },
113 },
114 11 ▶ ] unless ref $build eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $build eq "ARRAY" 10 1 11
115  
116 11 my($build_dir, $install_dir) = @$build;
117  
118 $meta->register_hook(
119 7 ▶ build => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
120 7 my($build) = @_;
121 7 _fs($build, $build_dir);
122 7 local $CWD = $build->install_prop->{prefix};
123 7 _fs($build, $install_dir);
124 },
125 11 );
126 }
127  
128 65 ▶ if(my $gather = $self->gather)
Branch: 1 branch
BranchTrueFalseTotal
if (my $gather = $self->gather) 4 61 65
129 {
130 $meta->register_hook(
131 4 ▶ $_ => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
132 4 my($build) = @_;
133 4 ▶ if(ref $gather eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $gather eq 'HASH') { } 2 2 4
134 {
135 2 foreach my $key (keys %$gather)
136 {
137 4 $build->runtime_prop->{$key} = $gather->{$key};
138 }
139 }
140 else
141 {
142 2 my $prefix = $build->runtime_prop->{prefix};
143 2 $build->runtime_prop->{cflags} = "-I$prefix/include";
144 2 $build->runtime_prop->{libs} = "-L$prefix/lib -lfoo";
145 }
146 },
147 4 ) for qw( gather_share gather_system );
148 }
149  
150 65 ▶ if(my $cd = $self->check_digest)
Branch: 1 branch
BranchTrueFalseTotal
if (my $cd = $self->check_digest) 65 0 65
151 {
152 $meta->register_hook(
153 82 ▶ check_digest => ref($cd) eq 'CODE' ? $cd : sub {
Subroutine __ANON__: called CC=3 SCAR=16.0
154 82 my($build, $file, $algorithm, $digest) = @_;
155 82 ▶ if($algorithm ne 'FOO92')
Branch: 1 branch
BranchTrueFalseTotal
if ($algorithm ne "FOO92") 82 0 82
156 {
157 82 return 'FAKE';
158 }
159 0 ▶ if($digest eq 'deadbeaf')
Branch: 1 branch
BranchTrueFalseTotal
if ($digest eq 'deadbeaf') { } 0 0 0
160 {
161 0 return 1;
162 }
163 else
164 {
165 0 die "Digest FAKE does not match: got deadbeaf, expected $digest";
166 }
167 }
168 65 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
ref $cd eq 'CODE' ? : 0 65 65
169 $meta->register_hook(
170 37 ▶ check_download => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
171 37 my($build) = @_;
172 37 my $path = $build->install_prop->{download};
173 37 ▶ if(defined $path)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $path) 37 0 37
174 {
175 37 $build->check_digest($path);
176 }
177 },
178 65 );
179 }
180 }
181  
182 sub _fs
183 139 ▶{
Subroutine _fs: called CC=7 SCAR=19.7
184 139 my($build, $hash, $download) = @_;
185  
186 139 foreach my $key (sort keys %$hash)
187 {
188 199 my $val = $hash->{$key};
189 199 ▶ if(ref $val eq 'HASH')
Branch: 3 branches
BranchTrueFalseTotal
if (ref $val eq 'HASH') { } 48 151 199
elsif (ref $val eq 'CODE') { } 6 145 151
elsif (defined $val) { } 145 0 145
190 {
191 48 mkdir $key;
192 48 local $CWD = $key;
193 48 _fs($build,$val);
194 }
195 elsif(ref $val eq 'CODE')
196 {
197 6 my $path = Path::Tiny->new($key)->absolute;
198 6 $path->spew_raw($val->($build));
199 6 ▶ if($download)
Branch: 1 branch
BranchTrueFalseTotal
if ($download) 0 6 6
200 {
201 0 $build->install_prop->{download_detail}->{"$path"}->{protocol} = 'file';
202 0 $build->install_prop->{download_detail}->{"$path"}->{digest} = [ FAKE => 'deadbeaf' ];
203 }
204 }
205 elsif(defined $val)
206 {
207 145 my $path = Path::Tiny->new($key)->absolute;
208 145 $path->spew_raw($val);
209 145 ▶ if($download)
Branch: 1 branch
BranchTrueFalseTotal
if ($download) 30 115 145
210 {
211 30 $build->install_prop->{download_detail}->{"$path"}->{protocol} = 'file';
212 30 $build->install_prop->{download_detail}->{"$path"}->{digest} = [ FAKE => 'deadbeaf' ];
213 }
214 }
215 }
216 }
217  
218 sub _tarball
219 36 ▶{
Subroutine _tarball: called CC=1 SCAR=0.0
220 36 return unpack 'u', <<'EOF';
221 M'XL(`+DM@5@``^V4P4K$,!"&>YZGF-V]J*SM9#=)#RN^B'BHV;0)U`32U(OX
222 M[D;0*LJREZVRF.\R?TA@)OS\TWI_S4JBJI@/(JJ%P%19+>AKG4"V)4Z;C922
223 M(;T=6(%BQIDFQB$V(8WB^]X.W>%WQ^[?_S'5,Z']\%]YU]IN#/KT/8[ZO^6?
224 M_B=-C-=<%$BG'^4G_]S_U:)ZL*X:#(!6QN/26(Q&![W<P5_/EIF?*?])E&J>
225 M'BD/DO/#^6<DON__6O*<_]]@99WJQ[W&FR'NK2_-+8!U$1X;ZRZ2P"9T:HW*
226 D-`&ODGZZN[^$9T`,.H[!(>W@)2^*3":3.3]>`:%LBYL`#@``
227 `
228 EOF
229 }
230  
231 sub _tarball_configure
232 24 ▶{
Subroutine _tarball_configure: called CC=1 SCAR=0.0
233 24 return unpack 'u', <<'EOF';
234 <(R$O8FEN+W-H"@IE8VAO(")H:2!T:&5R92(["@``
235 `
236 EOF
237 }
238  
239 sub _tarball_foo_c
240 24 ▶{
Subroutine _tarball_foo_c: called CC=1 SCAR=0.0
241 24 return unpack 'u', <<'EOF';
242 M(VEN8VQU9&4@/'-T9&EO+F@^"@II;G0*;6%I;BAI;G0@87)G8RP@8VAA<B`J
243 887)G=EM=*0I["B`@<F5T=7)N(#`["GT*
244 `
245 EOF
246 }
247  
248 sub _build_foo_o
249 10 ▶{
Subroutine _build_foo_o: called CC=1 SCAR=0.0
250 10 return unpack 'u', <<'EOF';
251 MS_KM_@<```$#`````0````0```"P`0```"`````````9````.`$`````````
252 M`````````````````````````&@`````````T`$```````!H``````````<`
253 M```'`````P````````!?7W1E>'0`````````````7U]415A4````````````
254 M````````````"`````````#0`0``!`````````````````0`@```````````
255 M`````%]?8V]M<&%C=%]U;G=I;F1?7TQ$````````````````"``````````@
256 M`````````-@!```#````.`(```$````````"````````````````7U]E:%]F
257 M<F%M90```````%]?5$585``````````````H`````````$``````````^`$`
258 M``,```````````````L``&@````````````````D````$``````-"@``````
259 M`@```!@```!``@```0```%`"```(````"P```%`````````````````````!
260 M`````0``````````````````````````````````````````````````````
261 M``````````````````!52(GE,<!=PP``````````"`````````$`````````
262 M````````````%``````````!>E(``7@0`1`,!PB0`0``)````!P```"X____
263 M_____P@``````````$$.$(8"0PT&```````````````!```&`0````\!````
264 /``````````!?;6%I;@``
265 `
266 EOF
267 }
268  
269 sub _build_libfoo_a
270 20 ▶{
Subroutine _build_libfoo_a: called CC=1 SCAR=0.0
271 20 return unpack 'u', <<'EOF';
272 M(3QA<F-H/@HC,2\R,"`@("`@("`@("`@,34S,S$U-38Q."`@-3`Q("`@,C`@
273 M("`@,3`P-C0T("`T-"`@("`@("`@8`I?7RY364U$148@4T]25$5$``````@`
274 M````````<`````@```!?;6%I;@```",Q+S$R("`@("`@("`@("`Q-3,S,34U
275 M-#8X("`U,#$@("`R,"`@("`Q,#`V-#0@(#8Q,B`@("`@("!@"F9O;RYO````
276 M`````,_Z[?X'```!`P````$````$````L`$````@````````&0```#@!````
277 M``````````````````````````````!H`````````-`!````````:```````
278 M```'````!P````,`````````7U]T97AT`````````````%]?5$585```````
279 M``````````````````@`````````T`$```0````````````````$`(``````
280 M``````````!?7V-O;7!A8W1?=6YW:6YD7U],1`````````````````@`````
281 M````(`````````#8`0```P```#@"```!`````````@```````````````%]?
282 M96A?9G)A;64```````!?7U1%6%0`````````````*`````````!`````````
283 M`/@!```#```````````````+``!H````````````````)````!``````#0H`
284 M``````(````8````0`(```$```!0`@``"`````L```!0````````````````
285 M`````0````$`````````````````````````````````````````````````
286 M````````````````````````54B)Y3'`7<,```````````@````````!````
287 M`````````````````!0``````````7I2``%X$`$0#`<(D`$``"0````<````
288 MN/________\(``````````!!#A"&`D,-!@```````````````0``!@$````/
289 3`0``````````````7VUA:6X`````
290 `
291 EOF
292 }
293  
294 19 1;
295  
296 __END__
« blib/lib/Alien/Build/Plugin/Fetch/LocalDir.pm ↑ Summary blib/lib/Alien/Build/Plugin/Probe/CBuilder.pm »