File Coverage

blib/lib/OPM/Maker/Utils.pm
Criterion Covered Total %
statement 35 35 100.0
branch 19 20 95.0
condition 10 10 100.0
subroutine 7 7 100.0
pod 2 2 100.0
total 73 74 98.6


line stmt bran cond sub pod time code
1             package OPM::Maker::Utils;
2             $OPM::Maker::Utils::VERSION = '1.16';
3             # ABSTRACT: Utility functions for OPM::Maker
4              
5 44     44   377 use strict;
  44         237  
  44         1654  
6 44     44   267 use warnings;
  44         112  
  44         1516  
7              
8 44     44   368 use Exporter 'import';
  44         93  
  44         1489  
9              
10 44     44   15178 use File::Find::Rule;
  44         247348  
  44         534  
11              
12             our @EXPORT_OK = qw(
13             reformat_size
14             check_args_sopm
15             );
16              
17             sub reformat_size {
18 32     32 1 94 my ($size) = @_;
19              
20 32         196 $size =~ m{\A(?[0-9]+)(?[MmGgKk])?\z};
21              
22 32 50   13   320 return 0 if !$+{count};
  13         8886  
  13         6136  
  13         4408  
23              
24 32   100     205 my $unit = lc( $+{unit} // 'b' );
25              
26 32 100       1230 my $factor =
    100          
    100          
27             $unit eq 'k' ? 1024 :
28             $unit eq 'm' ? 1024 * 1024 :
29             $unit eq 'g' ? 1024 * 1024 * 1024:
30             1;
31             ;
32              
33 32         184 return $+{count} * $factor;
34             }
35              
36             sub check_args_sopm {
37 119     119 1 287 my ($args, $opm) = @_;
38              
39 119 100 100     769 return if $args and 'ARRAY' ne ref $args;
40              
41 110         238 my $sopm = $args->[0];
42              
43 110 100       375 my @suffixes = $opm ? ('*.opm', '*.sopm') : ('*.sopm');
44              
45 110 100       299 if ( !$sopm ) {
46             my @all_sopm = map {
47 43         1503 $_ =~ s{\A\.[/\\]}{};
  24         24377  
48 24         98 $_;
49             } File::Find::Rule->file->name(@suffixes)->maxdepth(1)->in('.');
50              
51 43 100       44340 die 'Found more than one .sopm file' if @all_sopm > 1;
52              
53 42         126 $sopm = $all_sopm[0];
54             }
55              
56 109   100     367 $sopm //= '';
57              
58 109 100       272 my $re = $opm ? 's?opm' : 'sopm';
59 109 100 100     3143 return if $sopm !~ m{\.$re\z} or !-f $sopm;
60              
61 68         482 return $sopm;
62             }
63              
64             1;
65              
66             __END__