| 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
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 32 | ▶ | my $unit = lc( $+{unit} // 'b' ); | ||||||||||||||||||||||||||
|
Condition100%2/2
$+{"unit"} // "b"
MC/DC100%1/1
$+{"unit"} // "b"
$+{"unit"}
Truth table100%2/2
A
A= $+{"unit"}
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 32 | ▶ | my $factor = | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$args and "ARRAY" ne ref $args
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
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 110 | my $sopm = $args->[0]; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 110 | ▶ | my @suffixes = $opm ? ('*.opm', '*.sopm') : ('*.sopm'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 110 | ▶ | if ( !$sopm ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 42 | $sopm = $all_sopm[0]; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 109 | ▶ | $sopm //= ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$sopm //= ""
MC/DC100%1/1
$sopm //= ""
$sopm
Truth table100%2/2
A
A= $sopm
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 109 | ▶ | my $re = $opm ? 's?opm' : 'sopm'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 109 | ▶ | return if $sopm !~ m{\.$re\z} or !-f $sopm; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$sopm =~ /\.$re\z/ and -f $sopm
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
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 68 | return $sopm; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 44 | 1; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||||||||||