blib/lib/Specio/Library/Path/Tiny.pm

filter: Statementstmt 99.0% 100 / 101 Branchbran 83.3% 10 / 12 Conditioncond 82.5% 52 / 63 MC/DCmcdc 0.0% 0 / 30 Subroutinesub 97.5% 40 / 41 Podpod n/a totaltotal 81.7% 202 / 247 CC 28 SCAR 8.4
CC
28
Cov
92%
__ANON__
4.3
__ANON__
4.0
__ANON__
4.0
CRAP 2.3
↑ Summary
1 ## no critic (Modules::ProhibitExcessMainComplexity)
2 package Specio::Library::Path::Tiny;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.05';
8  
9 1 ▶use overload ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Path::Tiny 0.087;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Specio 0.29 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Specio::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Specio::Library::Builtins;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Specio::PartialDump qw( partial_dump );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use parent 'Specio::Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 435 ▶my $not_blessed = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
20 435 ▶ return blessed $_[0] ? q{} : "$_[1] is not an object";
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) ? : 246 189 435
21 1 };
22  
23 246 ▶my $not_path_tiny = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
24 246 ▶ return $_[0]->isa('Path::Tiny')
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->isa('Path::Tiny') ? : 48 198 246
25 ? q{}
26 : "$_[1] is not a Path::Tiny object";
27 1 };
28  
29 4 ▶my $not_absolute = sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
30 4 ▶ return $_[0]->is_absolute ? q{} : "$_[0] is not an absolute path";
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->is_absolute ? : 0 4 4
31 1 };
32  
33 10 ▶my $not_real = sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
34 10 ▶ return $_[0]->realpath eq $_[0] ? q{} : "$_[0] is not a real path";
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->realpath eq $_[0] ? : 0 10 10
35 1 };
36  
37 20 ▶my $not_file = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
38 20 ▶ return $_[0]->is_file ? q{} : "$_[0] is not a file on disk";
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->is_file ? : 2 18 20
39 1 };
40  
41 19 ▶my $not_dir = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
42 19 ▶ return $_[0]->is_dir ? q{} : "$_[0] is not a directory on disk";
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->is_dir ? : 3 16 19
43 1 };
44  
45 declare(
46 'Path',
47 parent => object_isa_type('Path::Tiny'),
48 43 ▶ message_generator => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
49 43 my $dump = partial_dump( $_[1] );
50 43 ▶ return $not_blessed->( $_[1], $dump )
Condition66%2/3
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump)
l!l&&r!l&&!r
21220
MC/DC0%0/2
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump)
&$not_blessed($_[1], $dump) &$not_path_tiny($_[1], $dump)
Truth table66%2/3
A || B
A= &$not_blessed($_[1], $dump)B= &$not_path_tiny($_[1], $dump)
ABresult
1X1
011
000
51 || $not_path_tiny->( $_[1], $dump );
52 },
53 1 );
54  
55 declare(
56 'AbsPath',
57 parent => t('Path'),
58 2 ▶ inline => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
59 2 return sprintf(
60 '( %s && %s->is_absolute )',
61 $_[0]->parent->inline_check( $_[1] ),
62 $_[1]
63 );
64 },
65 46 ▶ message_generator => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
66 46 my $dump = partial_dump( $_[1] );
67 return
68 46 ▶ $not_blessed->( $_[1], $dump )
Condition83%5/6
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_absolute($_[1], $dump)
l!l&&r!l&&!r
4330
&$not_blessed($_[1], $dump) or &$not_path_tiny($_[1], $dump)
l!l&&r!l&&!r
21223
MC/DC0%0/3
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_absolute($_[1], $dump)
&$not_blessed($_[1], $dump) &$not_path_tiny($_[1], $dump) &$not_absolute($_[1], $dump)
Truth table75%3/4
A or B || C
A= &$not_blessed($_[1], $dump)B= &$not_path_tiny($_[1], $dump)C= &$not_absolute($_[1], $dump)
ABCresult
1XX1
01X1
0011
0000
69 || $not_path_tiny->( $_[1], $dump )
70 || $not_absolute->( $_[1], $dump );
71 },
72 1 );
73  
74 declare(
75 'RealPath',
76 parent => t('Path'),
77 2 ▶ inline => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
78 2 return sprintf(
79 '( %s && %s->realpath eq %s )',
80 $_[0]->parent->inline_check( $_[1] ),
81 $_[1], $_[1]
82 );
83 },
84 49 ▶ message_generator => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
85 49 my $dump = partial_dump( $_[1] );
86 return
87 49 ▶ $not_blessed->( $_[1], $dump )
Condition83%5/6
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_real($_[1], $dump)
l!l&&r!l&&!r
4360
&$not_blessed($_[1], $dump) or &$not_path_tiny($_[1], $dump)
l!l&&r!l&&!r
21226
MC/DC0%0/3
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_real($_[1], $dump)
&$not_blessed($_[1], $dump) &$not_path_tiny($_[1], $dump) &$not_real($_[1], $dump)
Truth table75%3/4
A or B || C
A= &$not_blessed($_[1], $dump)B= &$not_path_tiny($_[1], $dump)C= &$not_real($_[1], $dump)
ABCresult
1XX1
01X1
0011
0000
88 || $not_path_tiny->( $_[1], $dump )
89 || $not_real->( $_[1], $dump );
90 },
91 1 );
92  
93 declare(
94 'File',
95 parent => t('Path'),
96 2 ▶ inline => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
97 2 return sprintf(
98 '( %s && %s->is_file )',
99 $_[0]->parent->inline_check( $_[1] ),
100 $_[1]
101 );
102 },
103 49 ▶ message_generator => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
104 49 my $dump = partial_dump( $_[1] );
105 return
106 49 ▶ $not_blessed->( $_[1], $dump )
Condition83%5/6
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_file($_[1], $dump)
l!l&&r!l&&!r
4360
&$not_blessed($_[1], $dump) or &$not_path_tiny($_[1], $dump)
l!l&&r!l&&!r
21226
MC/DC0%0/3
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_file($_[1], $dump)
&$not_blessed($_[1], $dump) &$not_path_tiny($_[1], $dump) &$not_file($_[1], $dump)
Truth table75%3/4
A or B || C
A= &$not_blessed($_[1], $dump)B= &$not_path_tiny($_[1], $dump)C= &$not_file($_[1], $dump)
ABCresult
1XX1
01X1
0011
0000
107 || $not_path_tiny->( $_[1], $dump )
108 || $not_file->( $_[1], $dump );
109 },
110 1 );
111  
112 declare(
113 'AbsFile',
114 parent => t('Path'),
115 2 ▶ inline => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
116 2 return sprintf(
117 '( %s && %s->is_file && %s->is_absolute )',
118 $_[0]->parent->inline_check( $_[1] ),
119 $_[1], $_[1]
120 );
121 },
122 49 ▶ message_generator => sub {
Subroutine __ANON__: called CC=4 SCAR=14.6
123 49 my $dump = partial_dump( $_[1] );
124 return
125 49 ▶ $not_blessed->( $_[1], $dump )
Condition66%6/9
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_file($_[1], $dump) || &$not_absolute($_[1], $dump)
l!l&&r!l&&!r
4900
&$not_blessed($_[1], $dump) or &$not_path_tiny($_[1], $dump) or &$not_file($_[1], $dump)
l!l&&r!l&&!r
4360
&$not_blessed($_[1], $dump) or &$not_path_tiny($_[1], $dump)
l!l&&r!l&&!r
21226
MC/DC0%0/4
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_file($_[1], $dump) || &$not_absolute($_[1], $dump)
&$not_blessed($_[1], $dump) &$not_path_tiny($_[1], $dump) &$not_file($_[1], $dump) &$not_absolute($_[1], $dump)
Truth table60%3/5
A or B or C || D
A= &$not_blessed($_[1], $dump)B= &$not_path_tiny($_[1], $dump)C= &$not_file($_[1], $dump)D= &$not_absolute($_[1], $dump)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
126 || $not_path_tiny->( $_[1], $dump )
127 || $not_file->( $_[1], $dump )
128 || $not_absolute->( $_[1], $dump );
129 },
130 1 );
131  
132 declare(
133 'RealFile',
134 parent => t('Path'),
135 2 ▶ inline => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
136 2 return sprintf(
137 '( %s && %s->is_file && %s->realpath eq %s )',
138 $_[0]->parent->inline_check( $_[1] ),
139 $_[1], $_[1], $_[1]
140 );
141 },
142 51 ▶ message_generator => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
143 51 my $dump = partial_dump( $_[1] );
144 return
145 51 ▶ $not_blessed->( $_[1], $dump )
Condition88%8/9
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_file($_[1], $dump) || &$not_real($_[1], $dump)
l!l&&r!l&&!r
4920
&$not_blessed($_[1], $dump) or &$not_path_tiny($_[1], $dump) or &$not_file($_[1], $dump)
l!l&&r!l&&!r
4362
&$not_blessed($_[1], $dump) or &$not_path_tiny($_[1], $dump)
l!l&&r!l&&!r
21228
MC/DC0%0/4
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_file($_[1], $dump) || &$not_real($_[1], $dump)
&$not_blessed($_[1], $dump) &$not_path_tiny($_[1], $dump) &$not_file($_[1], $dump) &$not_real($_[1], $dump)
Truth table80%4/5
A or B or C || D
A= &$not_blessed($_[1], $dump)B= &$not_path_tiny($_[1], $dump)C= &$not_file($_[1], $dump)D= &$not_real($_[1], $dump)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
146 || $not_path_tiny->( $_[1], $dump )
147 || $not_file->( $_[1], $dump )
148 || $not_real->( $_[1], $dump );
149 },
150 1 );
151  
152 declare(
153 'Dir',
154 parent => t('Path'),
155 2 ▶ inline => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
156 2 return sprintf(
157 '( %s && %s->is_dir )',
158 $_[0]->parent->inline_check( $_[1] ),
159 $_[1]
160 );
161 },
162 48 ▶ message_generator => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
163 48 my $dump = partial_dump( $_[1] );
164 return
165 48 ▶ $not_blessed->( $_[1], $dump )
Condition83%5/6
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_dir($_[1], $dump)
l!l&&r!l&&!r
4350
&$not_blessed($_[1], $dump) or &$not_path_tiny($_[1], $dump)
l!l&&r!l&&!r
21225
MC/DC0%0/3
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_dir($_[1], $dump)
&$not_blessed($_[1], $dump) &$not_path_tiny($_[1], $dump) &$not_dir($_[1], $dump)
Truth table75%3/4
A or B || C
A= &$not_blessed($_[1], $dump)B= &$not_path_tiny($_[1], $dump)C= &$not_dir($_[1], $dump)
ABCresult
1XX1
01X1
0011
0000
166 || $not_path_tiny->( $_[1], $dump )
167 || $not_dir->( $_[1], $dump );
168 },
169 1 );
170  
171 declare(
172 'AbsDir',
173 parent => t('Path'),
174 2 ▶ inline => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
175 2 return sprintf(
176 '( %s && %s->is_dir && %s->is_absolute )',
177 $_[0]->parent->inline_check( $_[1] ),
178 $_[1], $_[1],
179 );
180 },
181 49 ▶ message_generator => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
182 49 my $dump = partial_dump( $_[1] );
183 return
184 49 ▶ $not_blessed->( $_[1], $dump )
Condition88%8/9
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_dir($_[1], $dump) || &$not_absolute($_[1], $dump)
l!l&&r!l&&!r
4810
&$not_blessed($_[1], $dump) or &$not_path_tiny($_[1], $dump) or &$not_dir($_[1], $dump)
l!l&&r!l&&!r
4351
&$not_blessed($_[1], $dump) or &$not_path_tiny($_[1], $dump)
l!l&&r!l&&!r
21226
MC/DC0%0/4
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_dir($_[1], $dump) || &$not_absolute($_[1], $dump)
&$not_blessed($_[1], $dump) &$not_path_tiny($_[1], $dump) &$not_dir($_[1], $dump) &$not_absolute($_[1], $dump)
Truth table80%4/5
A or B or C || D
A= &$not_blessed($_[1], $dump)B= &$not_path_tiny($_[1], $dump)C= &$not_dir($_[1], $dump)D= &$not_absolute($_[1], $dump)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
185 || $not_path_tiny->( $_[1], $dump )
186 || $not_dir->( $_[1], $dump )
187 || $not_absolute->( $_[1], $dump );
188 },
189 1 );
190  
191 declare(
192 'RealDir',
193 parent => t('Path'),
194 2 ▶ inline => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
195 2 return sprintf(
196 '( %s && %s->is_dir && %s->realpath eq %s )',
197 $_[0]->parent->inline_check( $_[1] ),
198 $_[1], $_[1], $_[1]
199 );
200 },
201 51 ▶ message_generator => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
202 51 my $dump = partial_dump( $_[1] );
203 return
204 51 ▶ $not_blessed->( $_[1], $dump )
Condition88%8/9
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_dir($_[1], $dump) || &$not_real($_[1], $dump)
l!l&&r!l&&!r
4920
&$not_blessed($_[1], $dump) or &$not_path_tiny($_[1], $dump) or &$not_dir($_[1], $dump)
l!l&&r!l&&!r
4362
&$not_blessed($_[1], $dump) or &$not_path_tiny($_[1], $dump)
l!l&&r!l&&!r
21228
MC/DC0%0/4
&$not_blessed($_[1], $dump) || &$not_path_tiny($_[1], $dump) || &$not_dir($_[1], $dump) || &$not_real($_[1], $dump)
&$not_blessed($_[1], $dump) &$not_path_tiny($_[1], $dump) &$not_dir($_[1], $dump) &$not_real($_[1], $dump)
Truth table80%4/5
A or B or C || D
A= &$not_blessed($_[1], $dump)B= &$not_path_tiny($_[1], $dump)C= &$not_dir($_[1], $dump)D= &$not_real($_[1], $dump)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
205 || $not_path_tiny->( $_[1], $dump )
206 || $not_dir->( $_[1], $dump )
207 || $not_real->( $_[1], $dump );
208 },
209 1 );
210  
211 1 for my $type ( map { t($_) } qw( Path File Dir ) ) {
212 coerce(
213 $type,
214 from => t('Str'),
215 3 ▶ inline => sub {"Path::Tiny::path( $_[1] )"},
Subroutine __ANON__: called CC=1 SCAR=0.0
216 3 );
217  
218 coerce(
219 $type,
220 from => t('ArrayRef'),
221 3 ▶ inline => sub {"Path::Tiny::path( \@{ $_[1] } )"},
Subroutine __ANON__: called CC=1 SCAR=0.0
222 3 );
223 }
224  
225 1 for my $type ( map { t($_) } qw( AbsPath AbsFile AbsDir ) ) {
226 coerce(
227 $type,
228 from => t('Path'),
229 1 ▶ inline => sub { sprintf( '%s->absolute', $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
230 3 );
231  
232 coerce(
233 $type,
234 from => t('Str'),
235 inline =>
236 3 ▶ sub { sprintf( 'Path::Tiny::path( %s )->absolute', $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
237 3 );
238  
239 coerce(
240 $type,
241 from => t('ArrayRef'),
242 inline =>
243 3 ▶ sub { sprintf( 'Path::Tiny::path( @{ %s } )->absolute', $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
244 3 );
245 }
246  
247 1 for my $type ( map { t($_) } qw( RealPath RealFile RealDir ) ) {
248 coerce(
249 $type,
250 from => t('Path'),
251 0 ▶ inline => sub { sprintf( '%s->realpath', $_[1] ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
252 3 );
253  
254 coerce(
255 $type,
256 from => t('Str'),
257 inline =>
258 3 ▶ sub { sprintf( 'Path::Tiny::path( %s )->realpath', $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
259 3 );
260  
261 coerce(
262 $type,
263 from => t('ArrayRef'),
264 inline =>
265 3 ▶ sub { sprintf( 'Path::Tiny::path( @{ %s } )->realpath', $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
266 3 );
267 }
268  
269 1 1;
270  
271 # ABSTRACT: Path::Tiny types and coercions for Specio
272  
273 __END__
↑ Summary