blib/lib/Data/SmartMunge.pm

filter: Statementstmt 88.3% 38 / 43 Branchbran 45.0% 9 / 20 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 13 / 13 Podpod 100% 2 / 2 totaltotal 78.5% 66 / 84 CC 13 SCAR 25.6
CC
13
Cov
75%
smart_munge
27.5
delete_matching
3.0
BEGIN
1.0
CRAP 12.9
↑ Summary
1 3 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Data::SmartMunge;
6 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 $Data::SmartMunge::VERSION = '1.101612';
8 }
9  
10 # ABSTRACT: Munge scalars, hashes and arrays in flexible ways
11 3 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 our %EXPORT_TAGS = (util => [qw(smart_munge delete_matching)],);
13 3 our @EXPORT_OK = @{ $EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ] };
14 my %munger_dispatch = (
15 3 ▶ STRING_CODE => sub { $_[1]->($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
16 1 ▶ ARRAY_CODE => sub { $_[1]->($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 1 ▶ HASH_CODE => sub { $_[1]->($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 1 ▶ HASH_HASH => sub { +{ %{ $_[0] }, %{ $_[1] } } }, # overlay
Subroutine __ANON__: called CC=1 SCAR=0.0
19 3 );
20  
21 9 ▶sub smart_munge {
Subroutine smart_munge: called CC=11 SCAR=33.2
Pod documented
22 9 my ($data, $munger) = @_;
23  
24 9 ▶ unless (defined $munger) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $munger) 3 6 9
25 3 ▶ return $data unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 3 0 3
26 0 ▶ return @$data if ref $data eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $data eq "ARRAY" 0 0 0
27 0 ▶ return %$data if ref $data eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $data eq "HASH" 0 0 0
28 }
29  
30 6 ▶ my $data_ref = ref $data || 'STRING';
Condition100%2/2
ref $data || 'STRING'
l!l
33
MC/DC100%1/1
ref $data || 'STRING'
ref $data
Truth table100%2/2
A
A= ref $data
Aresult
11
00
31 6 ▶ my $munger_ref = ref $munger || 'STRING';
Condition50%1/2
ref $munger || 'STRING'
l!l
60
MC/DC0%0/1
ref $munger || 'STRING'
ref $munger
Truth table50%1/2
A
A= ref $munger
Aresult
11
00
32 6 ▶ if (my $handler = $munger_dispatch{ $data_ref . '_' . $munger_ref }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = $munger_dispatch{$data_ref . '_' . $munger_ref}) { } 6 0 6
33 6 my $result = $handler->($data, $munger);
34 6 ▶ return $result unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 6 0 6
35 0 ▶ return @$result if ref $result eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $result eq "ARRAY" 0 0 0
36 0 ▶ return %$result if ref $result eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $result eq "HASH" 0 0 0
37 } else {
38 0 die "can't munge $data_ref with $munger_ref";
39 }
40 }
41  
42 2 ▶sub delete_matching {
Subroutine delete_matching: called CC=3 SCAR=11.0
Pod documented
43 2 my ($re, $flags) = @_;
44 2 ▶ $flags = '' unless defined $flags;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flags 1 1 2
45 return $flags =~ s/g//
46 1 ▶ ? sub { $_[0] =~ s/$re//g; $_[0] }
Subroutine __ANON__: called CC=1 SCAR=0.0
47 2 ▶ : sub { $_[0] =~ s/$re//; $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$flags =~ s/g// ? : 1 1 2
48 }
49  
50  
51 __END__
↑ Summary