Usul/Functions.pm

filter: Statementstmt 93.9% 509 / 542 Branchbran 66.3% 162 / 244 Conditioncond 54.4% 117 / 215 MC/DCmcdc 28.6% 35 / 122 Subroutinesub 92.3% 133 / 144 Podpod 100% 83 / 83 totaltotal 76.9% 1039 / 1350 CC 214 SCAR 18.4
CC
214
Cov
79%
urandom
24.8
find_apphome
17.8
base64_decode_ns
15.8
CRAP 6.3
« Usul/Log.pm ↑ Summary Usul/Config.pm »
1 package Class::Usul::Functions;
2  
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use parent 'Exporter::Tiny';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 27 ▶use Class::Inspector;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 27 ▶use Class::Null;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 27 ▶use Class::Usul::Constants qw( ASSERT DEFAULT_CONFHOME DEFAULT_ENVDIR
Subroutine BEGIN: called CC=1 SCAR=0.0
10 DIGEST_ALGORITHMS EXCEPTION_CLASS
11 PERL_EXTNS PREFIX UNTAINT_CMDLINE
12 27 UNTAINT_IDENTIFIER UNTAINT_PATH UUID_PATH );
13 27 ▶use Cwd qw( );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 27 ▶use Data::Printer alias => q(_data_dumper), colored => 1, indent => 3,
Subroutine BEGIN: called CC=1 SCAR=1.6
15 0 ▶ filters => { 'DateTime' => sub { $_[ 0 ].q() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
16 8 ▶ 'File::DataClass::IO' => sub { $_[ 0 ]->pathname },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 0 ▶ 'JSON::XS::Boolean' => sub { $_[ 0 ].q() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 0 ▶ 'Type::Tiny' => sub { $_[ 0 ]->display_name },
Subroutine __ANON__: not called CC=1 SCAR=6.9
19 0 ▶ 'Type::Tiny::Enum' => sub { $_[ 0 ]->display_name },
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 0 ▶ 'Type::Tiny::Union' => sub { $_[ 0 ]->display_name }, };
Subroutine __ANON__: not called CC=1 SCAR=0.2
21 27 ▶use Digest qw( );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 27 ▶use Digest::MD5 qw( md5 );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 27 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
24 27 ▶use Fcntl qw( F_SETFL O_NONBLOCK );
Subroutine BEGIN: called CC=1 SCAR=0.0
25 27 ▶use File::Basename qw( basename dirname );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 27 ▶use File::DataClass::Functions qw( supported_extensions );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 27 ▶use File::DataClass::IO qw( );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 27 ▶use File::HomeDir qw( );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 27 ▶use File::Spec::Functions qw( canonpath catdir catfile curdir );
Subroutine BEGIN: called CC=1 SCAR=0.0
30 27 ▶use List::Util qw( first );
Subroutine BEGIN: called CC=1 SCAR=0.0
31 27 ▶use Module::Runtime qw( is_module_name require_module );
Subroutine BEGIN: called CC=1 SCAR=0.0
32 27 ▶use Scalar::Util qw( blessed openhandle );
Subroutine BEGIN: called CC=1 SCAR=0.0
33 27 ▶use Socket qw( AF_UNIX SOCK_STREAM PF_UNSPEC );
Subroutine BEGIN: called CC=1 SCAR=0.0
34 27 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 27 ▶use Sys::Hostname qw( hostname );
Subroutine BEGIN: called CC=1 SCAR=0.0
36 27 ▶use Unexpected::Functions qw( is_class_loaded PathAlreadyExists
Subroutine BEGIN: called CC=1 SCAR=0.0
37 27 PathNotFound Tainted Unspecified );
38 27 ▶use User::pwent;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 27 our @EXPORT_OK = qw( abs_path app_prefix arg_list assert assert_directory
41 base64_decode_ns base64_encode_ns bsonid bsonid_time
42 bson64id bson64id_time canonicalise class2appdir
43 classdir classfile create_token create_token64 cwdp
44 dash2under data_dumper digest distname elapsed emit
45 emit_err emit_to ensure_class_loaded env_prefix
46 escape_TT exception find_apphome find_source first_char
47 fqdn fullname get_cfgfiles get_user hex2str home2appldir
48 io is_arrayref is_coderef is_hashref is_member is_win32
49 list_attr_of loginid logname merge_attributes my_prefix
50 nonblocking_write_pipe_pair ns_environment pad
51 prefix2class socket_pair split_on__ split_on_dash
52 squeeze strip_leader sub_name symlink thread_id throw
53 throw_on_error trim unescape_TT untaint_cmdline
54 untaint_identifier untaint_path untaint_string urandom
55 uuid whiten zip chain compose curry fold Y factorial
56 fibonacci product sum );
57  
58 4 ▶our %EXPORT_REFS = ( assert => sub { ASSERT }, );
Subroutine __ANON__: called CC=1 SCAR=0.0
59 27 our %EXPORT_TAGS = ( all => [ @EXPORT_OK ], );
60  
61 # Package variables
62 27 my $bson_id_count : shared = 0;
63 27 my $bson2_id_count = 0;
64 27 my $bson2_prev_time = 0;
65 27 my $digest_cache;
66 27 my $host_id = substr md5( hostname ), 0, 3;
67  
68 # Private functions
69 2 ▶my $_base64_char_set = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
70 2 return [ 0 .. 9, 'A' .. 'Z', '_', 'a' .. 'z', '~', '+' ];
71 27 };
72  
73 2 ▶my $_bsonid_inc = sub {
Subroutine __ANON__: called CC=5 SCAR=16.8
74 2 my ($now, $version) = @_;
75  
76 2 ▶ $version or return substr pack( 'N', $bson_id_count++ % 0xFFFFFF ), 1, 3;
Branch: 1 branch
BranchTrueFalseTotal
$version or return substr(pack("N", $bson_id_count++ % 16777215), 1, 3) 1 1 2
77  
78 1 ▶ $bson2_id_count++; $now > $bson2_prev_time and $bson2_id_count = 0;
Branch: 1 branch
BranchTrueFalseTotal
$now > $bson2_prev_time and $bson2_id_count = 0 1 0 1
79 1 $bson2_prev_time = $now;
80  
81 1 ▶ $version < 2 and return (substr pack( 'n', thread_id() % 0xFF ), 1, 1)
Branch: 1 branch
BranchTrueFalseTotal
$version < 2 and return substr(pack("n", &thread_id() % 255), 1, 1) . pack("n", $bson2_id_count % 65535) 0 1 1
82 .(pack 'n', $bson2_id_count % 0xFFFF);
83  
84 1 ▶ $version < 3 and return (pack 'n', thread_id() % 0xFFFF )
Branch: 1 branch
BranchTrueFalseTotal
$version < 3 and return pack("n", &thread_id() % 65535) . pack("n", $bson2_id_count % 65535) 1 0 1
85 .(pack 'n', $bson2_id_count % 0xFFFF);
86  
87 0 return (pack 'n', thread_id() % 0xFFFF )
88 .(substr pack( 'N', $bson2_id_count % 0xFFFFFF ), 1, 3);
89 27 };
90  
91 2 ▶my $_bsonid_time = sub {
Subroutine __ANON__: called CC=4 SCAR=14.6
92 2 my ($now, $version) = @_;
93  
94 2 ▶ (not $version or $version < 2) and return pack 'N', $now;
Branch: 1 branch
BranchTrueFalseTotal
!$version || $version < 2 and return pack("N", $now) 1 1 2
Condition66%2/3
not $version or $version < 2
l!l&&r!l&&!r
101
MC/DC50%1/2
not $version or $version < 2
not $version $version < 2
Truth table66%2/3
not(A) or B
A= not $versionB= $version < 2
ABresult
1X1
011
000
95  
96 1 ▶ $version < 3 and return (substr pack( 'N', $now >> 32 ), 2, 2)
Branch: 1 branch
BranchTrueFalseTotal
$version < 3 and return substr(pack("N", $now >> 32), 2, 2) . pack("N", $now % 4294967295) 1 0 1
97 .(pack 'N', $now % 0xFFFFFFFF);
98  
99 0 return (pack 'N', $now >> 32).(pack 'N', $now % 0xFFFFFFFF);
100 27 };
101  
102 307 ▶my $_catpath = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
103 307 return untaint_path( catfile( @_ ) );
104 27 };
105  
106 21 ▶my $_get_env_var_for_conf = sub {
Subroutine __ANON__: called CC=4 SCAR=15.2
107 21 ▶ my $file = $ENV{ ($_[ 0 ] || return) };
Condition50%1/2
$_[0] || (return)
l!l
210
MC/DC0%0/1
$_[0] || (return)
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
108 21 ▶ my $path = $file ? dirname( $file ) : q();
Branch: 1 branch
BranchTrueFalseTotal
$file ? : 0 21 21
109  
110 21 ▶ return $path = assert_directory( $path ) ? $path : undef;
Branch: 1 branch
BranchTrueFalseTotal
&assert_directory($path) ? : 0 21 21
111 27 };
112  
113 45 ▶my $_get_pod_content_for_attr = sub {
Subroutine __ANON__: called CC=12 SCAR=26.4
114 45 my ($class, $attr) = @_; my $pod;
115  
116 45 ▶ my $src = find_source( $class )
Branch: 1 branch
BranchTrueFalseTotal
my $src = &find_source($class) or &throw("Class [_1] cannot find source", [$class]) 45 0 45
117 or throw( 'Class [_1] cannot find source', [ $class ] );
118 45 my $events = Pod::Eventual::Simple->read_file( $src );
119  
120 45 ▶ for (my $ev_no = 0, my $max = @{ $events }; $ev_no < $max; $ev_no++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ev_no < $max) 4158 0 4158
121 4158 ▶ my $ev = $events->[ $ev_no ]; $ev->{type} eq 'command' or next;
Branch: 1 branch
BranchTrueFalseTotal
$ev->{"type"} eq "command" or next 1025 3133 4158
122  
123 1025 ▶ $ev->{content} =~ m{ (?: ^|[< ]) $attr (?: [ >]|$ ) }msx or next;
Branch: 1 branch
BranchTrueFalseTotal
$ev->{"content"} =~ / (?: ^|[< ]) $attr (?: [ >]|$ ) /msx or next 45 980 1025
124  
125 45 ▶ $ev_no++ while ($ev = $events->[ $ev_no + 1 ] and $ev->{type} eq 'blank');
Branch: 1 branch
BranchTrueFalseTotal
$ev = $$events[$ev_no + 1] and $ev->{"type"} eq "blank" and do { ++$ev_no } 45 45 90
Condition66%2/3
$ev = $$events[$ev_no + 1] and $ev->{"type"} eq "blank"
!ll&&!rl&&r
04545
MC/DC50%1/2
$ev = $$events[$ev_no + 1] and $ev->{"type"} eq "blank"
$ev = $$events[$ev_no + 1] $ev->{"type"} eq "blank"
Truth table66%2/3
A and B
A= $ev = $$events[$ev_no + 1]B= $ev->{"type"} eq "blank"
ABresult
0X0
100
111
126  
127 45 ▶ $ev and $ev->{type} eq 'text' and $pod = $ev->{content} and last;
Branch: 1 branch
BranchTrueFalseTotal
$ev and $ev->{"type"} eq "text" and $pod = $ev->{"content"} and last 45 0 45
Condition33%2/6
$ev and $ev->{"type"} eq "text" and $pod = $ev->{"content"}
!ll&&!rl&&r
0045
$ev and $ev->{"type"} eq "text"
!ll&&!rl&&r
0045
MC/DC0%0/3
$ev and $ev->{"type"} eq "text" and $pod = $ev->{"content"}
$ev $ev->{"type"} eq "text" $pod = $ev->{"content"}
Truth table25%1/4
A and B and C
A= $evB= $ev->{"type"} eq "text"C= $pod = $ev->{"content"}
ABCresult
0XX0
10X0
1100
1111
128 }
129  
130 45 ▶ $pod //= 'Undocumented'; chomp $pod; $pod =~ s{ [\n] }{ }gmx;
Condition50%1/2
$pod //= "Undocumented"
l!l
450
MC/DC0%0/1
$pod //= "Undocumented"
$pod
Truth table50%1/2
A
A= $pod
Aresult
11
00
131  
132 45 ▶ $pod = squeeze( $pod ); $pod =~ m{ \A (.+) \z }msx and $pod = $1;
Branch: 1 branch
BranchTrueFalseTotal
$pod =~ / \A (.+) \z /msx and $pod = $1 45 0 45
133  
134 45 return $pod;
135 27 };
136  
137 2 ▶my $_index64 = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
138 2 return [ qw(XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
139 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
140 XX XX XX XX XX XX XX XX XX XX XX 64 XX XX XX XX
141 0 1 2 3 4 5 6 7 8 9 XX XX XX XX XX XX
142 XX 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
143 25 26 27 28 29 30 31 32 33 34 35 XX XX XX XX 36
144 XX 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
145 52 53 54 55 56 57 58 59 60 61 62 XX XX XX 63 XX
146  
147 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
148 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
149 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
150 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
151 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
152 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
153 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
154 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX) ];
155 27 };
156  
157 0 ▶my $_pseudo_random = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
158 0 return join q(), time, rand 10_000, $PID, {};
159 27 };
160  
161 2 ▶my $_bsonid = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
162 2 my $version = shift;
163 2 my $now = time;
164 2 my $time = $_bsonid_time->( $now, $version );
165 2 my $pid = pack 'n', $PID % 0xFFFF;
166  
167 2 return $time.$host_id.$pid.$_bsonid_inc->( $now, $version );
168 27 };
169  
170 42 ▶my $_find_cfg_in_inc = sub {
Subroutine __ANON__: called CC=6 SCAR=18.0
171 42 my ($classdir, $file, $extns) = @_;
172  
173 42 ▶ for my $dir (grep { defined and -d $_ }
Condition100%3/3
defined $_ && -d $_
!ll&&!rl&&r
38286120
MC/DC100%2/2
defined $_ && -d $_
defined $_ -d $_
Truth table100%3/3
A && B
A= defined $_B= -d $_
ABresult
0X0
100
111
174 588 map { abs_path( catdir( $_, $classdir ) ) } @INC) {
175 120 ▶ for my $extn (@{ $extns // [ supported_extensions() ] }) {
Condition50%1/2
$extns // [&supported_extensions()]
l!l
0120
MC/DC0%0/1
$extns // [&supported_extensions()]
$extns
Truth table50%1/2
A
A= $extns
Aresult
11
00
176 144 my $path = $_catpath->( $dir, $file.$extn );
177  
178 144 ▶ -f $path and return dirname( $path );
Branch: 1 branch
BranchTrueFalseTotal
-f $path and return dirname($path) 0 144 144
179 }
180 }
181  
182 42 return;
183 27 };
184  
185 63 ▶my $_read_variable = sub {
Subroutine __ANON__: called CC=7 SCAR=24.7
186 63 my ($dir, $file, $variable) = @_; my $path;
187  
188 63 ▶ ($dir and $file and $variable) or return;
Branch: 1 branch
BranchTrueFalseTotal
$dir and $file and $variable or return 63 0 63
Condition33%2/6
$dir and $file and $variable
!ll&&!rl&&r
0063
$dir and $file
!ll&&!rl&&r
0063
MC/DC0%0/3
$dir and $file and $variable
$dir $file $variable
Truth table25%1/4
A and B and C
A= $dirB= $fileC= $variable
ABCresult
0XX0
10X0
1100
1111
189 63 ▶ is_arrayref( $dir ) and $dir = catdir( @{ $dir } );
Branch: 1 branch
BranchTrueFalseTotal
&is_arrayref($dir) and $dir = catdir(@{$dir;}) 21 42 63
190 63 $path = io( $_catpath->( $dir, $file ) )->chomp;
191 63 ▶ ($path->exists and $path->is_file) or return;
Branch: 1 branch
BranchTrueFalseTotal
$path->exists and $path->is_file or return 0 63 63
Condition33%1/3
$path->exists and $path->is_file
!ll&&!rl&&r
6300
MC/DC0%0/2
$path->exists and $path->is_file
$path->exists $path->is_file
Truth table33%1/3
A and B
A= $path->existsB= $path->is_file
ABresult
0X0
100
111
192  
193 0 ▶ return first { length }
Subroutine __ANON__: not called CC=1 SCAR=6.9
194 0 map { trim( (split '=', $_)[ 1 ] ) }
195 0 grep { m{ \A \s* $variable \s* [=] }mx }
196 reverse $path->getlines;
197 27 };
198  
199 42 ▶my $_get_file_var = sub {
Subroutine __ANON__: called CC=3 SCAR=11.4
200 42 my ($dir, $file, $classdir) = @_;
201  
202 42 ▶ my $path; $path = $_read_variable->( $dir, ".${file}", 'APPLDIR' )
Branch: 1 branch
BranchTrueFalseTotal
$path = &$_read_variable($dir, ".$file", "APPLDIR") and $path = catdir($path, "lib", $classdir) 0 42 42
203 and $path = catdir( $path, 'lib', $classdir );
204  
205 42 ▶ return $path = assert_directory( $path ) ? $path : undef;
Branch: 1 branch
BranchTrueFalseTotal
&assert_directory($path) ? : 0 42 42
206 27 };
207  
208 21 ▶my $_get_known_file_var = sub {
Subroutine __ANON__: called CC=4 SCAR=14.6
209 21 ▶ my ($appname, $classdir) = @_; length $appname or return;
Branch: 1 branch
BranchTrueFalseTotal
length $appname or return 21 0 21
210  
211 21 ▶ my $path; $path = $_read_variable->( DEFAULT_ENVDIR(), $appname, 'APPLDIR' )
Branch: 1 branch
BranchTrueFalseTotal
$path = &$_read_variable(&DEFAULT_ENVDIR(), $appname, "APPLDIR") and $path = catdir($path, "lib", $classdir) 0 21 21
212 and $path = catdir( $path, 'lib', $classdir );
213  
214 21 ▶ return $path = assert_directory( $path ) ? $path : undef;
Branch: 1 branch
BranchTrueFalseTotal
&assert_directory($path) ? : 0 21 21
215 27 };
216  
217 # Construction
218 4 ▶sub _exporter_fail {
Subroutine _exporter_fail: called CC=2 SCAR=8.1
219 4 my ($class, $name, $value, $globals) = @_;
220  
221 exists $EXPORT_REFS{ $name }
222 4 ▶ and return ( $name => $EXPORT_REFS{ $name }->() );
Branch: 1 branch
BranchTrueFalseTotal
exists $Class::Usul::Functions::EXPORT_REFS{$name} and return $name, $Class::Usul::Functions::EXPORT_REFS{$name}->() 4 0 4
223  
224 0 throw( 'Subroutine [_1] not found in package [_2]', [ $name, $class ] );
225 }
226  
227 # Public functions
228 968 ▶sub abs_path ($) {
Subroutine abs_path: called CC=7 SCAR=21.0
Pod documented
229 968 ▶ my $v = shift; (defined $v and length $v) or return $v;
Branch: 1 branch
BranchTrueFalseTotal
defined $v and length $v or return $v 842 126 968
Condition100%3/3
defined $v and length $v
!ll&&!rl&&r
10521842
MC/DC100%2/2
defined $v and length $v
defined $v length $v
Truth table100%3/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
230  
231 842 ▶ is_ntfs() and not -e $v and return untaint_path( $v ); # Hate
Branch: 1 branch
BranchTrueFalseTotal
&is_ntfs() and not -e $v and return &untaint_path($v) 0 842 842
Condition33%1/3
&is_ntfs() and not -e $v
!ll&&!rl&&r
84200
MC/DC0%0/2
&is_ntfs() and not -e $v
&is_ntfs() not -e $v
Truth table33%1/3
A and not(B)
A= &is_ntfs()B= not -e $v
ABresult
0X0
100
111
232  
233 842 $v = Cwd::abs_path( untaint_path( $v ) );
234  
235 842 ▶ is_win32() and defined $v and $v =~ s{ / }{\\}gmx; # More hate
Branch: 1 branch
BranchTrueFalseTotal
&is_win32() and defined $v and $v =~ s[ / ][\\]gmx 0 842 842
Condition33%1/3
&is_win32() and defined $v
!ll&&!rl&&r
84200
MC/DC0%0/2
&is_win32() and defined $v
&is_win32() defined $v
Truth table33%1/3
A and B
A= &is_win32()B= defined $v
ABresult
0X0
100
111
236  
237 842 return $v;
238 }
239  
240 93 ▶sub app_prefix ($) {
Subroutine app_prefix: called CC=2 SCAR=6.9
Pod documented
241 93 ▶ (my $v = lc ($_[ 0 ] // q())) =~ s{ :: }{_}gmx; return $v;
Condition100%2/2
$_[0] // ""
l!l
921
MC/DC100%1/1
$_[0] // ""
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
242 }
243  
244 364 ▶sub arg_list (;@) {
Subroutine arg_list: called CC=4 SCAR=13.9
Pod documented
245 364 ▶ return $_[ 0 ] && ref $_[ 0 ] eq 'HASH' ? { %{ $_[ 0 ] } }
Branch: 2 branches
BranchTrueFalseTotal
$_[0] && ref $_[0] eq 'HASH' ? : 271 93 364
$_[0] ? : 5 88 93
Condition100%3/3
$_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
885271
MC/DC100%2/2
$_[0] and ref $_[0] eq "HASH"
$_[0] ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= $_[0]B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
246 : $_[ 0 ] ? { @_ }
247 : {};
248 }
249  
250 212 ▶sub assert_directory ($) {
Subroutine assert_directory: called CC=4 SCAR=13.9
Pod documented
251 212 my $v = abs_path( $_[ 0 ] );
252  
253 212 ▶ defined $v and length $v and -d "${v}" and return $v;
Branch: 1 branch
BranchTrueFalseTotal
defined $v and length $v and -d "$v" and return $v 1 211 212
Condition100%6/6
defined $v and length $v and -d "$v"
!ll&&!rl&&r
168431
defined $v and length $v
!ll&&!rl&&r
1472144
MC/DC100%3/3
defined $v and length $v and -d "$v"
defined $v length $v -d "$v"
Truth table100%4/4
A and B and C
A= defined $vB= length $vC= -d "$v"
ABCresult
0XX0
10X0
1100
1111
254  
255 211 return;
256 }
257  
258 2 ▶sub base64_decode_ns ($) {
Subroutine base64_decode_ns: called CC=13 SCAR=27.6
Pod documented
259 2 ▶ my $x = shift; defined $x or return; my @x = split q(), $x;
Branch: 1 branch
BranchTrueFalseTotal
defined $x or return 2 0 2
260  
261 2 my $index = $_index64->(); my $j = 0; my $k = 0;
262  
263 2 my $len = length $x; my $pad = 64; my @y = ();
264  
265 ROUND: {
266 2 ▶ while ($j < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $len) 10 1 11
267 10 my @c = (); my $i = 0;
268  
269 10 ▶ while ($i < 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 4) 40 8 48
270 40 my $uc = $index->[ ord $x[ $j++ ] ];
271  
272 40 ▶ $uc ne 'XX' and $c[ $i++ ] = 0 + $uc; $j == $len or next;
Branch: 2 branches
BranchTrueFalseTotal
$uc ne "XX" and $c[$i++] = 0 + $uc 40 0 40
$j == $len or next 2 38 40
273  
274 2 ▶ if ($i < 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 4) 0 2 2
275 0 ▶ $i < 2 and last ROUND; $i == 2 and $c[ 2 ] = $pad; $c[ 3 ] = $pad;
Branch: 2 branches
BranchTrueFalseTotal
$i < 2 and last ROUND 0 0 0
$i == 2 and $c[2] = $pad 0 0 0
276 }
277  
278 2 last;
279 }
280  
281 10 ▶ ($c[ 0 ] == $pad || $c[ 1 ] == $pad) and last;
Branch: 1 branch
BranchTrueFalseTotal
$c[0] == $pad || $c[1] == $pad and last 0 10 10
Condition33%1/3
$c[0] == $pad or $c[1] == $pad
l!l&&r!l&&!r
0010
MC/DC0%0/2
$c[0] == $pad or $c[1] == $pad
$c[0] == $pad $c[1] == $pad
Truth table33%1/3
A or B
A= $c[0] == $padB= $c[1] == $pad
ABresult
1X1
011
000
282 10 $y[ $k++ ] = ( $c[ 0 ] << 2) | (($c[ 1 ] & 0x30) >> 4);
283 10 ▶ $c[ 2 ] == $pad and last;
Branch: 1 branch
BranchTrueFalseTotal
$c[2] == $pad and last 0 10 10
284 10 $y[ $k++ ] = (($c[ 1 ] & 0x0F) << 4) | (($c[ 2 ] & 0x3C) >> 2);
285 10 ▶ $c[ 3 ] == $pad and last;
Branch: 1 branch
BranchTrueFalseTotal
$c[3] == $pad and last 1 9 10
286 9 $y[ $k++ ] = (($c[ 2 ] & 0x03) << 6) | $c[ 3 ];
287 }
288 }
289  
290 2 return join q(), map { chr $_ } @y;
291 }
292  
293 2 ▶sub base64_encode_ns (;$) {
Subroutine base64_encode_ns: called CC=6 SCAR=18.2
Pod documented
294 2 ▶ my $x = shift; defined $x or return; my @x = split q(), $x;
Branch: 1 branch
BranchTrueFalseTotal
defined $x or return 2 0 2
295  
296 2 my $basis = $_base64_char_set->(); my $len = length $x; my @y = ();
297  
298 2 ▶ for (my $i = 0, my $j = 0; $len > 0; $len -= 3, $i += 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 0) 10 2 12
299 10 ▶ my $c1 = ord $x[ $i ]; my $c2 = $len > 1 ? ord $x[ $i + 1 ] : 0;
Branch: 1 branch
BranchTrueFalseTotal
$len > 1 ? : 10 0 10
300  
301 10 $y[ $j++ ] = $basis->[ $c1 >> 2 ];
302 10 $y[ $j++ ] = $basis->[ (($c1 & 0x3) << 4) | (($c2 & 0xF0) >> 4) ];
303  
304 10 ▶ if ($len > 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($len > 2) { } 9 1 10
elsif ($len == 2) { } 1 0 1
305 9 my $c3 = ord $x[ $i + 2 ];
306  
307 9 $y[ $j++ ] = $basis->[ (($c2 & 0xF) << 2) | (($c3 & 0xC0) >> 6) ];
308 9 $y[ $j++ ] = $basis->[ $c3 & 0x3F ];
309 }
310 elsif ($len == 2) {
311 1 $y[ $j++ ] = $basis->[ ($c2 & 0xF) << 2 ];
312 1 $y[ $j++ ] = $basis->[ 64 ];
313 }
314 else { # len == 1
315 0 $y[ $j++ ] = $basis->[ 64 ];
316 0 $y[ $j++ ] = $basis->[ 64 ];
317 }
318 }
319  
320 2 return join q(), @y;
321 }
322  
323 1 ▶sub bsonid (;$) {
Subroutine bsonid: called CC=1 SCAR=0.0
Pod documented
324 1 return unpack 'H*', $_bsonid->( $_[ 0 ] );
325 }
326  
327 1 ▶sub bsonid_time ($) {
Subroutine bsonid_time: called CC=1 SCAR=0.0
Pod documented
328 1 return unpack 'N', substr hex2str( $_[ 0 ] ), 0, 4;
329 }
330  
331 1 ▶sub bson64id (;$) {
Subroutine bson64id: called CC=1 SCAR=0.0
Pod documented
332 1 return base64_encode_ns( $_bsonid->( 2 ) );
333 }
334  
335 1 ▶sub bson64id_time ($) {
Subroutine bson64id_time: called CC=1 SCAR=0.0
Pod documented
336 1 return unpack 'N', substr base64_decode_ns( $_[ 0 ] ), 2, 4;
337 }
338  
339 58 ▶sub canonicalise ($;$) {
Subroutine canonicalise: called CC=5 SCAR=17.3
Pod documented
340 58 my ($base, $relpath) = @_;
341  
342 0 ▶ $base = is_arrayref( $base ) ? catdir( @{ $base } ) : $base;
Branch: 1 branch
BranchTrueFalseTotal
&is_arrayref($base) ? : 0 58 58
343 58 ▶ $relpath or return canonpath( untaint_path( $base ) );
Branch: 1 branch
BranchTrueFalseTotal
$relpath or return canonpath(&untaint_path($base)) 33 25 58
344  
345 0 ▶ my @relpath = is_arrayref( $relpath ) ? @{ $relpath } : $relpath;
Branch: 1 branch
BranchTrueFalseTotal
&is_arrayref($relpath) ? : 0 33 33
346 33 my $path = canonpath( untaint_path( catdir( $base, @relpath ) ) );
347  
348 33 ▶ -d $path and return $path;
Branch: 1 branch
BranchTrueFalseTotal
-d $path and return $path 0 33 33
349  
350 33 return canonpath( untaint_path( catfile( $base, @relpath ) ) );
351 }
352  
353 49 ▶sub class2appdir ($) {
Subroutine class2appdir: called CC=1 SCAR=0.0
Pod documented
354 49 return lc distname( $_[ 0 ] );
355 }
356  
357 22 ▶sub classdir ($) {
Subroutine classdir: called CC=2 SCAR=7.6
Pod documented
358 22 ▶ return catdir( split m{ :: }mx, $_[ 0 ] // q() );
Condition50%1/2
$_[0] // ""
l!l
220
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
359 }
360  
361 56 ▶sub classfile ($) {
Subroutine classfile: called CC=1 SCAR=0.0
Pod documented
362 56 return catfile( split m{ :: }mx, $_[ 0 ].'.pm' );
363 }
364  
365 10 ▶sub create_token (;$) {
Subroutine create_token: called CC=2 SCAR=7.2
Pod documented
366 10 ▶ return digest( $_[ 0 ] // urandom() )->hexdigest;
Condition66%2/3
$_[0] // &urandom()
l!l&&r!l&&!r
910
MC/DC0%0/2
$_[0] // &urandom()
$_[0] &urandom()
Truth table66%2/3
A // B
A= $_[0]B= &urandom()
ABresult
1X1
011
000
367 }
368  
369 0 ▶sub create_token64 (;$) {
Subroutine create_token64: not called CC=2 SCAR=17.9
Pod documented
370 0 ▶ return digest( $_[ 0 ] // urandom() )->b64digest;
Condition0%0/3
$_[0] // &urandom()
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] // &urandom()
$_[0] &urandom()
Truth table0%0/3
A // B
A= $_[0]B= &urandom()
ABresult
1X1
011
000
371 }
372  
373 1 ▶sub cwdp () {
Subroutine cwdp: called CC=1 SCAR=0.0
Pod documented
374 1 return abs_path( curdir );
375 }
376  
377 4 ▶sub dash2under (;$) {
Subroutine dash2under: called CC=2 SCAR=7.2
Pod documented
378 4 ▶ (my $v = $_[ 0 ] // q()) =~ s{ [\-] }{_}gmx; return $v;
Condition50%1/2
$_[0] // ""
l!l
40
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
379 }
380  
381 2 ▶sub data_dumper (;@) {
Subroutine data_dumper: called CC=1 SCAR=0.0
Pod documented
382 2 _data_dumper( @_ ); return 1;
383 }
384  
385 10 ▶sub digest ($) {
Subroutine digest: called CC=5 SCAR=16.2
Pod documented
386 10 my $seed = shift; my ($candidate, $digest);
387  
388 10 ▶ if ($digest_cache) { $digest = Digest->new( $digest_cache ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($digest_cache) { } 7 3 10
389 else {
390 3 for (DIGEST_ALGORITHMS) {
391 3 ▶ $candidate = $_; $digest = eval { Digest->new( $candidate ) } and last;
Branch: 1 branch
BranchTrueFalseTotal
$digest = eval { do { "Digest"->new($candidate) } } and last 3 0 3
392 }
393  
394 3 ▶ $digest or throw( 'Digest algorithm not found' );
Branch: 1 branch
BranchTrueFalseTotal
$digest or &throw("Digest algorithm not found") 3 0 3
395 3 $digest_cache = $candidate;
396 }
397  
398 10 $digest->add( $seed );
399  
400 10 return $digest;
401 }
402  
403 50 ▶sub distname ($) {
Subroutine distname: called CC=2 SCAR=7.2
Pod documented
404 50 ▶ (my $v = $_[ 0 ] // q()) =~ s{ :: }{-}gmx; return $v;
Condition50%1/2
$_[0] // ""
l!l
500
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
405 }
406  
407 #head2 downgrade
408 # $sv_pv = downgrade $sv_pvgv;
409 #Horrendous Perl bug is promoting C<PV> and C<PVMG> type scalars to
410 #C<PVGV>. Serializing these values with L<Storable> throws a can't
411 #store SCALAR items error. This functions copies the string value of
412 #the input scalar to the output scalar but resets the output scalar
413 #type to C<PV>
414 #sub downgrade (;$) {
415 # my $x = shift // q(); my ($y) = $x =~ m{ (.*) }msx; return $y;
416 #}
417  
418 1 ▶sub elapsed () {
Subroutine elapsed: called CC=1 SCAR=0.0
Pod documented
419 1 return time - $BASETIME;
420 }
421  
422 10 ▶sub emit (;@) {
Subroutine emit: called CC=3 SCAR=11.0
Pod documented
423 10 ▶ my @args = @_; $args[ 0 ] //= q(); chomp( @args );
Condition100%2/2
$args[0] //= ""
l!l
82
MC/DC100%1/1
$args[0] //= ""
$args[0]
Truth table100%2/2
A
A= $args[0]
Aresult
11
00
424  
425 10 local ($OFS, $ORS) = ("\n", "\n");
426  
427 10 ▶ return openhandle *STDOUT ? emit_to( *STDOUT, @args ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
&openhandle(*STDOUT) ? : 10 0 10
428 }
429  
430 3 ▶sub emit_err (;@) {
Subroutine emit_err: called CC=3 SCAR=11.3
Pod documented
431 3 ▶ my @args = @_; $args[ 0 ] //= q(); chomp( @args );
Condition50%1/2
$args[0] //= ""
l!l
30
MC/DC0%0/1
$args[0] //= ""
$args[0]
Truth table50%1/2
A
A= $args[0]
Aresult
11
00
432  
433 3 local ($OFS, $ORS) = ("\n", "\n");
434  
435 3 ▶ return openhandle *STDERR ? emit_to( *STDERR, @args ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
&openhandle(*STDERR) ? : 3 0 3
436 }
437  
438 28 ▶sub emit_to ($;@) {
Subroutine emit_to: called CC=2 SCAR=7.4
Pod documented
439 28 my ($handle, @args) = @_; local $OS_ERROR;
440  
441 28 ▶ return (print {$handle} @args or throw( 'IO error: [_1]', [ $OS_ERROR ] ));
Condition33%1/3
print({$handle;} @args) || &throw('IO error: [_1]', [$Class::Usul::Functions::OS_ERROR])
l!l&&r!l&&!r
2800
MC/DC0%0/2
print({$handle;} @args) || &throw('IO error: [_1]', [$Class::Usul::Functions::OS_ERROR])
print({$handle;} @args) &throw('IO error: [_1]', [$Class::Usul::Functions::OS_ERROR])
Truth table33%1/3
A || B
A= print({$handle;} @args)B= &throw('IO error: [_1]', [$Class::Usul::Functions::OS_ERROR])
ABresult
1X1
011
000
442 }
443  
444 17 ▶sub ensure_class_loaded ($;$) {
Subroutine ensure_class_loaded: called CC=7 SCAR=20.2
Pod documented
445 17 ▶ my ($class, $opts) = @_; $opts //= {};
Condition50%1/2
$opts //= {}
l!l
017
MC/DC0%0/1
$opts //= {}
$opts
Truth table50%1/2
A
A= $opts
Aresult
11
00
446  
447 17 ▶ $class or throw( Unspecified, [ 'class name' ], level => 2 );
Branch: 1 branch
BranchTrueFalseTotal
$class or &throw(Unspecified(), ["class name"], "level", 2) 17 0 17
448  
449 17 ▶ is_module_name( $class )
Branch: 1 branch
BranchTrueFalseTotal
&is_module_name($class) or &throw("String [_1] invalid classname", [$class], "level", 2) 17 0 17
450 or throw( 'String [_1] invalid classname', [ $class ], level => 2 );
451  
452 17 ▶ not $opts->{ignore_loaded} and is_class_loaded( $class ) and return 1;
Branch: 1 branch
BranchTrueFalseTotal
not $opts->{"ignore_loaded"} and &is_class_loaded($class) and return 1 8 9 17
Condition66%2/3
not $opts->{"ignore_loaded"} and &is_class_loaded($class)
!ll&&!rl&&r
098
MC/DC50%1/2
not $opts->{"ignore_loaded"} and &is_class_loaded($class)
not $opts->{"ignore_loaded"} &is_class_loaded($class)
Truth table66%2/3
not(A) and B
A= not $opts->{"ignore_loaded"}B= &is_class_loaded($class)
ABresult
0X0
100
111
453  
454 9 eval { require_module( $class ) }; throw_on_error( { level => 3 } );
455  
456 8 ▶ is_class_loaded( $class )
Branch: 1 branch
BranchTrueFalseTotal
&is_class_loaded($class) or &throw("Class [_1] loaded but package undefined", [$class], "level", 2) 8 0 8
457 or throw( 'Class [_1] loaded but package undefined',
458 [ $class ], level => 2 );
459  
460 8 return 1;
461 }
462  
463 49 ▶sub env_prefix ($) {
Subroutine env_prefix: called CC=1 SCAR=0.0
Pod documented
464 49 return uc app_prefix( $_[ 0 ] );
465 }
466  
467 1 ▶sub escape_TT (;$$) {
Subroutine escape_TT: called CC=6 SCAR=20.9
Pod documented
468 1 ▶ my $v = defined $_[ 0 ] ? $_[ 0 ] : q();
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 1 0 1
469 1 ▶ my $fl = ($_[ 1 ] && $_[ 1 ]->[ 0 ]) || '<';
Condition40%2/5
$_[1] && $_[1][0] || '<'
l!l
01
$_[1] and $_[1][0]
!ll&&!rl&&r
100
MC/DC0%0/2
$_[1] && $_[1][0] || '<'
$_[1] $_[1][0]
Truth table33%1/3
A and B
A= $_[1]B= $_[1][0]
ABresult
111
0X0
100
470 1 ▶ my $fr = ($_[ 1 ] && $_[ 1 ]->[ 1 ]) || '>';
Condition40%2/5
$_[1] && $_[1][1] || '>'
l!l
01
$_[1] and $_[1][1]
!ll&&!rl&&r
100
MC/DC0%0/2
$_[1] && $_[1][1] || '>'
$_[1] $_[1][1]
Truth table33%1/3
A and B
A= $_[1]B= $_[1][1]
ABresult
111
0X0
100
471  
472 1 $v =~ s{ \[\% }{${fl}%}gmx; $v =~ s{ \%\] }{%${fr}}gmx;
473  
474 1 return $v;
475 }
476  
477 8 ▶sub exception (;@) {
Subroutine exception: called CC=1 SCAR=0.0
Pod documented
478 8 return EXCEPTION_CLASS->caught( @_ );
479 }
480  
481 21 ▶sub find_apphome ($;$$) {
Subroutine find_apphome: called CC=14 SCAR=28.8
Pod documented
482 21 my ($appclass, $default, $extns) = @_; my $path;
483  
484 # 0. Pass the directory in (short circuit the search)
485 21 ▶ $path = assert_directory $default and return $path;
Branch: 1 branch
BranchTrueFalseTotal
$path = &assert_directory($default) and return $path 0 21 21
486  
487 21 my $app_pref = app_prefix $appclass;
488 21 my $appdir = class2appdir $appclass;
489 21 my $classdir = classdir $appclass;
490 21 my $env_pref = env_prefix $appclass;
491 21 my $my_home = File::HomeDir->my_home;
492  
493 # 1a. Environment variable - for application directory
494 21 ▶ $path = assert_directory $ENV{ "${env_pref}_HOME" } and return $path;
Branch: 1 branch
BranchTrueFalseTotal
$path = &assert_directory($ENV{"${env_pref}_HOME"}) and return $path 0 21 21
495 # 1b. Environment variable - for config file
496 21 ▶ $path = $_get_env_var_for_conf->( "${env_pref}_CONFIG" ) and return $path;
Branch: 1 branch
BranchTrueFalseTotal
$path = &$_get_env_var_for_conf("${env_pref}_CONFIG") and return $path 0 21 21
497 # 2a. Users XDG_DATA_HOME env variable or XDG default share directory
498 21 ▶ $path = $ENV{ 'XDG_DATA_HOME' } // catdir( $my_home, '.local', 'share' );
Condition33%1/3
$ENV{"XDG_DATA_HOME"} // catdir($my_home, ".local", "share")
l!l&&r!l&&!r
0210
MC/DC0%0/2
$ENV{"XDG_DATA_HOME"} // catdir($my_home, ".local", "share")
$ENV{"XDG_DATA_HOME"} catdir($my_home, ".local", "share")
Truth table33%1/3
A // B
A= $ENV{"XDG_DATA_HOME"}B= catdir($my_home, ".local", "share")
ABresult
1X1
011
000
499 21 ▶ $path = assert_directory catdir( $path, $appdir ) and return $path;
Branch: 1 branch
BranchTrueFalseTotal
$path = &assert_directory(scalar catdir($path, $appdir)) and return $path 0 21 21
500 # 2b. Users home directory - dot file containing shell env variable
501 21 ▶ $path = $_get_file_var->( $my_home, $app_pref, $classdir ) and return $path;
Branch: 1 branch
BranchTrueFalseTotal
$path = &$_get_file_var($my_home, $app_pref, $classdir) and return $path 0 21 21
502 21 ▶ $path = $_get_file_var->( $my_home, $appdir, $classdir ) and return $path;
Branch: 1 branch
BranchTrueFalseTotal
$path = &$_get_file_var($my_home, $appdir, $classdir) and return $path 0 21 21
503 # 2c. Users home directory - dot directory is apphome
504 21 $path = catdir( $my_home, ".${app_pref}" );
505 21 ▶ $path = assert_directory $path and return $path;
Branch: 1 branch
BranchTrueFalseTotal
$path = &assert_directory($path) and return $path 0 21 21
506 21 $path = catdir( $my_home, ".${appdir}" );
507 21 ▶ $path = assert_directory $path and return $path;
Branch: 1 branch
BranchTrueFalseTotal
$path = &assert_directory($path) and return $path 0 21 21
508 # 3. Well known path containing shell env file
509 21 ▶ $path = $_get_known_file_var->( $appdir, $classdir ) and return $path;
Branch: 1 branch
BranchTrueFalseTotal
$path = &$_get_known_file_var($appdir, $classdir) and return $path 0 21 21
510 # 4. Default install prefix
511 21 $path = catdir( @{ PREFIX() }, $appdir, 'default', 'lib', $classdir );
512 21 ▶ $path = assert_directory $path and return $path;
Branch: 1 branch
BranchTrueFalseTotal
$path = &assert_directory($path) and return $path 0 21 21
513 # 5a. Config file found in @INC - underscore as separator
514 21 ▶ $path = $_find_cfg_in_inc->( $classdir, $app_pref, $extns ) and return $path;
Branch: 1 branch
BranchTrueFalseTotal
$path = &$_find_cfg_in_inc($classdir, $app_pref, $extns) and return $path 0 21 21
515 # 5b. Config file found in @INC - dash as separator
516 21 ▶ $path = $_find_cfg_in_inc->( $classdir, $appdir, $extns ) and return $path;
Branch: 1 branch
BranchTrueFalseTotal
$path = &$_find_cfg_in_inc($classdir, $appdir, $extns) and return $path 0 21 21
517 # 6. Default to /tmp
518 21 return untaint_path( DEFAULT_CONFHOME );
519 }
520  
521 55 ▶sub find_source ($) {
Subroutine find_source: called CC=4 SCAR=14.1
Pod documented
522 55 my $class = shift; my $file = classfile( $class ); my $path;
523  
524 55 for (@INC) {
525 165 ▶ $path = abs_path( catfile( $_, $file ) ) and -f $path and return $path;
Branch: 1 branch
BranchTrueFalseTotal
$path = &abs_path(scalar catfile($_, $file)) and -f $path and return $path 55 110 165
Condition66%2/3
$path = &abs_path(scalar catfile($_, $file)) and -f $path
!ll&&!rl&&r
110055
MC/DC50%1/2
$path = &abs_path(scalar catfile($_, $file)) and -f $path
$path = &abs_path(scalar catfile($_, $file)) -f $path
Truth table66%2/3
A and B
A= $path = &abs_path(scalar catfile($_, $file))B= -f $path
ABresult
0X0
100
111
526 }
527  
528 0 return;
529 }
530  
531 1 ▶sub first_char ($) {
Subroutine first_char: called CC=1 SCAR=0.0
Pod documented
532 1 return substr $_[ 0 ], 0, 1;
533 }
534  
535 0 ▶sub fqdn (;$) {
Subroutine fqdn: not called CC=2 SCAR=17.9
Pod documented
536 0 ▶ my $x = shift // hostname; return (gethostbyname( $x ))[ 0 ];
Condition0%0/3
shift() // hostname()
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // hostname()
shift() hostname()
Truth table0%0/3
A // B
A= shift()B= hostname()
ABresult
1X1
011
000
537 }
538  
539 0 ▶sub fullname () {
Subroutine fullname: not called CC=3 SCAR=24.8
Pod documented
540 0 ▶ my $v = (split m{ \s* , \s * }msx, (get_user()->gecos // q()))[ 0 ];
Condition0%0/2
&get_user()->gecos // ""
l!l
00
MC/DC0%0/1
&get_user()->gecos // ""
&get_user()->gecos
Truth table0%0/2
A
A= &get_user()->gecos
Aresult
11
00
541  
542 0 ▶ $v //= q(); $v =~ s{ [\&] }{}gmx; # Coz af25e158-d0c7-11e3-bdcb-31d9eda79835
Condition0%0/2
$v //= ""
l!l
00
MC/DC0%0/1
$v //= ""
$v
Truth table0%0/2
A
A= $v
Aresult
11
00
543  
544 0 return untaint_cmdline( $v );
545 }
546  
547 21 ▶sub get_cfgfiles ($;$$) {
Subroutine get_cfgfiles: called CC=10 SCAR=24.3
Pod documented
548 21 my ($appclass, $dirs, $extns) = @_;
549  
550 21 ▶ $appclass // throw( Unspecified, [ 'application class' ], level => 2 );
Condition33%1/3
$appclass // &throw(Unspecified(), ["application class"], "level", 2)
l!l&&r!l&&!r
2100
MC/DC0%0/2
$appclass // &throw(Unspecified(), ["application class"], "level", 2)
$appclass &throw(Unspecified(), ["application class"], "level", 2)
Truth table33%1/3
A // B
A= $appclassB= &throw(Unspecified(), ["application class"], "level", 2)
ABresult
1X1
011
000
551 21 ▶ is_arrayref( $dirs ) or $dirs = [ $dirs || curdir ];
Branch: 1 branch
BranchTrueFalseTotal
&is_arrayref($dirs) or $dirs = [$dirs || "."] 0 21 21
Condition50%1/2
$dirs || '.'
l!l
210
MC/DC0%0/1
$dirs || '.'
$dirs
Truth table50%1/2
A
A= $dirs
Aresult
11
00
552  
553 21 my $app_pref = app_prefix $appclass;
554 21 my $appdir = class2appdir $appclass;
555 21 my $env_pref = env_prefix $appclass;
556 21 ▶ my $suffix = $ENV{ "${env_pref}_CONFIG_LOCAL_SUFFIX" } // '_local';
Condition50%1/2
$ENV{"${env_pref}_CONFIG_LOCAL_SUFFIX"} // "_local"
l!l
021
MC/DC0%0/1
$ENV{"${env_pref}_CONFIG_LOCAL_SUFFIX"} // "_local"
$ENV{"${env_pref}_CONFIG_LOCAL_SUFFIX"}
Truth table50%1/2
A
A= $ENV{"${env_pref}_CONFIG_LOCAL_SUFFIX"}
Aresult
11
00
557 21 my @paths = ();
558  
559 21 for my $dir (@{ $dirs }) {
560 21 ▶ for my $extn (@{ $extns // [ supported_extensions() ] }) {
Condition50%1/2
$extns // [&supported_extensions()]
l!l
021
MC/DC0%0/1
$extns // [&supported_extensions()]
$extns
Truth table50%1/2
A
A= $extns
Aresult
11
00
561 25 for my $path (map { $_catpath->( $dir, $_ ) } "${app_pref}${extn}",
562 "${appdir}${extn}", "${app_pref}${suffix}${extn}",
563 "${appdir}${suffix}${extn}") {
564 100 ▶ -f $path and push @paths, $path;
Branch: 1 branch
BranchTrueFalseTotal
-f $path and push @paths, $path 0 100 100
565 }
566 }
567 }
568  
569 21 return \@paths;
570 }
571  
572 6 ▶sub get_user (;$) {
Subroutine get_user: called CC=5 SCAR=18.1
Pod documented
573 6 ▶ my $user = shift; is_win32() and return Class::Null->new;
Branch: 1 branch
BranchTrueFalseTotal
&is_win32() and return "Class::Null"->new 0 6 6
574  
575 6 ▶ defined $user and $user !~ m{ \A \d+ \z }mx and return getpwnam( $user );
Branch: 1 branch
BranchTrueFalseTotal
defined $user and not $user =~ / \A \d+ \z /mx and return &Class::Usul::Functions::getpwnam($user) 0 6 6
Condition33%1/3
defined $user and not $user =~ / \A \d+ \z /mx
!ll&&!rl&&r
600
MC/DC0%0/2
defined $user and not $user =~ / \A \d+ \z /mx
defined $user not $user =~ / \A \d+ \z /mx
Truth table33%1/3
A and not(B)
A= defined $userB= not $user =~ / \A \d+ \z /mx
ABresult
0X0
100
111
576  
577 6 ▶ return getpwuid( $user // $UID );
Condition66%2/3
$user // $Class::Usul::Functions::UID
l!l&&r!l&&!r
042
MC/DC50%1/2
$user // $Class::Usul::Functions::UID
$user $Class::Usul::Functions::UID
Truth table66%2/3
A // B
A= $userB= $Class::Usul::Functions::UID
ABresult
1X1
011
000
578 }
579  
580 2 ▶sub hex2str (;$) {
Subroutine hex2str: called CC=3 SCAR=11.0
Pod documented
581 2 ▶ my @a = split m{}mx, shift // q(); my $str = q();
Condition50%1/2
shift() // ""
l!l
20
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
582  
583 2 ▶ while (my ($x, $y) = splice @a, 0, 2) { $str .= pack 'C', hex "${x}${y}" }
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@a, 0, 2)) 13 2 15
584  
585 2 return $str;
586 }
587  
588 7 ▶sub home2appldir ($) {
Subroutine home2appldir: called CC=5 SCAR=16.1
Pod documented
589 7 ▶ $_[ 0 ] or return; my $dir = io( $_[ 0 ] );
Branch: 1 branch
BranchTrueFalseTotal
$_[0] or return 6 1 7
590  
591 6 ▶ $dir = $dir->parent while ($dir ne $dir->parent and $dir !~ m{ lib \z }mx);
Branch: 1 branch
BranchTrueFalseTotal
$dir ne $dir->parent and not $dir =~ / lib \z /mx and do { $dir = $dir->parent } 6 6 12
Condition100%3/3
$dir ne $dir->parent and not $dir =~ / lib \z /mx
!ll&&!rl&&r
516
MC/DC100%2/2
$dir ne $dir->parent and not $dir =~ / lib \z /mx
$dir ne $dir->parent not $dir =~ / lib \z /mx
Truth table100%3/3
A and not(B)
A= $dir ne $dir->parentB= not $dir =~ / lib \z /mx
ABresult
0X0
100
111
592  
593 6 ▶ return $dir ne $dir->parent ? $dir->parent : undef;
Branch: 1 branch
BranchTrueFalseTotal
$dir ne $dir->parent ? : 1 5 6
594 }
595  
596 200 ▶sub io (;@) {
Subroutine io: called CC=1 SCAR=0.0
Pod documented
597 200 return File::DataClass::IO->new( @_ );
598 }
599  
600 2501 ▶sub is_arrayref (;$) {
Subroutine is_arrayref: called CC=3 SCAR=11.0
Pod documented
601 2501 ▶ return $_[ 0 ] && ref $_[ 0 ] eq 'ARRAY' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] && ref $_[0] eq 'ARRAY' ? : 1245 1256 2501
Condition100%3/3
$_[0] and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
3379191245
MC/DC100%2/2
$_[0] and ref $_[0] eq "ARRAY"
$_[0] ref $_[0] eq "ARRAY"
Truth table100%3/3
A and B
A= $_[0]B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
602 }
603  
604 56 ▶sub is_coderef (;$) {
Subroutine is_coderef: called CC=3 SCAR=11.0
Pod documented
605 56 ▶ return $_[ 0 ] && ref $_[ 0 ] eq 'CODE' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] && ref $_[0] eq 'CODE' ? : 14 42 56
Condition100%3/3
$_[0] and ref $_[0] eq "CODE"
!ll&&!rl&&r
123014
MC/DC100%2/2
$_[0] and ref $_[0] eq "CODE"
$_[0] ref $_[0] eq "CODE"
Truth table100%3/3
A and B
A= $_[0]B= ref $_[0] eq "CODE"
ABresult
0X0
100
111
606 }
607  
608 418 ▶sub is_hashref (;$) {
Subroutine is_hashref: called CC=3 SCAR=11.0
Pod documented
609 418 ▶ return $_[ 0 ] && ref $_[ 0 ] eq 'HASH' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] && ref $_[0] eq 'HASH' ? : 373 45 418
Condition100%3/3
$_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
2916373
MC/DC100%2/2
$_[0] and ref $_[0] eq "HASH"
$_[0] ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= $_[0]B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
610 }
611  
612 491 ▶sub is_member (;@) {
Subroutine is_member: called CC=4 SCAR=13.9
Pod documented
613 491 ▶ my ($candidate, @args) = @_; $candidate or return;
Branch: 1 branch
BranchTrueFalseTotal
$candidate or return 491 0 491
614  
615 491 ▶ is_arrayref $args[ 0 ] and @args = @{ $args[ 0 ] };
Branch: 1 branch
BranchTrueFalseTotal
&is_arrayref($args[0]) and @args = @{$args[0];} 414 77 491
616  
617 491 ▶ return (first { $_ eq $candidate } @args) ? 1 : 0;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { $_ eq $candidate; } , @args) ? : 19 472 491
618 }
619  
620 842 ▶sub is_ntfs () {
Subroutine is_ntfs: called CC=3 SCAR=14.2
Pod documented
621 842 ▶ return is_win32() || lc $OSNAME eq 'cygwin' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
&is_win32() || lc $Class::Usul::Functions::OSNAME eq 'cygwin' ? : 0 842 842
Condition33%1/3
&is_win32() or lc $Class::Usul::Functions::OSNAME eq "cygwin"
l!l&&r!l&&!r
00842
MC/DC0%0/2
&is_win32() or lc $Class::Usul::Functions::OSNAME eq "cygwin"
&is_win32() lc $Class::Usul::Functions::OSNAME eq "cygwin"
Truth table33%1/3
A or B
A= &is_win32()B= lc $Class::Usul::Functions::OSNAME eq "cygwin"
ABresult
1X1
011
000
622 }
623  
624 2241 ▶sub is_win32 () {
Subroutine is_win32: called CC=2 SCAR=7.6
Pod documented
625 2241 ▶ return lc $OSNAME eq 'mswin32' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
lc $Class::Usul::Functions::OSNAME eq 'mswin32' ? : 0 2241 2241
626 }
627  
628 1 ▶sub list_attr_of ($;@) {
Subroutine list_attr_of: called CC=3 SCAR=11.0
Pod documented
629 1 my ($obj, @except) = @_; my $class = blessed $obj;
630  
631 1 ensure_class_loaded( 'Pod::Eventual::Simple' );
632  
633 1 ▶ is_member 'new', @except or push @except, 'new';
Branch: 1 branch
BranchTrueFalseTotal
&is_member("new", @except) or push @except, "new" 0 1 1
634  
635 45 return map { my $attr = $_->[0]; [ @{ $_ }, $obj->$attr ] }
636 45 map { [ $_->[1], $_->[0], $_get_pod_content_for_attr->( @{ $_ } ) ] }
637 50 ▶ grep { $_->[0] ne 'Moo::Object' and not is_member $_->[1], @except }
Condition100%3/3
$_->[0] ne 'Moo::Object' && !&is_member($_->[1], @except)
!ll&&!rl&&r
4145
MC/DC100%2/2
$_->[0] ne 'Moo::Object' && !&is_member($_->[1], @except)
$_->[0] ne 'Moo::Object' !&is_member($_->[1], @except)
Truth table100%3/3
A && not(B)
A= $_->[0] ne 'Moo::Object'B= !&is_member($_->[1], @except)
ABresult
0X0
100
111
638 50 map { m{ \A (.+) \:\: ([^:]+) \z }mx; [ $1, $2 ] }
639 1 @{ Class::Inspector->methods( $class, 'full', 'public' ) };
640 }
641  
642 6 ▶sub loginid (;$) {
Subroutine loginid: called CC=2 SCAR=7.6
Pod documented
643 6 ▶ return untaint_cmdline( get_user( $_[ 0 ] )->name || 'unknown' );
Condition50%1/2
&get_user($_[0])->name || 'unknown'
l!l
60
MC/DC0%0/1
&get_user($_[0])->name || 'unknown'
&get_user($_[0])->name
Truth table50%1/2
A
A= &get_user($_[0])->name
Aresult
11
00
644 }
645  
646 5 ▶sub logname (;$) { # Deprecated use loginid
Subroutine logname: called CC=3 SCAR=15.4
Pod documented
647 5 ▶ return untaint_cmdline( $ENV{USER} || $ENV{LOGNAME} || loginid( $_[ 0 ] ) );
Condition33%2/6
$ENV{'USER'} || $ENV{'LOGNAME'} || &loginid($_[0])
l!l&&r!l&&!r
050
$ENV{"USER"} or $ENV{"LOGNAME"}
l!l&&r!l&&!r
005
MC/DC0%0/3
$ENV{'USER'} || $ENV{'LOGNAME'} || &loginid($_[0])
$ENV{"USER"} $ENV{"LOGNAME"} &loginid($_[0])
Truth table25%1/4
A or B || C
A= $ENV{"USER"}B= $ENV{"LOGNAME"}C= &loginid($_[0])
ABCresult
1XX1
01X1
0011
0000
648 }
649  
650 47 ▶sub merge_attributes ($@) {
Subroutine merge_attributes: called CC=9 SCAR=22.0
Pod documented
651 47 my ($dest, @args) = @_;
652  
653 47 ▶ my $attr = is_arrayref( $args[ -1 ] ) ? pop @args : [];
Branch: 1 branch
BranchTrueFalseTotal
&is_arrayref($args[-1]) ? : 47 0 47
654  
655 47 ▶ for my $k (grep { not exists $dest->{ $_ } or not defined $dest->{ $_ } }
Condition66%2/3
exists $dest->{$_} && defined $dest->{$_}
!ll&&!rl&&r
17104
MC/DC50%1/2
exists $dest->{$_} && defined $dest->{$_}
exists $dest->{$_} defined $dest->{$_}
Truth table66%2/3
A && B
A= exists $dest->{$_}B= defined $dest->{$_}
ABresult
0X0
100
111
656 47 @{ $attr }) {
657 171 my $i = 0; my $v;
658  
659 171 ▶ while (not defined $v and defined( my $src = $args[ $i++ ] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $v and defined(my $src = $args[$i++])) 201 171 372
Condition100%3/3
not defined $v and defined(my $src = $args[$i++])
!ll&&!rl&&r
11655201
MC/DC100%2/2
not defined $v and defined(my $src = $args[$i++])
not defined $v defined(my $src = $args[$i++])
Truth table100%3/3
not(A) and B
A= not defined $vB= defined(my $src = $args[$i++])
ABresult
0X0
100
111
660 201 my $class = blessed $src;
661  
662 201 ▶ $v = $class ? ($src->can( $k ) ? $src->$k() : undef) : $src->{ $k };
Branch: 2 branches
BranchTrueFalseTotal
$class ? : 151 50 201
$src->can($k) ? : 109 42 151
663 }
664  
665 171 ▶ defined $v and $dest->{ $k } = $v;
Branch: 1 branch
BranchTrueFalseTotal
defined $v and $dest->{$k} = $v 116 55 171
666 }
667  
668 47 return $dest;
669 }
670  
671 2 ▶sub my_prefix (;$) {
Subroutine my_prefix: called CC=2 SCAR=7.6
Pod documented
672 2 ▶ return split_on__( basename( $_[ 0 ] // q(), PERL_EXTNS ) );
Condition50%1/2
$_[0] // ""
l!l
20
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
673 }
674  
675 384 ▶sub nonblocking_write_pipe_pair () {
Subroutine nonblocking_write_pipe_pair: called CC=2 SCAR=7.0
Pod documented
676 384 ▶ my ($r, $w); pipe $r, $w or throw( 'No pipe' );
Branch: 1 branch
BranchTrueFalseTotal
pipe $r, $w or &throw("No pipe") 384 0 384
677  
678 384 fcntl $w, F_SETFL, O_NONBLOCK; $w->autoflush( 1 );
679  
680 384 binmode $r; binmode $w;
681  
682 384 return [ $r, $w ];
683 }
684  
685 6 ▶sub ns_environment ($$;$) {
Subroutine ns_environment: called CC=2 SCAR=7.1
Pod documented
686 6 my ($class, $k, $v) = @_; $k = (env_prefix $class).'_'.(uc $k);
687  
688 6 ▶ return defined $v ? $ENV{ $k } = $v : $ENV{ $k };
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 0 6 6
689 }
690  
691 7 ▶sub pad ($$;$$) {
Subroutine pad: called CC=7 SCAR=19.5
Pod documented
692 7 my ($v, $wanted, $str, $direction) = @_; my $len = $wanted - length $v;
693  
694 7 ▶ $len > 0 or return $v; (defined $str and length $str) or $str = q( );
Branch: 2 branches
BranchTrueFalseTotal
$len > 0 or return $v 6 1 7
defined $str and length $str or $str = " " 3 3 6
Condition66%2/3
defined $str and length $str
!ll&&!rl&&r
303
MC/DC50%1/2
defined $str and length $str
defined $str length $str
Truth table66%2/3
A and B
A= defined $strB= length $str
ABresult
0X0
100
111
695  
696 6 my $pad = substr( $str x $len, 0, $len );
697  
698 6 ▶ (not $direction or $direction eq 'right') and return $v.$pad;
Branch: 1 branch
BranchTrueFalseTotal
!$direction || $direction eq "right" and return $v . $pad 4 2 6
Condition100%3/3
not $direction or $direction eq "right"
l!l&&r!l&&!r
312
MC/DC100%2/2
not $direction or $direction eq "right"
not $direction $direction eq "right"
Truth table100%3/3
not(A) or B
A= not $directionB= $direction eq "right"
ABresult
1X1
011
000
699 2 ▶ $direction eq 'left' and return $pad.$v;
Branch: 1 branch
BranchTrueFalseTotal
$direction eq "left" and return $pad . $v 1 1 2
700  
701 1 return (substr $pad, 0, int( (length $pad) / 2 )).$v
702 .(substr $pad, 0, int( 0.99999999 + (length $pad) / 2 ));
703 }
704  
705 1 ▶sub prefix2class (;$) {
Subroutine prefix2class: called CC=1 SCAR=0.0
Pod documented
706 1 return join '::', map { ucfirst } split m{ - }mx, my_prefix( $_[ 0 ] );
707 }
708  
709 1 ▶sub socket_pair () {
Subroutine socket_pair: called CC=2 SCAR=7.0
Pod documented
710 1 my $rdr = gensym; my $wtr = gensym;
711  
712 1 ▶ socketpair( $rdr, $wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC )
Branch: 1 branch
BranchTrueFalseTotal
socketpair $rdr, $wtr, 1, 1, 0 or &throw($Class::Usul::Functions::EXTENDED_OS_ERROR) 1 0 1
713 or throw( $EXTENDED_OS_ERROR );
714 1 shutdown ( $rdr, 1 ); # No more writing for reader
715 1 shutdown ( $wtr, 0 ); # No more reading for writer
716  
717 1 return [ $rdr, $wtr ];
718 }
719  
720 11 ▶sub split_on__ (;$$) {
Subroutine split_on__: called CC=3 SCAR=11.2
Pod documented
721 11 ▶ return (split m{ _ }mx, $_[ 0 ] // q())[ $_[ 1 ] // 0 ];
Condition75%3/4
$_[1] // 0
l!l
92
$_[0] // ""
l!l
110
MC/DC100%1/1
$_[1] // 0
$_[1]
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
722 }
723  
724 9 ▶sub split_on_dash (;$$) {
Subroutine split_on_dash: called CC=3 SCAR=12.7
Pod documented
725 9 ▶ return (split m{ \- }mx, $_[ 0 ] // q())[ $_[ 1 ] // 0 ];
Condition50%2/4
$_[1] // 0
l!l
90
$_[0] // ""
l!l
90
MC/DC0%0/1
$_[1] // 0
$_[1]
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
726 }
727  
728 46 ▶sub squeeze (;$) {
Subroutine squeeze: called CC=2 SCAR=7.2
Pod documented
729 46 ▶ (my $v = $_[ 0 ] // q()) =~ s{ \s+ }{ }gmx; return $v;
Condition50%1/2
$_[0] // ""
l!l
460
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
730 }
731  
732 612 ▶sub strip_leader (;$) {
Subroutine strip_leader: called CC=2 SCAR=7.2
Pod documented
733 612 ▶ (my $v = $_[ 0 ] // q()) =~ s{ \A [^:]+ [:] \s+ }{}msx; return $v;
Condition50%1/2
$_[0] // ""
l!l
6120
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
734 }
735  
736 1 ▶sub sub_name (;$) {
Subroutine sub_name: called CC=3 SCAR=12.0
Pod documented
737 1 ▶ my $frame = 1 + ($_[ 0 ] // 0);
Condition50%1/2
$_[0] // 0
l!l
01
MC/DC0%0/1
$_[0] // 0
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
738  
739 1 ▶ return (split m{ :: }mx, ((caller $frame)[ 3 ]) // 'main')[ -1 ];
Condition50%1/2
(caller $frame)[3] // "main"
l!l
01
MC/DC0%0/1
(caller $frame)[3] // "main"
(caller $frame)[3]
Truth table50%1/2
A
A= (caller $frame)[3]
Aresult
11
00
740 }
741  
742 3 ▶sub symlink (;$$$) {
Subroutine symlink: called CC=9 SCAR=23.9
Pod documented
743 3 my ($from, $to, $base) = @_;
744  
745 3 ▶ defined $base and not CORE::length $base and $base = File::Spec->rootdir;
Branch: 1 branch
BranchTrueFalseTotal
defined $base and not length $base and $base = "File::Spec"->rootdir 0 3 3
Condition66%2/3
defined $base and not length $base
!ll&&!rl&&r
120
MC/DC0%0/2
defined $base and not length $base
defined $base not length $base
Truth table66%2/3
A and not(B)
A= defined $baseB= not length $base
ABresult
0X0
100
111
746 3 ▶ $from or throw( Unspecified, [ 'path from' ] );
Branch: 1 branch
BranchTrueFalseTotal
$from or &throw(Unspecified(), ["path from"]) 3 0 3
747 3 $from = io( $from )->absolute( $base );
748 3 ▶ $from->exists or throw( PathNotFound, [ "${from}" ] );
Branch: 1 branch
BranchTrueFalseTotal
$from->exists or &throw(PathNotFound(), ["$from"]) 3 0 3
749 3 ▶ $to or throw( Unspecified, [ 'path to' ] );
Branch: 1 branch
BranchTrueFalseTotal
$to or &throw(Unspecified(), ["path to"]) 3 0 3
750 3 ▶ $to = io( $to )->absolute( $base ); $to->is_link and $to->unlink;
Branch: 1 branch
BranchTrueFalseTotal
$to->is_link and $to->unlink 0 3 3
751 3 ▶ $to->exists and throw( PathAlreadyExists, [ "${to}" ] );
Branch: 1 branch
BranchTrueFalseTotal
$to->exists and &throw(PathAlreadyExists(), ["$to"]) 0 3 3
752 3 ▶ CORE::symlink "${from}", "${to}"
Branch: 1 branch
BranchTrueFalseTotal
CORE::symlink "$from", "$to" or &throw("Symlink from [_1] to [_2] failed: [_3]", ["$from", "$to", $Class::Usul::Functions::OS_ERROR]) 3 0 3
753 or throw( 'Symlink from [_1] to [_2] failed: [_3]',
754 [ "${from}", "${to}", $OS_ERROR ] );
755 3 return "Symlinked ${from} to ${to}";
756 }
757  
758 1 ▶sub thread_id () {
Subroutine thread_id: called CC=2 SCAR=7.6
Pod documented
759 1 ▶ return exists $INC{ 'threads.pm' } ? threads->tid() : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $INC{'threads.pm'} ? : 0 1 1
760 }
761  
762 170 ▶sub throw (;@) {
Subroutine throw: called CC=1 SCAR=0.0
Pod documented
763 170 EXCEPTION_CLASS->throw( @_ );
764 }
765  
766 9 ▶sub throw_on_error (;@) {
Subroutine throw_on_error: called CC=1 SCAR=0.0
Pod documented
767 9 EXCEPTION_CLASS->throw_on_error( @_ );
768 }
769  
770 2 ▶sub trim (;$$) {
Subroutine trim: called CC=3 SCAR=11.0
Pod documented
771 2 ▶ my $chs = $_[ 1 ] // " \t"; (my $v = $_[ 0 ] // q()) =~ s{ \A [$chs]+ }{}mx;
Condition75%3/4
$_[1] // " \t"
l!l
11
$_[0] // ""
l!l
20
MC/DC100%1/1
$_[1] // " \t"
$_[1]
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
772  
773 2 chomp $v; $v =~ s{ [$chs]+ \z }{}mx; return $v;
774 }
775  
776 1 ▶sub unescape_TT (;$$) {
Subroutine unescape_TT: called CC=6 SCAR=20.9
Pod documented
777 1 ▶ my $v = defined $_[ 0 ] ? $_[ 0 ] : q();
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 1 0 1
778 1 ▶ my $fl = ($_[ 1 ] && $_[ 1 ]->[ 0 ]) || '<';
Condition40%2/5
$_[1] && $_[1][0] || '<'
l!l
01
$_[1] and $_[1][0]
!ll&&!rl&&r
100
MC/DC0%0/2
$_[1] && $_[1][0] || '<'
$_[1] $_[1][0]
Truth table33%1/3
A and B
A= $_[1]B= $_[1][0]
ABresult
111
0X0
100
779 1 ▶ my $fr = ($_[ 1 ] && $_[ 1 ]->[ 1 ]) || '>';
Condition40%2/5
$_[1] && $_[1][1] || '>'
l!l
01
$_[1] and $_[1][1]
!ll&&!rl&&r
100
MC/DC0%0/2
$_[1] && $_[1][1] || '>'
$_[1] $_[1][1]
Truth table33%1/3
A and B
A= $_[1]B= $_[1][1]
ABresult
111
0X0
100
780  
781 1 $v =~ s{ ${fl}\% }{[%}gmx; $v =~ s{ \%${fr} }{%]}gmx;
782  
783 1 return $v;
784 }
785  
786 58 ▶sub untaint_cmdline (;$) {
Subroutine untaint_cmdline: called CC=1 SCAR=0.0
Pod documented
787 58 return untaint_string( UNTAINT_CMDLINE, $_[ 0 ] );
788 }
789  
790 16 ▶sub untaint_identifier (;$) {
Subroutine untaint_identifier: called CC=1 SCAR=0.0
Pod documented
791 16 return untaint_string( UNTAINT_IDENTIFIER, $_[ 0 ] );
792 }
793  
794 1276 ▶sub untaint_path (;$) {
Subroutine untaint_path: called CC=1 SCAR=0.0
Pod documented
795 1276 return untaint_string( UNTAINT_PATH, $_[ 0 ] );
796 }
797  
798 1350 ▶sub untaint_string ($;$) {
Subroutine untaint_string: called CC=5 SCAR=16.2
Pod documented
799 1350 my ($regex, $string) = @_;
800  
801 1350 ▶ defined $string or return; length $string or return q();
Branch: 2 branches
BranchTrueFalseTotal
defined $string or return 1337 13 1350
length $string or return "" 1337 0 1337
802  
803 1337 my ($untainted) = $string =~ $regex;
804  
805 1337 ▶ (defined $untainted and $untainted eq $string)
Branch: 1 branch
BranchTrueFalseTotal
defined $untainted and $untainted eq $string or &throw(Tainted(), [$string], "level", 3) 1333 4 1337
Condition66%2/3
defined $untainted and $untainted eq $string
!ll&&!rl&&r
401333
MC/DC50%1/2
defined $untainted and $untainted eq $string
defined $untainted $untainted eq $string
Truth table66%2/3
A and B
A= defined $untaintedB= $untainted eq $string
ABresult
0X0
100
111
806 or throw( Tainted, [ $string ], level => 3 );
807  
808 1333 return $untainted;
809 }
810  
811 2 ▶sub urandom (;$$) {
Subroutine urandom: called CC=10 SCAR=32.1
Pod documented
812 2 ▶ my ($wanted, $opts) = @_; $wanted //= 64; $opts //= {};
Condition50%2/4
$wanted //= 64
l!l
02
$opts //= {}
l!l
02
MC/DC0%0/1
$wanted //= 64
$wanted
MC/DC0%0/1
$opts //= {}
$opts
Truth table50%1/2
A
A= $wanted
Aresult
11
00
Truth table50%1/2
A
A= $opts
Aresult
11
00
813  
814 2 ▶ my $default = [ q(), 'dev', $OSNAME eq 'freebsd' ? 'random' : 'urandom' ];
Branch: 1 branch
BranchTrueFalseTotal
$Class::Usul::Functions::OSNAME eq 'freebsd' ? : 0 2 2
815 2 ▶ my $io = io( $opts->{source} // $default )->block_size( $wanted );
Condition33%1/3
$opts->{"source"} // $default
l!l&&r!l&&!r
020
MC/DC0%0/2
$opts->{"source"} // $default
$opts->{"source"} $default
Truth table33%1/3
A // B
A= $opts->{"source"}B= $default
ABresult
1X1
011
000
816  
817 2 my $red; $io->exists and $io->is_readable and $red = $io->read
818 2 ▶ and $red == $wanted and return ${ $io->buffer };
Branch: 1 branch
BranchTrueFalseTotal
$io->exists and $io->is_readable and $red = $io->read and $red == $wanted and return ${$io->buffer;} 2 0 2
Condition33%3/9
$io->exists and $io->is_readable and $red = $io->read and $red == $wanted
!ll&&!rl&&r
002
$io->exists and $io->is_readable and $red = $io->read
!ll&&!rl&&r
002
$io->exists and $io->is_readable
!ll&&!rl&&r
002
MC/DC0%0/4
$io->exists and $io->is_readable and $red = $io->read and $red == $wanted
$io->exists $io->is_readable $red = $io->read $red == $wanted
Truth table20%1/5
A and B and C and D
A= $io->existsB= $io->is_readableC= $red = $io->readD= $red == $wanted
ABCDresult
0XXX0
10XX0
110X0
11100
11111
819  
820 0 ▶ my $res = q(); while (length $res < $wanted) { $res .= $_pseudo_random->() }
Branch: 1 branch
BranchTrueFalseTotal
if (length $res < $wanted) 0 0 0
821  
822 0 return substr $res, 0, $wanted;
823 }
824  
825 0 ▶sub uuid (;$) {
Subroutine uuid: not called CC=2 SCAR=17.9
Pod documented
826 0 ▶ return io( $_[ 0 ] // UUID_PATH )->chomp->getline;
Condition0%0/3
$_[0] // &UUID_PATH()
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] // &UUID_PATH()
$_[0] &UUID_PATH()
Truth table0%0/3
A // B
A= $_[0]B= &UUID_PATH()
ABresult
1X1
011
000
827 }
828  
829 1 ▶sub whiten ($) {
Subroutine whiten: called CC=1 SCAR=0.0
Pod documented
830 1 my $v = unpack "b*", pop; my $pad = " \t" x 8;
831  
832 1 $v =~ tr{01}{ \t}; $v =~ s{ (.{9}) }{$1\n}gmx;
833  
834 1 return "${pad}\n${v}";
835 }
836  
837 1 ▶sub zip (@) {
Subroutine zip: called CC=1 SCAR=0.0
Pod documented
838 1 my $p = @_ / 2; return @_[ map { $_, $_ + $p } 0 .. $p - 1 ];
839 }
840  
841 # Function composition
842 1 ▶sub chain (;@) {
Subroutine chain: called CC=1 SCAR=0.0
Pod documented
843 1 ▶ return (fold( sub { my ($x, $y) = @_; $x->$y } )->( shift ))->( @_ );
Subroutine __ANON__: called CC=1 SCAR=0.0
844 }
845  
846 3 ▶sub compose (&;$) { # Was called build
Subroutine compose: called CC=2 SCAR=7.0
Pod documented
847 3 ▶ my ($f, $g) = @_; $g //= sub { @_ }; return sub { $f->( $g->( @_ ) ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Condition66%2/3
$g //= sub { @_; }
l!l&&r!l&&!r
210
MC/DC0%0/2
$g //= sub { @_; }
$g sub { @_; }
Truth table66%2/3
A //= B
A= $gB= sub { @_; }
ABresult
1X1
011
000
848 }
849  
850 1 ▶sub curry (&$;@) {
Subroutine curry: called CC=1 SCAR=0.0
Pod documented
851 1 ▶ my ($f, @args) = @_; return sub { $f->( @args, @_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
852 }
853  
854 3 ▶sub fold (&) {
Subroutine fold: called CC=1 SCAR=0.0
Pod documented
855 3 my $f = shift;
856  
857 3 ▶ return sub (;$) {
Subroutine __ANON__: called CC=1 SCAR=0.0
858 3 my $x = shift;
859  
860 3 ▶ return sub (;@) {
Subroutine __ANON__: called CC=2 SCAR=6.9
861 3 ▶ my $y = $x; $y = $f->( $y, shift ) while (@_); return $y;
Branch: 1 branch
BranchTrueFalseTotal
@_ and do { $y = &$f($y, shift()) } 11 3 14
862 }
863 3 }
864 3 }
865  
866 116 ▶sub Y (&) {
Subroutine Y: called CC=1 SCAR=0.0
Pod documented
867 116 ▶ my $f = shift; return sub { $f->( Y( $f ) )->( @_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
868 }
869  
870 1 ▶sub factorial ($) {
Subroutine factorial: called CC=1 SCAR=0.0
Pod documented
871 5 ▶ return Y( sub (&) {
Subroutine __ANON__: called CC=1 SCAR=0.0
872 5 my $fac = shift;
873  
874 5 ▶ return sub ($) {
Subroutine __ANON__: called CC=2 SCAR=6.9
875 5 my $n = shift;
876  
877 1 ▶ return $n < 2 ? 1 : $n * $fac->( $n - 1 ) } } )->( @_ );
Branch: 1 branch
BranchTrueFalseTotal
$n < 2 ? : 1 4 5
878 }
879  
880 1 ▶sub fibonacci ($) {
Subroutine fibonacci: called CC=1 SCAR=0.0
Pod documented
881 109 ▶ return Y( sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
882 109 my $fib = shift;
883  
884 109 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
885 109 my $n = shift;
886  
887 109 ▶ return $n == 0 ? 0
Branch: 2 branches
BranchTrueFalseTotal
$n == 0 ? : 21 88 109
$n == 1 ? : 34 54 88
888 : $n == 1 ? 1
889 1 : $fib->( $n - 1 ) + $fib->( $n - 2 ) } } )->( @_ );
890 }
891  
892 1 ▶sub product (;@) {
Subroutine product: called CC=1 SCAR=0.0
Pod documented
893 1 ▶ return ((fold { $_[ 0 ] * $_[ 1 ] })->( 1 ))->( @_ );
Subroutine __ANON__: called CC=1 SCAR=0.0
894 }
895  
896 1 ▶sub sum (;@) {
Subroutine sum: called CC=1 SCAR=0.0
Pod documented
897 1 ▶ return ((fold { $_[ 0 ] + $_[ 1 ] })->( 0 ))->( @_ );
Subroutine __ANON__: called CC=1 SCAR=0.0
898 }
899  
900 27 1;
901  
902 __END__
« Usul/Log.pm ↑ Summary Usul/Config.pm »