Resolver/Utils.pm

filter: Statementstmt 68.1% 30 / 44 Branchbran 12.5% 1 / 8 Conditioncond 50.0% 3 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 76.9% 10 / 13 Podpod 50.0% 3 / 6 totaltotal 60.0% 48 / 80 CC 9 SCAR 15.5
CC
9
Cov
59%
to_boolean
12.0
to_boolean
12.0
_is
3.7
CRAP 4.7
« Resolver.pm ↑ Summary
1 package Config::Resolver::Utils;
2  
3 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 29 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 29 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 29 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 29 our @EXPORT_OK = qw(to_boolean is_hash is_array slurp_file);
11  
12 29 our $VERSION = '1.0.12';
13  
14 29 ▶use parent qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 ########################################################################
17 10 ▶sub slurp_file {
Subroutine slurp_file: called CC=2 SCAR=10.0
Pod undocumented
18 ########################################################################
19 0 ▶ my ($file) = @_;
Subroutine slurp_file: not called CC=2 SCAR=10.0
Pod undocumented
20  
21 0 local $RS = undef;
22  
23 0 ▶ open my $fh, '<', $file
Branch: 2 branches
BranchTrueFalseTotal
open my $fh, "<", $file or croak("ERROR: could not open $file for reading\n$Config::Resolver::Utils::OS_ERROR") 10 0 10
open my $fh, "<", $file or croak("ERROR: could not open $file for reading\n$Config::Resolver::Utils::OS_ERROR") 0 0 0
24 or croak "ERROR: could not open $file for reading\n$OS_ERROR";
25  
26 0 my $content = <$fh>;
27  
28 0 close $fh;
29  
30 0 return $content;
31 }
32  
33 ########################################################################
34 0 ▶sub choose(&) { return $_[0]->(); } ## no critic
Subroutine choose: not called CC=1 SCAR=6.9
Pod undocumented
35 ########################################################################
36 28 ▶sub _is { return ref $_[0] && ( reftype( $_[0] ) eq $_[1] || ref $_[0] eq $_[1] ); }
Subroutine _is: called CC=3 SCAR=13.1
Condition50%3/6
ref $_[0] && (builtin::reftype($_[0]) eq $_[1] || ref $_[0] eq $_[1])
!ll&&!rl&&r
2206
builtin::reftype($_[0]) eq $_[1] or ref $_[0] eq $_[1]
l!l&&r!l&&!r
600
MC/DC33%1/3
ref $_[0] && (builtin::reftype($_[0]) eq $_[1] || ref $_[0] eq $_[1])
ref $_[0] builtin::reftype($_[0]) eq $_[1] ref $_[0] eq $_[1]
Truth table50%2/4
A && B or C
A= ref $_[0]B= builtin::reftype($_[0]) eq $_[1]C= ref $_[0] eq $_[1]
ABCresult
0XX0
1000
11X1
1011
37 ########################################################################
38 17 ▶sub is_hash { return _is( @_, 'HASH' ); }
Subroutine is_hash: called CC=1 SCAR=0.0
Pod documented
39 ########################################################################
40 11 ▶sub is_array { return _is( @_, 'ARRAY' ); }
Subroutine is_array: called CC=1 SCAR=0.0
Pod documented
41 ########################################################################
42  
43 ########################################################################
44 0 ▶sub to_boolean {
Subroutine to_boolean: not called CC=3 SCAR=24.8
Pod documented
45 ########################################################################
46 0 my ($val) = @_;
47  
48 # undefined may trigger defaults, so return
49 return
50 0 ▶ if !defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
51  
52 0 $val =~ s/^\s+|\s+$//xsmg;
53  
54 0 $val = lc $val;
55  
56 0 my %booleans = (
57 true => 1,
58 false => 0,
59 yes => 1,
60 no => 0,
61 on => 1,
62 off => 0,
63 '0' => 0,
64 '1' => 1,
65 );
66  
67 croak "ERROR: unknown boolean: $val: valid values [yes,no,true,false,off,on,0,1]\n"
68 0 ▶ if !exists $booleans{$val};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $booleans{$val} 0 0 0
69  
70 0 return $booleans{$val};
71 }
72  
73 29 1;
74  
75 __END__
« Resolver.pm ↑ Summary