KDBX/Util.pm

filter: Statementstmt 74.6% 373 / 500 Branchbran 56.9% 156 / 274 Conditioncond 64.3% 119 / 185 MC/DCmcdc 37.3% 37 / 99 Subroutinesub 84.9% 90 / 106 Podpod 100% 45 / 45 totaltotal 67.8% 820 / 1209 CC 216 SCAR 30.0
CC
216
Cov
68%
can_fork
197.9
pack_Ql
78.4
split_url
42.0
CRAP 20.1
« KDBX/Key.pm ↑ Summary KDBX/Loader/V4.pm »
1 package File::KDBX::Util;
2 # ABSTRACT: Utility functions for working with KDBX files
3  
4 64 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 64 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 64 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 64 ▶use Crypt::PRNG qw(random_bytes random_string);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 64 ▶use Encode qw(decode encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 64 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 64 ▶use File::KDBX::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 64 ▶use List::Util 1.33 qw(any all);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 64 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 64 ▶use Ref::Util qw(is_arrayref is_coderef is_hashref is_ref is_refref is_scalarref);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 64 ▶use Scalar::Util qw(blessed looks_like_number readonly);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 64 ▶use Time::Piece 1.33;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 64 ▶use boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 64 ▶use namespace::clean -except => 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 64 our $VERSION = '0.905'; # VERSION
21  
22 64 our %EXPORT_TAGS = (
23 assert => [qw(DEBUG assert)],
24 class => [qw(extends has list_attributes)],
25 clone => [qw(clone clone_nomagic)],
26 coercion => [qw(to_bool to_number to_string to_time to_tristate to_uuid)],
27 crypt => [qw(pad_pkcs7)],
28 debug => [qw(DEBUG dumper)],
29 fork => [qw(can_fork)],
30 function => [qw(memoize recurse_limit)],
31 empty => [qw(empty nonempty)],
32 erase => [qw(erase erase_scoped)],
33 gzip => [qw(gzip gunzip)],
34 int => [qw(int64 pack_ql pack_Ql unpack_ql unpack_Ql)],
35 io => [qw(read_all)],
36 load => [qw(load_optional load_xs try_load_optional)],
37 search => [qw(query query_any search simple_expression_query)],
38 text => [qw(snakify trim)],
39 uuid => [qw(format_uuid generate_uuid is_uuid uuid UUID_NULL)],
40 uri => [qw(split_url uri_escape_utf8 uri_unescape_utf8)],
41 );
42  
43 64 $EXPORT_TAGS{all} = [map { @$_ } values %EXPORT_TAGS];
44 64 our @EXPORT_OK = @{$EXPORT_TAGS{all}};
45  
46 BEGIN {
47 64 ▶ my $debug = $ENV{DEBUG};
Subroutine BEGIN: called CC=7 SCAR=23.2
48 64 ▶ $debug = looks_like_number($debug) ? (0 + $debug) : ($debug ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
&looks_like_number($debug) ? : 0 64 64
$debug ? : 0 64 64
49 *DEBUG = $debug == 1 ? sub() { 1 } :
50 $debug == 2 ? sub() { 2 } :
51 $debug == 3 ? sub() { 3 } :
52 64 ▶ $debug == 4 ? sub() { 4 } : sub() { 0 };
Branch: 4 branches
BranchTrueFalseTotal
$debug == 1 ? : 0 64 64
$debug == 2 ? : 0 64 64
$debug == 3 ? : 0 64 64
$debug == 4 ? : 0 64 64
53 }
54  
55 64 my %OPS = (
56 'eq' => 2, # binary
57 'ne' => 2,
58 'lt' => 2,
59 'gt' => 2,
60 'le' => 2,
61 'ge' => 2,
62 '==' => 2,
63 '!=' => 2,
64 '<' => 2,
65 '>' => 2,
66 '<=' => 2,
67 '>=' => 2,
68 '=~' => 2,
69 '!~' => 2,
70 '!' => 1, # unary
71 '!!' => 1,
72 '-not' => 1, # special
73 '-false' => 1,
74 '-true' => 1,
75 '-defined' => 1,
76 '-undef' => 1,
77 '-empty' => 1,
78 '-nonempty' => 1,
79 '-or' => -1,
80 '-and' => -1,
81 );
82 64 my %OP_NEG = (
83 'eq' => 'ne',
84 'ne' => 'eq',
85 'lt' => 'ge',
86 'gt' => 'le',
87 'le' => 'gt',
88 'ge' => 'lt',
89 '==' => '!=',
90 '!=' => '==',
91 '<' => '>=',
92 '>' => '<=',
93 '<=' => '>',
94 '>=' => '<',
95 '=~' => '!~',
96 '!~' => '=~',
97 );
98 64 my %ATTRIBUTES;
99  
100  
101 my $XS_LOADED;
102 sub load_xs {
103 76 ▶ my $version = shift;
Subroutine load_xs: called CC=6 SCAR=18.7
Pod documented
104  
105 76 ▶ goto IS_LOADED if defined $XS_LOADED;
Branch: 1 branch
BranchTrueFalseTotal
if defined $XS_LOADED 12 64 76
106  
107 64 ▶ if ($ENV{PERL_ONLY} || (exists $ENV{PERL_FILE_KDBX_XS} && !$ENV{PERL_FILE_KDBX_XS})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"PERL_ONLY"} or exists $ENV{"PERL_FILE_KDBX_XS"} and not $ENV{"PERL_FILE_KDBX_XS"}) 1 63 64
Condition66%4/6
$ENV{"PERL_ONLY"} or exists $ENV{"PERL_FILE_KDBX_XS"} and not $ENV{"PERL_FILE_KDBX_XS"}
l!l&&r!l&&!r
0163
exists $ENV{"PERL_FILE_KDBX_XS"} and not $ENV{"PERL_FILE_KDBX_XS"}
!ll&&!rl&&r
6301
MC/DC0%0/3
$ENV{"PERL_ONLY"} or exists $ENV{"PERL_FILE_KDBX_XS"} and not $ENV{"PERL_FILE_KDBX_XS"}
$ENV{"PERL_ONLY"} exists $ENV{"PERL_FILE_KDBX_XS"} not $ENV{"PERL_FILE_KDBX_XS"}
Truth table25%1/4
A or B and not(C)
A= $ENV{"PERL_ONLY"}B= exists $ENV{"PERL_FILE_KDBX_XS"}C= not $ENV{"PERL_FILE_KDBX_XS"}
ABCresult
1XX1
0111
00X0
0100
108 1 return $XS_LOADED = !1;
109 }
110  
111 63 $XS_LOADED = !!eval { require File::KDBX::XS; 1 };
112  
113 IS_LOADED:
114 {
115 75 local $@;
116 75 ▶ return $XS_LOADED if !$version;
Branch: 1 branch
BranchTrueFalseTotal
unless $version 75 0 75
117 0 return !!eval { File::KDBX::XS->VERSION($version); 1 };
118 }
119 }
120  
121  
122 sub assert(&) { ## no critic (ProhibitSubroutinePrototypes)
123 2320 ▶ return if !DEBUG;
Subroutine assert: called CC=3 SCAR=23.5
Pod documented
124 0 my $code = shift;
125 0 ▶ return if $code->();
Branch: 1 branch
BranchTrueFalseTotal
if &$code() 0 0 0
126  
127 0 (undef, my $file, my $line) = caller;
128 0 $file =~ s!([^/\\]+)$!$1!;
129 0 my $assertion = '';
130 0 ▶ if (try_load_optional('B::Deparse')) {
Branch: 1 branch
BranchTrueFalseTotal
if (try_load_optional("B::Deparse")) 0 0 0
131 0 my $deparse = B::Deparse->new(qw{-P -x9});
132 0 $assertion = $deparse->coderef2text($code);
133 0 $assertion =~ s/^\{(?:\s*(?:package[^;]+|use[^;]+);)*\s*(.*?);\s*\}$/$1/s;
134 0 $assertion =~ s/\s+/ /gs;
135 0 $assertion = ": $assertion";
136 }
137 0 die "$0: $file:$line: Assertion failed$assertion\n";
138 }
139  
140  
141 sub can_fork {
142 16 ▶ require Config;
Subroutine can_fork: called CC=15 SCAR=52.9
Pod documented
143 16 ▶ return 1 if $Config::Config{d_fork};
Branch: 1 branch
BranchTrueFalseTotal
if $Config::Config{"d_fork"} 16 0 16
144 0 ▶ return 0 if $^O ne 'MSWin32' && $^O ne 'NetWare';
Branch: 1 branch
BranchTrueFalseTotal
if $^O ne "MSWin32" and $^O ne "NetWare" 0 0 0
Condition0%0/3
$^O ne "MSWin32" and $^O ne "NetWare"
!ll&&!rl&&r
000
MC/DC0%0/2
$^O ne "MSWin32" and $^O ne "NetWare"
$^O ne "MSWin32" $^O ne "NetWare"
Truth table0%0/3
A and B
A= $^O ne "MSWin32"B= $^O ne "NetWare"
ABresult
0X0
100
111
145 0 ▶ return 0 if !$Config::Config{useithreads};
Branch: 1 branch
BranchTrueFalseTotal
unless $Config::Config{"useithreads"} 0 0 0
146 0 ▶ return 0 if $Config::Config{ccflags} !~ /-DPERL_IMPLICIT_SYS/;
Branch: 1 branch
BranchTrueFalseTotal
unless $Config::Config{"ccflags"} =~ /-DPERL_IMPLICIT_SYS/ 0 0 0
147 0 ▶ return 0 if $] < 5.008001;
Branch: 1 branch
BranchTrueFalseTotal
if $] < "5.008001" 0 0 0
148 0 ▶ if ($] == 5.010000 && $Config::Config{ccname} eq 'gcc' && $Config::Config{gccversion}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] == "5.01" and $Config::Config{"ccname"} eq "gcc" and $Config::Config{"gccversion"}) 0 0 0
Condition0%0/6
$] == "5.01" and $Config::Config{"ccname"} eq "gcc" and $Config::Config{"gccversion"}
!ll&&!rl&&r
000
$] == "5.01" and $Config::Config{"ccname"} eq "gcc"
!ll&&!rl&&r
000
MC/DC0%0/3
$] == "5.01" and $Config::Config{"ccname"} eq "gcc" and $Config::Config{"gccversion"}
$] == "5.01" $Config::Config{"ccname"} eq "gcc" $Config::Config{"gccversion"}
Truth table0%0/4
A and B and C
A= $] == "5.01"B= $Config::Config{"ccname"} eq "gcc"C= $Config::Config{"gccversion"}
ABCresult
0XX0
10X0
1100
1111
149 0 ▶ return 0 if $Config::Config{gccversion} !~ m/^(\d+)\.(\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $Config::Config{"gccversion"} =~ /^(\d+)\.(\d+)/ 0 0 0
150 0 my @parts = split(/[\.\s]+/, $Config::Config{gccversion});
151 0 ▶ return 0 if $parts[0] > 4 || ($parts[0] == 4 && $parts[1] >= 8);
Branch: 1 branch
BranchTrueFalseTotal
if $parts[0] > 4 or $parts[0] == 4 and $parts[1] >= 8 0 0 0
Condition0%0/6
$parts[0] > 4 or $parts[0] == 4 and $parts[1] >= 8
l!l&&r!l&&!r
000
$parts[0] == 4 and $parts[1] >= 8
!ll&&!rl&&r
000
MC/DC0%0/3
$parts[0] > 4 or $parts[0] == 4 and $parts[1] >= 8
$parts[0] > 4 $parts[0] == 4 $parts[1] >= 8
Truth table0%0/4
A or B and C
A= $parts[0] > 4B= $parts[0] == 4C= $parts[1] >= 8
ABCresult
1XX1
0111
00X0
0100
152 }
153 0 ▶ return 0 if $INC{'Devel/Cover.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"Devel/Cover.pm"} 0 0 0
154 0 return 1;
155 }
156  
157  
158 sub clone {
159 0 ▶ require Storable;
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
160 0 goto &Storable::dclone;
161 }
162  
163  
164 sub clone_nomagic {
165 0 ▶ my $thing = shift;
Subroutine clone_nomagic: not called CC=5 SCAR=34.0
Pod documented
166 0 ▶ if (is_arrayref($thing)) {
Branch: 3 branches
BranchTrueFalseTotal
if (Ref::Util::XS::is_arrayref($thing)) { } 0 0 0
elsif (Ref::Util::XS::is_hashref($thing)) { } 0 0 0
elsif (Ref::Util::XS::is_ref($thing)) { } 0 0 0
167 0 my @arr = map { clone_nomagic($_) } @$thing;
168 0 return \@arr;
169 }
170 elsif (is_hashref($thing)) {
171 0 my %hash;
172 0 $hash{$_} = clone_nomagic($thing->{$_}) for keys %$thing;
173 0 return \%hash;
174 }
175 elsif (is_ref($thing)) {
176 0 return clone($thing);
177 }
178 0 return $thing;
179 }
180  
181  
182 sub dumper {
183 0 ▶ require Data::Dumper;
Subroutine dumper: not called CC=3 SCAR=24.8
Pod documented
184 # avoid "once" warnings
185 0 local $Data::Dumper::Deepcopy = $Data::Dumper::Deepcopy = 1;
186 0 local $Data::Dumper::Deparse = $Data::Dumper::Deparse = 1;
187 0 local $Data::Dumper::Indent = 1;
188 0 local $Data::Dumper::Quotekeys = 0;
189 0 local $Data::Dumper::Sortkeys = 1;
190 0 local $Data::Dumper::Terse = 1;
191 0 local $Data::Dumper::Trailingcomma = 1;
192 0 local $Data::Dumper::Useqq = 1;
193  
194 0 my @dumps;
195 0 for my $struct (@_) {
196 0 my $str = Data::Dumper::Dumper($struct);
197  
198 # boolean
199 0 $str =~ s/bless\( do\{\\\(my \$o = ([01])\)\}, 'boolean' \)/boolean($1)/gs;
200 # Time::Piece
201 0 $str =~ s/bless\([^\)]+?(\d+)'?,\s+\d+,?\s+\], 'Time::Piece' \),/
202 0 "scalar gmtime($1), # " . scalar gmtime($1)->datetime/ges;
203  
204 0 ▶ print STDERR $str if !defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 0 0
205 0 push @dumps, $str;
206 0 return $str;
207 }
208 0 return join("\n", @dumps);
209 }
210  
211  
212 583 ▶sub empty { _empty(@_) }
Subroutine empty: called CC=1 SCAR=0.0
Pod documented
213 786 ▶sub nonempty { !_empty(@_) }
Subroutine nonempty: called CC=1 SCAR=0.0
Pod documented
214  
215 sub _empty {
216 1397 ▶ return 1 if @_ == 0;
Subroutine _empty: called CC=12 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 0 4 1393 1397
217 1393 local $_ = shift;
218 1393 ▶ return !defined $_
Condition100%30/30
!defined($_) || $_ eq '' || Ref::Util::XS::is_arrayref($_) && @$_ == 0 || Ref::Util::XS::is_hashref($_) && keys %$_ == 0 || Ref::Util::XS::is_scalarref($_) && (!defined($$_) || $$_ eq '') || Ref::Util::XS::is_refref($_) && _empty($$_)
l!l&&r!l&&!r
83614543
not defined $_ or $_ eq "" or Ref::Util::XS::is_arrayref($_) and @$_ == 0 or Ref::Util::XS::is_hashref($_) and keys %$_ == 0 or Ref::Util::XS::is_scalarref($_) and !defined($$_) || $$_ eq ""
l!l&&r!l&&!r
8288557
not defined $_ or $_ eq "" or Ref::Util::XS::is_arrayref($_) and @$_ == 0 or Ref::Util::XS::is_hashref($_) and keys %$_ == 0
l!l&&r!l&&!r
535293565
not defined $_ or $_ eq "" or Ref::Util::XS::is_arrayref($_) and @$_ == 0
l!l&&r!l&&!r
5332858
not defined $_ or $_ eq ""
l!l&&r!l&&!r
134399860
Ref::Util::XS::is_arrayref($_) and @$_ == 0
!ll&&!rl&&r
85622
Ref::Util::XS::is_hashref($_) and keys %$_ == 0
!ll&&!rl&&r
375190293
Ref::Util::XS::is_scalarref($_) and !defined($$_) || $$_ eq ""
!ll&&!rl&&r
55078
not defined $$_ or $$_ eq ""
l!l&&r!l&&!r
267
Ref::Util::XS::is_refref($_) and _empty($$_)
!ll&&!rl&&r
5291414
MC/DC90%10/11
!defined($_) || $_ eq '' || Ref::Util::XS::is_arrayref($_) && @$_ == 0 || Ref::Util::XS::is_hashref($_) && keys %$_ == 0 || Ref::Util::XS::is_scalarref($_) && (!defined($$_) || $$_ eq '') || Ref::Util::XS::is_refref($_) && _empty($$_)
not defined $_ $_ eq "" Ref::Util::XS::is_arrayref($_) @$_ == 0 Ref::Util::XS::is_hashref($_) keys %$_ == 0 Ref::Util::XS::is_scalarref($_) not defined $$_ $$_ eq "" Ref::Util::XS::is_refref($_) _empty($$_)
Truth table29%11/37
not(A) or B or C and D or E and F or G and not(H) or I || J and K
A= not defined $_B= $_ eq ""C= Ref::Util::XS::is_arrayref($_)D= @$_ == 0E= Ref::Util::XS::is_hashref($_)F= keys %$_ == 0G= Ref::Util::XS::is_scalarref($_)H= not defined $$_I= $$_ eq ""J= Ref::Util::XS::is_refref($_)K= _empty($$_)
ABCDEFGHIJKresult
1XXXXXXXXXX1
01XXXXXXXXX1
0011XXXXXXX1
000X11XXXXX1
001011XXXXX1
000X0X11XXX1
000X0X101XX1
000X1011XXX1
000X10101XX1
00100X11XXX1
00100X101XX1
00101011XXX1
001010101XX1
000X0X0XX111
000X0X100111
000X100XX111
000X10100111
00100X0XX111
00100X100111
0010100XX111
001010100111
000X0X0XX0X0
000X0X0XX100
000X0X1000X0
000X0X100100
000X100XX0X0
000X100XX100
000X101000X0
000X10100100
00100X0XX0X0
00100X0XX100
00100X1000X0
00100X100100
0010100XX0X0
0010100XX100
0010101000X0
001010100100
219 || $_ eq ''
220 || (is_arrayref($_) && @$_ == 0)
221 || (is_hashref($_) && keys %$_ == 0)
222 || (is_scalarref($_) && (!defined $$_ || $$_ eq ''))
223 || (is_refref($_) && _empty($$_));
224 }
225  
226  
227 BEGIN {
228 64 ▶ if (load_xs) {
Subroutine BEGIN: called CC=3 SCAR=11.6
Branch: 2 branches
BranchTrueFalseTotal
if (load_xs()) { } 63 1 64
elsif (eval { do { require B::COW; 1 } }) { } 1 0 1
229 63 *_CowREFCNT = \&File::KDBX::XS::CowREFCNT;
230 }
231 1 elsif (eval { require B::COW; 1 }) {
232 1 *_CowREFCNT = \&B::COW::cowrefcnt;
233 }
234 else {
235 0 ▶ *_CowREFCNT = sub { undef };
Subroutine __ANON__: not called CC=1 SCAR=6.9
236 }
237 }
238  
239 sub erase {
240 # Only bother zeroing out memory if we have the last SvPV COW reference, otherwise we'll end up just
241 # creating a copy and erasing the copy.
242 # TODO - Is this worth doing? Need some benchmarking.
243 1978 ▶ for (@_) {
Subroutine erase: called CC=14 SCAR=26.6
Pod documented
244 2065 ▶ if (!is_ref($_)) {
Branch: 4 branches
BranchTrueFalseTotal
if (not Ref::Util::XS::is_ref($_)) { } 360 1705 2065
elsif (Ref::Util::XS::is_scalarref($_)) { } 1639 66 1705
elsif (Ref::Util::XS::is_arrayref($_)) { } 65 1 66
elsif (Ref::Util::XS::is_hashref($_)) { } 1 0 1
245 360 ▶ next if !defined $_ || readonly $_;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_ or &readonly($_) 117 243 360
Condition66%2/3
not defined $_ or &readonly($_)
l!l&&r!l&&!r
1170243
MC/DC50%1/2
not defined $_ or &readonly($_)
not defined $_ &readonly($_)
Truth table66%2/3
not(A) or B
A= not defined $_B= &readonly($_)
ABresult
1X1
011
000
246 243 my $cowrefcnt = _CowREFCNT($_);
247 243 ▶ goto FREE_NONREF if defined $cowrefcnt && 1 < $cowrefcnt;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cowrefcnt and 1 < $cowrefcnt 0 243 243
Condition66%2/3
defined $cowrefcnt and 1 < $cowrefcnt
!ll&&!rl&&r
12420
MC/DC0%0/2
defined $cowrefcnt and 1 < $cowrefcnt
defined $cowrefcnt 1 < $cowrefcnt
Truth table66%2/3
A and B
A= defined $cowrefcntB= 1 < $cowrefcnt
ABresult
0X0
100
111
248 # if (__PACKAGE__->can('erase_xs')) {
249 # erase_xs($_);
250 # }
251 # else {
252 243 substr($_, 0, length($_), "\0" x length($_));
253 # }
254 FREE_NONREF: {
255 64 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
256 243 undef $_;
257 }
258 }
259 elsif (is_scalarref($_)) {
260 1639 ▶ next if !defined $$_ || readonly $$_;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $$_ or &readonly($$_) 415 1224 1639
Condition66%2/3
not defined $$_ or &readonly($$_)
l!l&&r!l&&!r
41501224
MC/DC50%1/2
not defined $$_ or &readonly($$_)
not defined $$_ &readonly($$_)
Truth table66%2/3
not(A) or B
A= not defined $$_B= &readonly($$_)
ABresult
1X1
011
000
261 1224 my $cowrefcnt = _CowREFCNT($$_);
262 1224 ▶ goto FREE_REF if defined $cowrefcnt && 1 < $cowrefcnt;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cowrefcnt and 1 < $cowrefcnt 245 979 1224
Condition100%3/3
defined $cowrefcnt and 1 < $cowrefcnt
!ll&&!rl&&r
252727245
MC/DC100%2/2
defined $cowrefcnt and 1 < $cowrefcnt
defined $cowrefcnt 1 < $cowrefcnt
Truth table100%3/3
A and B
A= defined $cowrefcntB= 1 < $cowrefcnt
ABresult
0X0
100
111
263 # if (__PACKAGE__->can('erase_xs')) {
264 # erase_xs($$_);
265 # }
266 # else {
267 979 substr($$_, 0, length($$_), "\0" x length($$_));
268 # }
269 FREE_REF: {
270 64 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
271 1224 undef $$_;
272 }
273 }
274 elsif (is_arrayref($_)) {
275 65 erase(@$_);
276 65 @$_ = ();
277 }
278 elsif (is_hashref($_)) {
279 1 erase(values %$_);
280 1 %$_ = ();
281 }
282 else {
283 0 throw 'Cannot erase this type of scalar', type => ref $_, what => $_;
284 }
285 }
286 }
287  
288  
289 sub erase_scoped {
290 828 ▶ throw 'Programmer error: Cannot call erase_scoped in void context' if !defined wantarray;
Subroutine erase_scoped: called CC=8 SCAR=21.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 828 828
291 828 my @args;
292 828 for (@_) {
293 890 ▶ !is_ref($_) || is_arrayref($_) || is_hashref($_) || is_scalarref($_)
Branch: 1 branch
BranchTrueFalseTotal
not Ref::Util::XS::is_ref($_) or Ref::Util::XS::is_arrayref($_) or Ref::Util::XS::is_hashref($_) or Ref::Util::XS::is_scalarref($_) or throw("Cannot erase this type of scalar", "type", ref $_, "what", $_) 0 890 890
Condition77%7/9
not Ref::Util::XS::is_ref($_) or Ref::Util::XS::is_arrayref($_) or Ref::Util::XS::is_hashref($_) or Ref::Util::XS::is_scalarref($_)
l!l&&r!l&&!r
844460
not Ref::Util::XS::is_ref($_) or Ref::Util::XS::is_arrayref($_) or Ref::Util::XS::is_hashref($_)
l!l&&r!l&&!r
844046
not Ref::Util::XS::is_ref($_) or Ref::Util::XS::is_arrayref($_)
l!l&&r!l&&!r
7806446
MC/DC0%0/4
not Ref::Util::XS::is_ref($_) or Ref::Util::XS::is_arrayref($_) or Ref::Util::XS::is_hashref($_) or Ref::Util::XS::is_scalarref($_)
not Ref::Util::XS::is_ref($_) Ref::Util::XS::is_arrayref($_) Ref::Util::XS::is_hashref($_) Ref::Util::XS::is_scalarref($_)
Truth table60%3/5
not(A) or B or C or D
A= not Ref::Util::XS::is_ref($_)B= Ref::Util::XS::is_arrayref($_)C= Ref::Util::XS::is_hashref($_)D= Ref::Util::XS::is_scalarref($_)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
294 or throw 'Cannot erase this type of scalar', type => ref $_, what => $_;
295 890 ▶ push @args, is_ref($_) ? $_ : \$_;
Branch: 1 branch
BranchTrueFalseTotal
Ref::Util::XS::is_ref($_) ? : 110 780 890
296 }
297 828 require Scope::Guard;
298 828 ▶ return Scope::Guard->new(sub { erase(@args) });
Subroutine __ANON__: called CC=1 SCAR=0.0
299 }
300  
301  
302 sub extends {
303 162 ▶ my $parent = shift;
Subroutine extends: called CC=1 SCAR=0.0
Pod documented
304 162 my $caller = caller;
305 162 load $parent;
306 64 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
307 162 @{"${caller}::ISA"} = $parent;
308 }
309  
310  
311 sub has {
312 1765 ▶ my $name = shift;
Subroutine has: called CC=15 SCAR=27.1
Pod documented
313 1765 ▶ my %args = @_ % 2 == 1 ? (default => shift, @_) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 == 1 ? : 1598 167 1765
314  
315 1765 my ($package, $file, $line) = caller;
316  
317 1765 my $d = $args{default};
318 1765 ▶ my $default = is_arrayref($d) ? sub { [@$d] } : is_hashref($d) ? sub { +{%$d} } : $d;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
BranchTrueFalseTotal
Ref::Util::XS::is_arrayref($d) ? : 36 1729 1765
Ref::Util::XS::is_hashref($d) ? : 181 1548 1729
319 1765 my $coerce = $args{coerce};
320 1765 ▶ my $is = $args{is} || 'rw';
Condition100%2/2
$args{'is'} || 'rw'
l!l
1561609
MC/DC100%1/1
$args{'is'} || 'rw'
$args{'is'}
Truth table100%2/2
A
A= $args{'is'}
Aresult
11
00
321  
322 1765 my $store = $args{store};
323 1765 ▶ ($store, $name) = split(/\./, $name, 2) if $name =~ /\./;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\./ 900 865 1765
324  
325 1765 ▶ my @path = split(/\./, $args{path} || '');
Condition100%2/2
$args{'path'} || ''
l!l
331732
MC/DC100%1/1
$args{'path'} || ''
$args{'path'}
Truth table100%2/2
A
A= $args{'path'}
Aresult
11
00
326 1765 my $last = pop @path;
327 1765 ▶ my $path = $last ? join('', map { qq{->$_} } @path) . qq{->{'$last'}}
Branch: 2 branches
BranchTrueFalseTotal
$last ? : 33 1732 1765
$store ? : 1047 685 1732
328 : $store ? qq{->$store\->{'$name'}} : qq{->{'$name'}};
329 1765 my $member = qq{\$_[0]$path};
330  
331  
332 1765 ▶ my $default_code = is_coderef $default ? q{scalar $default->($_[0])}
Branch: 2 branches
BranchTrueFalseTotal
Ref::Util::XS::is_coderef($default) ? : 623 1142 1765
defined $default ? : 935 207 1142
333 : defined $default ? q{$default}
334 : q{undef};
335 1765 my $get = qq{$member //= $default_code;};
336  
337 1765 my $set = '';
338 1765 ▶ if ($is eq 'rw') {
Branch: 1 branch
BranchTrueFalseTotal
if ($is eq "rw") 1609 156 1765
339 1609 ▶ $set = is_coderef $coerce ? qq{$member = scalar \$coerce->(\@_[1..\$#_]) if \$#_;}
Branch: 2 branches
BranchTrueFalseTotal
Ref::Util::XS::is_coderef($coerce) ? : 1317 292 1609
defined $coerce ? : 0 292 292
340 : defined $coerce ? qq{$member = do { local @_ = (\@_[1..\$#_]); $coerce } if \$#_;}
341 : qq{$member = \$_[1] if \$#_;};
342 }
343  
344 1765 ▶ push @{$ATTRIBUTES{$package} //= []}, $name;
Condition100%2/2
$ATTRIBUTES{$package} //= []
l!l
1650115
MC/DC100%1/1
$ATTRIBUTES{$package} //= []
$ATTRIBUTES{$package}
Truth table100%2/2
A
A= $ATTRIBUTES{$package}
Aresult
11
00
345 1765 $line -= 4;
346 1765 my $code = <<END;
347 # line $line "$file"
348 sub ${package}::${name} {
349 return $default_code if !Scalar::Util::blessed(\$_[0]);
350 $set
351 $get
352 }
353 END
354 1765 eval $code; ## no critic (ProhibitStringyEval)
355 }
356  
357  
358 sub format_uuid {
359 376 ▶ local $_ = shift // "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
Subroutine format_uuid: called CC=4 SCAR=14.2
Pod documented
Condition50%1/2
shift() // "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
l!l
3760
MC/DC0%0/1
shift() // "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
360 376 ▶ my $delim = shift // '';
Condition100%2/2
shift() // ""
l!l
1375
MC/DC100%1/1
shift() // ""
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
361 376 ▶ length($_) == 16 or throw 'Must provide a 16-bytes UUID', size => length($_), str => $_;
Branch: 1 branch
BranchTrueFalseTotal
length $_ == 16 or throw("Must provide a 16-bytes UUID", "size", length $_, "str", $_) 0 376 376
362 376 return uc(join($delim, unpack('H8 H4 H4 H4 H12', $_)));
363 }
364  
365  
366 sub generate_uuid {
367 191 ▶ my $set = @_ % 2 == 1 ? shift : undef;
Subroutine generate_uuid: called CC=8 SCAR=20.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 == 1 ? : 2 189 191
368 191 my %args = @_;
369 191 ▶ my $test = $set //= $args{test};
Condition66%2/3
$set //= $args{"test"}
l!l&&r!l&&!r
20189
MC/DC50%1/2
$set //= $args{"test"}
$set $args{"test"}
Truth table66%2/3
A //= B
A= $setB= $args{"test"}
ABresult
1X1
011
000
370 191 ▶ $test = sub { !$set->{$_} } if is_hashref($test);
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if Ref::Util::XS::is_hashref($test) 1 190 191
371 191 ▶ $test //= sub { 1 };
Subroutine __ANON__: called CC=1 SCAR=0.1
Condition66%2/3
$test //= sub { 1; }
l!l&&r!l&&!r
21890
MC/DC0%0/2
$test //= sub { 1; }
$test sub { 1; }
Truth table66%2/3
A //= B
A= $testB= sub { 1; }
ABresult
1X1
011
000
372 191 ▶ my $printable = $args{printable} // $args{print};
Condition100%3/3
$args{"printable"} // $args{"print"}
l!l&&r!l&&!r
11189
MC/DC100%2/2
$args{"printable"} // $args{"print"}
$args{"printable"} $args{"print"}
Truth table100%3/3
A // B
A= $args{"printable"}B= $args{"print"}
ABresult
1X1
011
000
373 191 local $_ = '';
374 191 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
&$test($_) or do { do { $_ = $printable ? &random_string(16) : &random_bytes(16) } } 0 191 191
375 191 ▶ $_ = $printable ? random_string(16) : random_bytes(16);
Branch: 1 branch
BranchTrueFalseTotal
$printable ? : 2 189 191
376 } while (!$test->($_));
377 191 return $_;
378 }
379  
380  
381 sub gunzip {
382 0 ▶ load_optional('Compress::Raw::Zlib');
Subroutine gunzip: not called CC=3 SCAR=24.8
Pod documented
383 0 local $_ = shift;
384 0 my ($i, $status) = Compress::Raw::Zlib::Inflate->new(-WindowBits => 31);
385 0 ▶ $status == Compress::Raw::Zlib::Z_OK()
Branch: 1 branch
BranchTrueFalseTotal
$status == Compress::Raw::Zlib::Z_OK() or throw("Failed to initialize compression library", "status", $status) 0 0 0
386 or throw 'Failed to initialize compression library', status => $status;
387 0 $status = $i->inflate($_, my $out);
388 0 ▶ $status == Compress::Raw::Zlib::Z_STREAM_END()
Branch: 1 branch
BranchTrueFalseTotal
$status == Compress::Raw::Zlib::Z_STREAM_END() or throw("Failed to decompress data", "status", $status) 0 0 0
389 or throw 'Failed to decompress data', status => $status;
390 0 return $out;
391 }
392  
393  
394 sub gzip {
395 2 ▶ load_optional('Compress::Raw::Zlib');
Subroutine gzip: called CC=4 SCAR=14.2
Pod documented
396 2 local $_ = shift;
397 2 my ($d, $status) = Compress::Raw::Zlib::Deflate->new(-WindowBits => 31, -AppendOutput => 1);
398 2 ▶ $status == Compress::Raw::Zlib::Z_OK()
Branch: 1 branch
BranchTrueFalseTotal
$status == Compress::Raw::Zlib::Z_OK() or throw("Failed to initialize compression library", "status", $status) 0 2 2
399 or throw 'Failed to initialize compression library', status => $status;
400 2 $status = $d->deflate($_, my $out);
401 2 ▶ $status == Compress::Raw::Zlib::Z_OK()
Branch: 1 branch
BranchTrueFalseTotal
$status == Compress::Raw::Zlib::Z_OK() or throw("Failed to compress data", "status", $status) 0 2 2
402 or throw 'Failed to compress data', status => $status;
403 2 $status = $d->flush($out);
404 2 ▶ $status == Compress::Raw::Zlib::Z_OK()
Branch: 1 branch
BranchTrueFalseTotal
$status == Compress::Raw::Zlib::Z_OK() or throw("Failed to compress data", "status", $status) 0 2 2
405 or throw 'Failed to compress data', status => $status;
406 2 return $out;
407 }
408  
409  
410 sub int64 {
411 67 ▶ require Config;
Subroutine int64: called CC=2 SCAR=8.4
Pod documented
412 67 ▶ if ($Config::Config{ivsize} < 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Config::Config{"ivsize"} < 8) 0 67 67
413 0 require Math::BigInt;
414 0 return Math::BigInt->new(@_);
415 }
416 67 return 0 + shift;
417 }
418  
419  
420 sub pack_Ql {
421 317 ▶ my $num = shift;
Subroutine pack_Ql: called CC=10 SCAR=43.6
Pod documented
422 317 require Config;
423 317 ▶ if ($Config::Config{ivsize} < 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Config::Config{"ivsize"} < 8) 0 317 317
424 0 ▶ if (blessed $num && $num->can('as_hex')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($num) and $num->can('as_hex')) { } 0 0 0
Condition0%0/3
builtin::blessed($num) and $num->can("as_hex")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($num) and $num->can("as_hex")
builtin::blessed($num) $num->can("as_hex")
Truth table0%0/3
A and B
A= builtin::blessed($num)B= $num->can("as_hex")
ABresult
0X0
100
111
425 0 require Math::BigInt;
426 0 ▶ return "\xff\xff\xff\xff\xff\xff\xff\xff" if Math::BigInt->new('18446744073709551615') <= $num;
Branch: 1 branch
BranchTrueFalseTotal
if "Math::BigInt"->new("18446744073709551615") <= $num 0 0 0
427 0 ▶ return "\x00\x00\x00\x00\x00\x00\x00\x80" if $num <= Math::BigInt->new('-9223372036854775808');
Branch: 1 branch
BranchTrueFalseTotal
if $num <= "Math::BigInt"->new("-9223372036854775808") 0 0 0
428 0 my $neg;
429 0 ▶ if ($num < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num < 0) 0 0 0
430 0 $neg = 1;
431 0 $num = -$num;
432 }
433 0 my $hex = $num->as_hex;
434 0 $hex =~ s/^0x/000000000000000/;
435 0 my $bytes = reverse pack('H16', substr($hex, -16));
436 0 ▶ $bytes .= "\0" x (8 - length $bytes) if length $bytes < 8;
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes < 8 0 0 0
437 0 ▶ if ($neg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($neg) 0 0 0
438 # two's compliment
439 0 $bytes = join('', map { chr(~ord($_) & 0xff) } split(//, $bytes));
440 0 substr($bytes, 0, 1, chr(ord(substr($bytes, 0, 1)) + 1));
441 }
442 0 return $bytes;
443 }
444 else {
445 0 ▶ my $pad = $num < 0 ? "\xff" : "\0";
Branch: 1 branch
BranchTrueFalseTotal
$num < 0 ? : 0 0 0
446 0 return pack('L<', $num) . ($pad x 4);
447 };
448 }
449 317 return pack('Q<', $num);
450 }
451  
452  
453 0 ▶sub pack_ql { goto &pack_Ql }
Subroutine pack_ql: not called CC=1 SCAR=6.9
Pod documented
454  
455  
456 sub unpack_Ql {
457 174 ▶ my $bytes = shift;
Subroutine unpack_Ql: called CC=2 SCAR=7.9
Pod documented
458 174 require Config;
459 174 ▶ if ($Config::Config{ivsize} < 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Config::Config{"ivsize"} < 8) 0 174 174
460 0 require Math::BigInt;
461 0 return Math::BigInt->new('0x' . unpack('H*', scalar reverse $bytes));
462 }
463 174 return unpack('Q<', $bytes);
464 }
465  
466  
467 sub unpack_ql {
468 8 ▶ my $bytes = shift;
Subroutine unpack_ql: called CC=4 SCAR=23.1
Pod documented
469 8 require Config;
470 8 ▶ if ($Config::Config{ivsize} < 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Config::Config{"ivsize"} < 8) 0 8 8
471 0 require Math::BigInt;
472 0 ▶ if (ord(substr($bytes, -1, 1)) & 128) {
Branch: 1 branch
BranchTrueFalseTotal
if (ord substr($bytes, -1, 1) & 128) { } 0 0 0
473 0 ▶ return Math::BigInt->new('-9223372036854775808') if $bytes eq "\x00\x00\x00\x00\x00\x00\x00\x80";
Branch: 1 branch
BranchTrueFalseTotal
if $bytes eq "\0\0\0\0\0\0\0\200" 0 0 0
474 # two's compliment
475 0 substr($bytes, 0, 1, chr(ord(substr($bytes, 0, 1)) - 1));
476 0 $bytes = join('', map { chr(~ord($_) & 0xff) } split(//, $bytes));
477 0 return -Math::BigInt->new('0x' . unpack('H*', scalar reverse $bytes));
478 }
479 else {
480 0 return Math::BigInt->new('0x' . unpack('H*', scalar reverse $bytes));
481 }
482 }
483 8 return unpack('q<', $bytes);
484 }
485  
486  
487 0 ▶sub is_uuid { defined $_[0] && !is_ref($_[0]) && length($_[0]) == 16 }
Subroutine is_uuid: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and not Ref::Util::XS::is_ref($_[0]) and length $_[0] == 16 0 0 0
Condition0%0/3
defined $_[0] and not Ref::Util::XS::is_ref($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0] and not Ref::Util::XS::is_ref($_[0])
defined $_[0] not Ref::Util::XS::is_ref($_[0])
Truth table0%0/3
A and not(B)
A= defined $_[0]B= not Ref::Util::XS::is_ref($_[0])
ABresult
0X0
100
111
488  
489  
490 sub list_attributes {
491 223 ▶ my $package = shift;
Subroutine list_attributes: called CC=2 SCAR=7.1
Pod documented
492 223 ▶ return @{$ATTRIBUTES{$package} // []};
Condition50%1/2
$ATTRIBUTES{$package} // []
l!l
2230
MC/DC0%0/1
$ATTRIBUTES{$package} // []
$ATTRIBUTES{$package}
Truth table50%1/2
A
A= $ATTRIBUTES{$package}
Aresult
11
00
493 }
494  
495  
496 sub load_optional {
497 96 ▶ for my $module (@_) {
Subroutine load_optional: called CC=4 SCAR=14.9
Pod documented
498 96 eval { load $module };
499 96 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 96 96
500 0 throw "Missing dependency: Please install $module to use this feature.\n",
501 module => $module,
502 error => $err;
503 }
504 }
505 96 ▶ return wantarray ? @_ : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 96 96
506 }
507  
508  
509 sub memoize {
510 346 ▶ my $func = shift;
Subroutine memoize: called CC=1 SCAR=0.0
Pod documented
511 346 my @args = @_;
512 346 my %cache;
513 346 ▶ return sub { $cache{join("\0", grep { defined } @_)} //= $func->(@args, @_) };
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%3/3
$cache{join "\0", grep({defined $_;} @_)} //= &$func(@args, @_)
l!l&&r!l&&!r
34045
MC/DC100%2/2
$cache{join "\0", grep({defined $_;} @_)} //= &$func(@args, @_)
$cache{join "\0", grep({defined $_;} @_)} &$func(@args, @_)
Truth table100%3/3
A //= B
A= $cache{join "\0", grep({defined $_;} @_)}B= &$func(@args, @_)
ABresult
1X1
011
000
514 }
515  
516  
517 sub pad_pkcs7 {
518 16 ▶ my $data = shift // throw 'Must provide a string to pad';
Subroutine pad_pkcs7: called CC=5 SCAR=17.0
Pod documented
Condition66%2/3
shift() // throw("Must provide a string to pad")
l!l&&r!l&&!r
1510
MC/DC0%0/2
shift() // throw("Must provide a string to pad")
shift() throw("Must provide a string to pad")
Truth table33%1/3
A // B
A= shift()B= throw("Must provide a string to pad")
ABresult
1X1
011
000
519 15 ▶ my $size = shift or throw 'Must provide block size';
Branch: 1 branch
BranchTrueFalseTotal
my $size = shift() or throw("Must provide block size") 2 13 15
520  
521 13 ▶ 0 <= $size && $size < 256
Branch: 1 branch
BranchTrueFalseTotal
0 <= $size and $size < 256 or throw("Cannot add PKCS7 padding to a large block size", "size", $size) 0 13 13
Condition33%1/3
0 <= $size and $size < 256
!ll&&!rl&&r
0013
MC/DC0%0/2
0 <= $size and $size < 256
0 <= $size $size < 256
Truth table33%1/3
A and B
A= 0 <= $sizeB= $size < 256
ABresult
0X0
100
111
522 or throw 'Cannot add PKCS7 padding to a large block size', size => $size;
523  
524 13 my $pad_len = $size - length($data) % $size;
525 13 $data .= chr($pad_len) x $pad_len;
526 }
527  
528  
529 65 ▶sub query { _query(undef, '-or', \@_) }
Subroutine query: called CC=1 SCAR=0.0
Pod documented
530  
531  
532 sub query_any {
533 395 ▶ my $code = shift;
Subroutine query_any: called CC=4 SCAR=13.9
Pod documented
534  
535 395 ▶ if (is_coderef($code) || overload::Method($code, '&{}')) {
Branch: 2 branches
BranchTrueFalseTotal
if (Ref::Util::XS::is_coderef($code) or overload::Method($code, '&{}')) { } 359 36 395
elsif (Ref::Util::XS::is_scalarref($code)) { } 2 34 36
Condition66%2/3
Ref::Util::XS::is_coderef($code) or overload::Method($code, "&{}")
l!l&&r!l&&!r
359036
MC/DC50%1/2
Ref::Util::XS::is_coderef($code) or overload::Method($code, "&{}")
Ref::Util::XS::is_coderef($code) overload::Method($code, "&{}")
Truth table66%2/3
A or B
A= Ref::Util::XS::is_coderef($code)B= overload::Method($code, "&{}")
ABresult
1X1
011
000
536 359 return $code;
537 }
538 elsif (is_scalarref($code)) {
539 2 return simple_expression_query($$code, @_);
540 }
541 else {
542 34 return query($code, @_);
543 }
544 }
545  
546  
547 sub read_all($$$;$) { ## no critic (ProhibitSubroutinePrototypes)
548 1306 ▶ my $result = @_ == 3 ? read($_[0], $_[1], $_[2])
Subroutine read_all: called CC=4 SCAR=14.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 ? : 1306 0 1306
549 : read($_[0], $_[1], $_[2], $_[3]);
550 1306 ▶ return if !defined $result;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 1306 1306
551 1306 ▶ return if $result != $_[2];
Branch: 1 branch
BranchTrueFalseTotal
if $result != $_[2] 1 1305 1306
552 1305 return $result;
553 }
554  
555  
556 sub recurse_limit {
557 23 ▶ my $func = shift;
Subroutine recurse_limit: called CC=3 SCAR=11.3
Pod documented
558 23 ▶ my $max_depth = shift // 200;
Condition50%1/2
shift() // 200
l!l
230
MC/DC0%0/1
shift() // 200
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
559 23 ▶ my $error = shift // sub {};
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
shift() // sub { }
l!l&&r!l&&!r
2300
MC/DC0%0/2
shift() // sub { }
shift() sub { }
Truth table33%1/3
A // B
A= shift()B= sub { }
ABresult
1X1
011
000
560 23 my $depth = 0;
561 23 ▶ return sub { return $error->(@_) if $max_depth < ++$depth; $func->(@_) };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $max_depth < ++$depth 1 41 42
562 };
563  
564  
565 sub search {
566 36 ▶ my $list = shift;
Subroutine search: called CC=3 SCAR=11.0
Pod documented
567 36 my $query = query_any(@_);
568  
569 36 my @match;
570 36 for my $item (@$list) {
571 144 ▶ push @match, $item if $query->($item);
Branch: 1 branch
BranchTrueFalseTotal
if &$query($item) 50 94 144
572 }
573 36 return \@match;
574 }
575  
576  
577 sub simple_expression_query {
578 21 ▶ my $expr = shift;
Subroutine simple_expression_query: called CC=10 SCAR=23.1
Pod documented
579 21 ▶ my $op = @_ && ($OPS{$_[0] || ''} || 0) == 2 ? shift : '=~';
Branch: 1 branch
BranchTrueFalseTotal
@_ && ($OPS{$_[0] or ''} || 0) == 2 ? : 10 11 21
Condition71%5/7
@_ and ($OPS{$_[0] or ""} || 0) == 2
!ll&&!rl&&r
01110
$OPS{$_[0] or ''} || 0
l!l
1011
$_[0] || ''
l!l
210
MC/DC50%1/2
@_ and ($OPS{$_[0] or ""} || 0) == 2
@_ $OPS{$_[0] or ''}
MC/DC0%0/1
$_[0] || ''
$_[0]
Truth table66%2/3
A and B
A= @_B= $OPS{$_[0] or ''}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
580  
581 21 my $neg_op = $OP_NEG{$op};
582 21 ▶ my $is_re = $op eq '=~' || $op eq '!~';
Condition66%2/3
$op eq '=~' || $op eq '!~'
l!l&&r!l&&!r
1902
MC/DC50%1/2
$op eq '=~' || $op eq '!~'
$op eq '=~' $op eq '!~'
Truth table66%2/3
A || B
A= $op eq '=~'B= $op eq '!~'
ABresult
1X1
011
000
583  
584 21 require Text::ParseWords;
585 21 my @terms = Text::ParseWords::shellwords($expr);
586  
587 21 my @query = qw(-and);
588  
589 21 for my $term (@terms) {
590 28 my @subquery = qw(-or);
591  
592 28 my $neg = $term =~ s/^-//;
593 28 ▶ my $condition = [($neg ? $neg_op : $op) => ($is_re ? qr/\Q$term\E/i : $term)];
Branch: 2 branches
BranchTrueFalseTotal
$neg ? : 4 24 28
$is_re ? : 26 2 28
594  
595 28 for my $field (@_) {
596 32 push @subquery, $field => $condition;
597 }
598  
599 28 push @query, \@subquery;
600 }
601  
602 21 return query(\@query);
603 }
604  
605  
606 sub snakify {
607 3450 ▶ local $_ = shift;
Subroutine snakify: called CC=1 SCAR=0.0
Pod documented
608 3450 s/UserName/Username/g;
609 3450 s/([a-z])([A-Z0-9])/${1}_${2}/g;
610 3450 s/([A-Z0-9]+)([A-Z0-9])(?![A-Z0-9]|$)/${1}_${2}/g;
611 3450 return lc($_);
612 }
613  
614  
615 sub split_url {
616 0 ▶ local $_ = shift;
Subroutine split_url: not called CC=6 SCAR=37.4
Pod documented
617 0 my ($scheme, $auth, $host, $port, $path, $query, $hash) =~ m!
618 ^([^:/\?\#]+) ://
619 (?:([^\@]+)\@)
620 ([^:/\?\#]*)
621 (?::(\d+))?
622 ([^\?\#]*)
623 (\?[^\#]*)?
624 (\#(.*))?
625 !x;
626  
627 0 $scheme = lc($scheme);
628  
629 0 ▶ $host ||= 'localhost';
Condition0%0/2
$host ||= "localhost"
l!l
00
MC/DC0%0/1
$host ||= "localhost"
$host
Truth table0%0/2
A
A= $host
Aresult
11
00
630 0 $host = lc($host);
631  
632 0 ▶ $path = "/$path" if $path !~ m!^/!;
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ m[^/] 0 0 0
633  
634 0 ▶ $port ||= $scheme eq 'http' ? 80 : $scheme eq 'https' ? 433 : undef;
Branch: 2 branches
BranchTrueFalseTotal
$scheme eq 'http' ? : 0 0 0
$scheme eq 'https' ? : 0 0 0
Condition0%0/3
$port ||= $scheme eq "http" ? 80 : ($scheme eq "https" ? 433 : undef)
l!l&&r!l&&!r
000
MC/DC0%0/2
$port ||= $scheme eq "http" ? 80 : ($scheme eq "https" ? 433 : undef)
$port $scheme eq "http" ? 80 : ($scheme eq "https" ? 433 : undef)
Truth table0%0/3
A ||= B
A= $portB= $scheme eq "http" ? 80 : ($scheme eq "https" ? 433 : undef)
ABresult
1X1
011
000
635  
636 0 my ($username, $password) = split($auth, ':', 2);
637  
638 0 return ($scheme, $auth, $host, $port, $path, $query, $hash, $username, $password);
639 }
640  
641  
642 66 ▶sub to_bool { $_[0] // return; boolean($_[0]) }
Subroutine to_bool: called CC=2 SCAR=7.2
Pod documented
Condition50%1/2
$_[0] // (return)
l!l
660
MC/DC0%0/1
$_[0] // (return)
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
643 98 ▶sub to_number { $_[0] // return; 0+$_[0] }
Subroutine to_number: called CC=2 SCAR=7.2
Pod documented
Condition50%1/2
$_[0] // (return)
l!l
980
MC/DC0%0/1
$_[0] // (return)
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
644 203 ▶sub to_string { $_[0] // return; "$_[0]" }
Subroutine to_string: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$_[0] // (return)
l!l
2003
MC/DC100%1/1
$_[0] // (return)
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
645 sub to_time {
646 32 ▶ $_[0] // return;
Subroutine to_time: called CC=5 SCAR=16.3
Pod documented
Condition50%1/2
$_[0] // (return)
l!l
320
MC/DC0%0/1
$_[0] // (return)
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
647 32 ▶ return scalar gmtime($_[0]) if looks_like_number($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if &looks_like_number($_[0]) 0 32 32
648 32 ▶ return scalar gmtime if $_[0] eq 'now';
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] eq "now" 1 31 32
649 31 ▶ return Time::Piece->strptime($_[0], '%Y-%m-%d %H:%M:%S') if !blessed $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 1 30 31
650 30 return $_[0];
651 }
652 2 ▶sub to_tristate { $_[0] // return; boolean($_[0]) }
Subroutine to_tristate: called CC=2 SCAR=7.2
Pod documented
Condition50%1/2
$_[0] // (return)
l!l
20
MC/DC0%0/1
$_[0] // (return)
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
653 sub to_uuid {
654 10 ▶ my $str = to_string(@_) // return;
Subroutine to_uuid: called CC=4 SCAR=14.2
Pod documented
Condition100%2/2
to_string(@_) // (return)
l!l
73
MC/DC100%1/1
to_string(@_) // (return)
to_string(@_)
Truth table100%2/2
A
A= to_string(@_)
Aresult
11
00
655 7 ▶ return sprintf('%016s', $str) if length($str) < 16;
Branch: 1 branch
BranchTrueFalseTotal
if length $str < 16 0 7 7
656 7 ▶ return substr($str, 0, 16) if 16 < length($str);
Branch: 1 branch
BranchTrueFalseTotal
if 16 < length $str 0 7 7
657 7 return $str;
658 }
659  
660  
661 sub trim($) { ## no critic (ProhibitSubroutinePrototypes)
662 1790 ▶ local $_ = shift // return;
Subroutine trim: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
shift() // (return)
l!l
171278
MC/DC100%1/1
shift() // (return)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
663 1712 s/^\s*//;
664 1712 s/\s*$//;
665 1712 return $_;
666 }
667  
668  
669 sub try_load_optional {
670 2 ▶ for my $module (@_) {
Subroutine try_load_optional: called CC=3 SCAR=12.0
Pod documented
671 2 eval { load $module };
672 2 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 2 2
673 0 warn $err if 3 <= DEBUG;
674 0 return;
675 }
676 }
677 2 return @_;
678 }
679  
680  
681 64 my %ESC = map { chr($_) => sprintf('%%%02X', $_) } 0..255;
682 sub uri_escape_utf8 {
683 148 ▶ local $_ = shift // return;
Subroutine uri_escape_utf8: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
shift() // (return)
l!l
1462
MC/DC100%1/1
shift() // (return)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
684 146 $_ = encode('UTF-8', $_);
685 # RFC 3986 section 2.3 unreserved characters
686 146 s/([^A-Za-z0-9\-\._~])/$ESC{$1}/ge;
687 146 return $_;
688 }
689  
690  
691 sub uri_unescape_utf8 {
692 24 ▶ local $_ = shift // return;
Subroutine uri_unescape_utf8: called CC=2 SCAR=7.1
Pod documented
Condition50%1/2
shift() // (return)
l!l
240
MC/DC0%0/1
shift() // (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
693 24 s/\%([A-Fa-f0-9]{2})/chr(hex($1))/;
694 24 return decode('UTF-8', $_);
695 }
696  
697  
698 sub uuid {
699 12 ▶ local $_ = shift // return "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
Subroutine uuid: called CC=3 SCAR=11.4
Pod documented
Condition50%1/2
shift() // (return "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0")
l!l
120
MC/DC0%0/1
shift() // (return "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0")
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
700 12 s/-//g;
701 12 ▶ /^[A-Fa-f0-9]{32}$/ or throw 'Must provide a formatted 128-bit UUID';
Branch: 1 branch
BranchTrueFalseTotal
/^[A-Fa-f0-9]{32}$/ or throw("Must provide a formatted 128-bit UUID") 0 12 12
702 12 return pack('H32', $_);
703  
704 }
705  
706  
707 sub UUID_NULL() { "\0" x 16 }
708  
709 ### --------------------------------------------------------------------------
710  
711 # Determine if an array looks like keypairs from a hash.
712 sub _looks_like_keypairs {
713 216 ▶ my $arr = shift;
Subroutine _looks_like_keypairs: called CC=4 SCAR=13.9
714 216 ▶ return 0 if @$arr % 2 == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$arr % 2 == 1 67 149 216
715 149 ▶ for (my $i = 0; $i < @$arr; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$arr) 161 142 303
716 161 ▶ return 0 if is_ref($arr->[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if Ref::Util::XS::is_ref($arr->[$i]) 7 154 161
717 }
718 142 return 1;
719 }
720  
721 sub _is_operand_plain {
722 298 ▶ local $_ = shift;
Subroutine _is_operand_plain: called CC=2 SCAR=6.9
723 298 ▶ return !(is_hashref($_) || is_arrayref($_));
Condition100%3/3
Ref::Util::XS::is_hashref($_) || Ref::Util::XS::is_arrayref($_)
l!l&&r!l&&!r
1719784
MC/DC100%2/2
Ref::Util::XS::is_hashref($_) || Ref::Util::XS::is_arrayref($_)
Ref::Util::XS::is_hashref($_) Ref::Util::XS::is_arrayref($_)
Truth table100%3/3
A || B
A= Ref::Util::XS::is_hashref($_)B= Ref::Util::XS::is_arrayref($_)
ABresult
1X1
011
000
724 }
725  
726 sub _query {
727 # dumper \@_;
728 287 ▶ my $subject = shift;
Subroutine _query: called CC=20 SCAR=30.5
729 287 ▶ my $op = shift // throw 'Must specify a query operator';
Condition33%1/3
shift() // throw("Must specify a query operator")
l!l&&r!l&&!r
28700
MC/DC0%0/2
shift() // throw("Must specify a query operator")
shift() throw("Must specify a query operator")
Truth table33%1/3
A // B
A= shift()B= throw("Must specify a query operator")
ABresult
1X1
011
000
730 287 my $operand = shift;
731  
732 287 ▶ return _query_simple($op, $subject) if defined $subject && !is_ref($op) && ($OPS{$subject} || 2) < 2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $subject and not Ref::Util::XS::is_ref($op) and ($OPS{$subject} || 2) < 2 0 287 287
Condition62%5/8
defined $subject and not Ref::Util::XS::is_ref($op) and ($OPS{$subject} || 2) < 2
!ll&&!rl&&r
1661210
defined $subject and not Ref::Util::XS::is_ref($op)
!ll&&!rl&&r
1660121
$OPS{$subject} || 2
l!l
0121
MC/DC0%0/3
defined $subject and not Ref::Util::XS::is_ref($op) and ($OPS{$subject} || 2) < 2
defined $subject not Ref::Util::XS::is_ref($op) $OPS{$subject}
Truth table50%2/4
A and not(B) and C
A= defined $subjectB= not Ref::Util::XS::is_ref($op)C= $OPS{$subject}
ABCresult
0XX0
10X0
1100
1111
733 287 ▶ return _query_simple($subject, $op, $operand) if _is_operand_plain($operand);
Branch: 1 branch
BranchTrueFalseTotal
if _is_operand_plain($operand) 75 212 287
734 212 ▶ return _query_inverse(_query($subject, '-or', $operand)) if $op eq '-not' || $op eq '-false';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "-not" or $op eq "-false" 2 210 212
Condition66%2/3
$op eq "-not" or $op eq "-false"
l!l&&r!l&&!r
20210
MC/DC50%1/2
$op eq "-not" or $op eq "-false"
$op eq "-not" $op eq "-false"
Truth table66%2/3
A or B
A= $op eq "-not"B= $op eq "-false"
ABresult
1X1
011
000
735 210 ▶ return _query($subject, '-and', [%$operand]) if is_hashref($operand);
Branch: 1 branch
BranchTrueFalseTotal
if Ref::Util::XS::is_hashref($operand) 13 197 210
736  
737 197 my @queries;
738  
739 197 my @atoms = @$operand;
740 197 ▶ while (@atoms) {
Branch: 1 branch
BranchTrueFalseTotal
if (@atoms) 216 162 378
741 216 ▶ if (_looks_like_keypairs(\@atoms)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_looks_like_keypairs(\@atoms)) { } 142 74 216
742 142 my ($atom, $operand) = splice @atoms, 0, 2;
743 142 ▶ if (my $op_type = $OPS{$atom}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $op_type = $OPS{$atom}) { } 67 75 142
elsif (not Ref::Util::XS::is_ref($atom)) { } 75 0 75
744 67 ▶ if ($op_type == 1 && _is_operand_plain($operand)) { # unary
Branch: 1 branch
BranchTrueFalseTotal
if ($op_type == 1 and _is_operand_plain($operand)) { } 9 58 67
Condition100%3/3
$op_type == 1 and _is_operand_plain($operand)
!ll&&!rl&&r
5629
MC/DC100%2/2
$op_type == 1 and _is_operand_plain($operand)
$op_type == 1 _is_operand_plain($operand)
Truth table100%3/3
A and B
A= $op_type == 1B= _is_operand_plain($operand)
ABresult
0X0
100
111
745 9 push @queries, _query_simple($operand, $atom);
746 }
747 else {
748 58 push @queries, _query($subject, $atom, $operand);
749 }
750 }
751 elsif (!is_ref($atom)) {
752 75 push @queries, _query($atom, 'eq', $operand);
753 }
754 }
755 else {
756 74 my $atom = shift @atoms;
757 74 ▶ if ($OPS{$atom}) { # apply new operator over the rest
Branch: 1 branch
BranchTrueFalseTotal
if ($OPS{$atom}) { } 35 39 74
758 35 push @queries, _query($subject, $atom, \@atoms);
759 35 last;
760 }
761 else { # apply original operator over this one
762 39 push @queries, _query($subject, $op, $atom);
763 }
764 }
765 }
766  
767 197 ▶ if (@queries == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (@queries == 1) { } 178 19 197
elsif ($op eq '-and') { } 12 7 19
elsif ($op eq '-or') { } 7 0 7
768 178 return $queries[0];
769 }
770 elsif ($op eq '-and') {
771 12 return _query_all(@queries);
772 }
773 elsif ($op eq '-or') {
774 7 return _query_any(@queries);
775 }
776 0 throw 'Malformed query';
777 }
778  
779 sub _query_simple {
780 84 ▶ my $subject = shift;
Subroutine _query_simple: called CC=14 SCAR=32.3
781 84 ▶ my $op = shift // 'eq';
Condition50%1/2
shift() // "eq"
l!l
840
MC/DC0%0/1
shift() // "eq"
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
782 84 my $operand = shift;
783  
784 # these special operators can also act as simple operators
785 84 ▶ $op = '!!' if $op eq '-true';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "-true" 2 82 84
786 84 ▶ $op = '!' if $op eq '-false';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "-false" 1 83 84
787 84 ▶ $op = '!' if $op eq '-not';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "-not" 0 84 84
788  
789 84 ▶ defined $subject or throw 'Subject is not set in query';
Branch: 1 branch
BranchTrueFalseTotal
defined $subject or throw("Subject is not set in query") 0 84 84
790 84 ▶ $OPS{$op} >= 0 or throw 'Cannot use a non-simple operator in a simple query';
Branch: 1 branch
BranchTrueFalseTotal
$OPS{$op} >= 0 or throw("Cannot use a non-simple operator in a simple query") 0 84 84
791 84 ▶ if (empty($operand)) {
Branch: 1 branch
BranchTrueFalseTotal
if (empty($operand)) 11 73 84
792 11 ▶ if ($OPS{$op} < 2) {
Branch: 3 branches
BranchTrueFalseTotal
if ($OPS{$op} < 2) { } 9 2 11
elsif ($op eq 'eq' or $op eq '==') { } 1 1 2
elsif ($op eq 'ne' or $op eq '!=') { } 1 0 1
793 # no operand needed
794 }
795 # Allow field => undef and field => {'ne' => undef} to do the (arguably) right thing.
796 ▶ elsif ($op eq 'eq' || $op eq '==') {
Condition66%2/3
$op eq "eq" or $op eq "=="
l!l&&r!l&&!r
101
MC/DC50%1/2
$op eq "eq" or $op eq "=="
$op eq "eq" $op eq "=="
Truth table66%2/3
A or B
A= $op eq "eq"B= $op eq "=="
ABresult
1X1
011
000
797 1 $op = '-empty';
798 }
799 ▶ elsif ($op eq 'ne' || $op eq '!=') {
Condition33%1/3
$op eq "ne" or $op eq "!="
l!l&&r!l&&!r
100
MC/DC0%0/2
$op eq "ne" or $op eq "!="
$op eq "ne" $op eq "!="
Truth table33%1/3
A or B
A= $op eq "ne"B= $op eq "!="
ABresult
1X1
011
000
800 1 $op = '-nonempty';
801 }
802 else {
803 0 throw 'Operand is required';
804 }
805 }
806  
807 84 ▶ my $field = sub { blessed $_[0] && $_[0]->can($subject) ? $_[0]->$subject : $_[0]->{$subject} };
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) && $_[0]->can($subject) ? : 56 169 225
Condition66%2/3
builtin::blessed($_[0]) and $_[0]->can($subject)
!ll&&!rl&&r
169056
MC/DC50%1/2
builtin::blessed($_[0]) and $_[0]->can($subject)
builtin::blessed($_[0]) $_[0]->can($subject)
Truth table66%2/3
A and B
A= builtin::blessed($_[0])B= $_[0]->can($subject)
ABresult
0X0
100
111
808  
809 my %map = (
810 79 ▶ 'eq' => sub { local $_ = $field->(@_); defined && $_ eq $operand },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ eq $operand 77 2 79
811 2 ▶ 'ne' => sub { local $_ = $field->(@_); defined && $_ ne $operand },
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ ne $operand 2 0 2
812 0 ▶ 'lt' => sub { local $_ = $field->(@_); defined && $_ lt $operand },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ lt $operand 0 0 0
813 0 ▶ 'gt' => sub { local $_ = $field->(@_); defined && $_ gt $operand },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ gt $operand 0 0 0
814 0 ▶ 'le' => sub { local $_ = $field->(@_); defined && $_ le $operand },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ le $operand 0 0 0
815 0 ▶ 'ge' => sub { local $_ = $field->(@_); defined && $_ ge $operand },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ ge $operand 0 0 0
816 4 ▶ '==' => sub { local $_ = $field->(@_); defined && $_ == $operand },
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ == $operand 4 0 4
817 4 ▶ '!=' => sub { local $_ = $field->(@_); defined && $_ != $operand },
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ != $operand 4 0 4
818 0 ▶ '<' => sub { local $_ = $field->(@_); defined && $_ < $operand },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ < $operand 0 0 0
819 0 ▶ '>' => sub { local $_ = $field->(@_); defined && $_ > $operand },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ > $operand 0 0 0
820 0 ▶ '<=' => sub { local $_ = $field->(@_); defined && $_ <= $operand },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ <= $operand 0 0 0
821 4 ▶ '>=' => sub { local $_ = $field->(@_); defined && $_ >= $operand },
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ >= $operand 4 0 4
822 81 ▶ '=~' => sub { local $_ = $field->(@_); defined && $_ =~ $operand },
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ =~ /$operand/ 81 0 81
823 7 ▶ '!~' => sub { local $_ = $field->(@_); defined && $_ !~ $operand },
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and not $_ =~ /$operand/ 7 0 7
824 11 ▶ '!' => sub { local $_ = $field->(@_); ! $_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
825 9 ▶ '!!' => sub { local $_ = $field->(@_); !!$_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
826 4 ▶ '-defined' => sub { local $_ = $field->(@_); defined $_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
827 4 ▶ '-undef' => sub { local $_ = $field->(@_); !defined $_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
828 8 ▶ '-nonempty' => sub { local $_ = $field->(@_); nonempty $_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
829 8 ▶ '-empty' => sub { local $_ = $field->(@_); empty $_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
830 84 );
831  
832 84 ▶ return $map{$op} // throw "Unexpected operator in query: $op",
Condition33%1/3
$map{$op} // throw("Unexpected operator in query: $op", "subject", $subject, "operator", $op, "operand", $operand)
l!l&&r!l&&!r
8400
MC/DC0%0/2
$map{$op} // throw("Unexpected operator in query: $op", "subject", $subject, "operator", $op, "operand", $operand)
$map{$op} throw("Unexpected operator in query: $op", "subject", $subject, "operator", $op, "operand", $operand)
Truth table33%1/3
A // B
A= $map{$op}B= throw("Unexpected operator in query: $op", "subject", $subject, "operator", $op, "operand", $operand)
ABresult
1X1
011
000
833 subject => $subject,
834 operator => $op,
835 operand => $operand;
836 }
837  
838 sub _query_inverse {
839 2 ▶ my $query = shift;
Subroutine _query_inverse: called CC=1 SCAR=0.0
840 2 ▶ return sub { !$query->(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
841 }
842  
843 sub _query_all {
844 12 ▶ my @queries = @_;
Subroutine _query_all: called CC=1 SCAR=0.0
845 return sub {
846 44 ▶ my $val = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
847 44 ▶ all { $_->($val) } @queries;
Subroutine __ANON__: called CC=1 SCAR=0.0
848 12 };
849 }
850  
851 sub _query_any {
852 7 ▶ my @queries = @_;
Subroutine _query_any: called CC=1 SCAR=0.0
853 return sub {
854 26 ▶ my $val = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
855 26 ▶ any { $_->($val) } @queries;
Subroutine __ANON__: called CC=1 SCAR=0.0
856 7 };
857 }
858  
859 64 1;
860  
861 __END__
« KDBX/Key.pm ↑ Summary KDBX/Loader/V4.pm »