blib/lib/Manipulator.pm

filter: Statementstmt 84.7% 39 / 46 Branchbran 72.2% 13 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 3 totaltotal 80.5% 62 / 77 SCAR 23.7
CC
10
Cov
81%
__ANON__
6.5
manipulate
5.4
ordered
2.0
CRAP 10.7
↑ Summary
1 package Manipulator;
2 2 ▶use 5.006; use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 our $VERSION = '0.01';
4 2 ▶use overload '&{}' => 'engage';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use base 'Import::Export';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our %EX = (
9 manipulate => [qw/all/],
10 );
11  
12 sub manipulate {
13 my (%args) = (scalar @_ > 1
14 ? @_
15 : ref $_[0] eq 'CODE'
16 ? (code => $_[0])
17 : ref $_[0] eq 'HASH'
18 0 ? %{ $_[0] }
19 2 ▶ : @{ $_[0] }
Subroutine manipulate: called CC=4 SCAR=16.9
Pod undocumented
Branch: 3 branches
BranchTrueFalseTotal
scalar @_ > 1 ? : 1 1 2
ref $_[0] eq 'CODE' ? : 1 0 1
ref $_[0] eq 'HASH' ? : 0 0 0
20 );
21 2 bless \%args, __PACKAGE__;
22 }
23  
24 sub engage {
25 3 ▶ my ($self) = shift;
Subroutine engage: called CC=1 SCAR=0.1
Pod undocumented
26 return sub {
27 3 ▶ my (@params) = @_;
Subroutine __ANON__: called CC=6 SCAR=18.7
28  
29 3 ▶ if (scalar @params == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @params == 1) 0 3 3
30 0 my $hash = shift @params;
31 0 @params = map {($_, $hash->{$_})} sort { $a <=> $b } keys %{$hash};
32 }
33  
34 3 ▶ if (scalar keys %{$self} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$self;} > 1) { } 2 1 3
35 2 ▶ for (my $i = 0; $i < scalar @params; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @params) 4 2 6
36 4 my ($key, $value) = ($params[$i], $params[$i + 1]);
37 4 $params[$i + 1] = $self->{$key}->($value);
38 }
39 } else {
40 1 ▶ for (my $i = 0; $i < scalar @params; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @params) 4 1 5
41 4 $params[$i] = $self->{code}->($params[$i]);
42 }
43 }
44  
45 3 ▶ return wantarray ? @params : {@params};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 1 3
46 3 };
47 }
48  
49 sub ordered {
50 1 ▶ my ($self, @params) = @_;
Subroutine ordered: called CC=2 SCAR=7.0
Pod undocumented
51 1 my @data = $self->(@params);
52 1 my %out; tie %out, 'Tie::IxHash', @data;
53 1 ▶ return wantarray ? %out : \%out;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
54 }
55  
56 2 1;
57  
58 __END__
↑ Summary