Maker/Utils.pm

filter: Statementstmt 100% 35 / 35 Branchbran 95.0% 19 / 20 Conditioncond 100% 10 / 10 MC/DCmcdc 100% 6 / 6 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 98.7% 78 / 79 CC 15 SCAR 19.5
CC
15
Cov
98%
check_args_sopm
10.0
reformat_size
6.0
BEGIN
1.0
CRAP 7.0
« Maker/Command/index.pm ↑ Summary Maker/Command/filetest.pm »
1 package OPM::Maker::Utils;
2 44 $OPM::Maker::Utils::VERSION = '1.17';
3 # ABSTRACT: Utility functions for OPM::Maker
4  
5 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 44 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 44 ▶use File::Find::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 44 our @EXPORT_OK = qw(
13 reformat_size
14 check_args_sopm
15 );
16  
17 32 ▶sub reformat_size {
Subroutine reformat_size: called CC=6 SCAR=17.9
Pod documented
18 32 my ($size) = @_;
19  
20 32 $size =~ m{\A(?<count>[0-9]+)(?<unit>[MmGgKk])?\z};
21  
22 32 ▶ return 0 if !$+{count};
Branch: 1 branch
BranchTrueFalseTotal
unless $+{"count"} 0 32 32
23  
24 32 ▶ my $unit = lc( $+{unit} // 'b' );
Condition100%2/2
$+{"unit"} // "b"
l!l
284
MC/DC100%1/1
$+{"unit"} // "b"
$+{"unit"}
Truth table100%2/2
A
A= $+{"unit"}
Aresult
11
00
25  
26 32 ▶ my $factor =
Branch: 3 branches
BranchTrueFalseTotal
$unit eq 'k' ? : 8 24 32
$unit eq 'm' ? : 10 14 24
$unit eq 'g' ? : 10 4 14
27 $unit eq 'k' ? 1024 :
28 $unit eq 'm' ? 1024 * 1024 :
29 $unit eq 'g' ? 1024 * 1024 * 1024:
30 1;
31 ;
32  
33 32 return $+{count} * $factor;
34 }
35  
36 119 ▶sub check_args_sopm {
Subroutine check_args_sopm: called CC=10 SCAR=23.0
Pod documented
37 119 my ($args, $opm) = @_;
38  
39 119 ▶ return if $args and 'ARRAY' ne ref $args;
Branch: 1 branch
BranchTrueFalseTotal
if $args and "ARRAY" ne ref $args 9 110 119
Condition100%3/3
$args and "ARRAY" ne ref $args
!ll&&!rl&&r
18929
MC/DC100%2/2
$args and "ARRAY" ne ref $args
$args "ARRAY" ne ref $args
Truth table100%3/3
A and B
A= $argsB= "ARRAY" ne ref $args
ABresult
0X0
100
111
40  
41 110 my $sopm = $args->[0];
42  
43 110 ▶ my @suffixes = $opm ? ('*.opm', '*.sopm') : ('*.sopm');
Branch: 1 branch
BranchTrueFalseTotal
$opm ? : 51 59 110
44  
45 110 ▶ if ( !$sopm ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sopm) 43 67 110
46 my @all_sopm = map {
47 43 $_ =~ s{\A\.[/\\]}{};
48 24 $_;
49 } File::Find::Rule->file->name(@suffixes)->maxdepth(1)->in('.');
50  
51 43 ▶ die 'Found more than one .sopm file' if @all_sopm > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @all_sopm > 1 1 42 43
52  
53 42 $sopm = $all_sopm[0];
54 }
55  
56 109 ▶ $sopm //= '';
Condition100%2/2
$sopm //= ""
l!l
8821
MC/DC100%1/1
$sopm //= ""
$sopm
Truth table100%2/2
A
A= $sopm
Aresult
11
00
57  
58 109 ▶ my $re = $opm ? 's?opm' : 'sopm';
Branch: 1 branch
BranchTrueFalseTotal
$opm ? : 51 58 109
59 109 ▶ return if $sopm !~ m{\.$re\z} or !-f $sopm;
Branch: 1 branch
BranchTrueFalseTotal
unless $sopm =~ /\.$re\z/ and -f $sopm 41 68 109
Condition100%3/3
$sopm =~ /\.$re\z/ and -f $sopm
!ll&&!rl&&r
301168
MC/DC100%2/2
$sopm =~ /\.$re\z/ and -f $sopm
$sopm =~ /\.$re\z/ -f $sopm
Truth table100%3/3
A and B
A= $sopm =~ /\.$re\z/B= -f $sopm
ABresult
0X0
100
111
60  
61 68 return $sopm;
62 }
63  
64 44 1;
65  
66 __END__
« Maker/Command/index.pm ↑ Summary Maker/Command/filetest.pm »