InputMonster/Util.pm

filter: Statementstmt 90.0% 27 / 30 Branchbran 77.7% 14 / 18 Conditioncond 66.6% 6 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 80.0% 56 / 70 CC 14 SCAR 19.1
CC
14
Cov
82%
__ANON__
10.3
dig
5.3
__ANON__
2.0
CRAP 6.8
« InputMonster.pm ↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Data::InputMonster::Util 0.011;
4 # ABSTRACT: handy routines for use with the input monster
5 1 ▶use Sub::Exporter::Util qw(curry_method);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 exports => {
9 dig => curry_method,
10 },
11 1 };
12  
13 #pod =head1 DESCRIPTION
14 #pod
15 #pod These methods, which provide some helpers for use with InputMonster, can be
16 #pod exported as routines upon request.
17 #pod
18 #pod =cut
19  
20 #pod =method dig
21 #pod
22 #pod my $source = dig( [ $key1, $key2, $key2 ]);
23 #pod my $source = dig( sub { ... } );
24 #pod
25 #pod A C<dig> source looks through the input using the given locator. If it's a
26 #pod coderef, the code is called and passed the input. If it's an arrayref, each
27 #pod entry is used, in turn, to subscript the input as a deep data structure. If
28 #pod it's a plain scalar, it's treated like a one-element arrayref would have been.
29 #pod
30 #pod For example, given:
31 #pod
32 #pod $input = [ { ... }, { ... }, { foo => [ { bar => 13, baz => undef } ] } ];
33 #pod $source = dig( [ qw( 2 foo 0 bar ) ] );
34 #pod
35 #pod The source would find 13.
36 #pod
37 #pod =cut
38  
39 5 ▶sub dig {
Subroutine dig: called CC=5 SCAR=16.7
Pod documented
40 5 my ($self, $locator) = @_;
41
42 5 ▶ Carp::confess("no locator given") unless defined $locator;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $locator 0 5 5
43  
44 5 ▶ $locator = [ $locator ] unless ref $locator;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $locator 1 4 5
45  
46 5 ▶ if (ref $locator eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $locator eq 'CODE') { } 0 5 5
elsif (ref $locator eq 'ARRAY') { } 5 0 5
47 0 ▶ return sub { $locator->($_[1]) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 } elsif (ref $locator eq 'ARRAY') {
49 5 ▶ return sub {
Subroutine __ANON__: called CC=10 SCAR=23.3
50 5 my ($monster, $input) = @_;
51 5 my $next = $input;
52  
53 5 for my $k (@$locator) {
54 14 ▶ return unless my $ref = ref $next;
Branch: 1 branch
BranchTrueFalseTotal
unless my $ref = ref $next 1 13 14
55 13 ▶ return unless $ref and (($ref eq 'ARRAY') or ($ref eq 'HASH'));
Branch: 1 branch
BranchTrueFalseTotal
unless $ref and $ref eq "ARRAY" || $ref eq "HASH" 0 13 13
Condition50%3/6
$ref and $ref eq "ARRAY" || $ref eq "HASH"
!ll&&!rl&&r
0013
$ref eq "ARRAY" or $ref eq "HASH"
l!l&&r!l&&!r
850
MC/DC0%0/3
$ref and $ref eq "ARRAY" || $ref eq "HASH"
$ref $ref eq "ARRAY" $ref eq "HASH"
Truth table50%2/4
A and B or C
A= $refB= $ref eq "ARRAY"C= $ref eq "HASH"
ABCresult
0XX0
1000
11X1
1011
56  
57 13 ▶ return if $ref eq 'ARRAY' and $k !~ /\A-?\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "ARRAY" and not $k =~ /\A-?\d+\z/ 1 12 13
Condition100%3/3
$ref eq "ARRAY" and not $k =~ /\A-?\d+\z/
!ll&&!rl&&r
571
MC/DC100%2/2
$ref eq "ARRAY" and not $k =~ /\A-?\d+\z/
$ref eq "ARRAY" not $k =~ /\A-?\d+\z/
Truth table100%3/3
A and not(B)
A= $ref eq "ARRAY"B= not $k =~ /\A-?\d+\z/
ABresult
0X0
100
111
58 12 ▶ $next = $next->[ $k ] if $ref eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "ARRAY" 7 5 12
59 12 ▶ $next = $next->{ $k } if $ref eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "HASH" 5 7 12
60 }
61  
62 3 return $next;
63 5 };
64 }
65  
66 0 Carp::confess("locator must be either a code or array reference");
67 }
68  
69 1 'hi, domm!';
70  
71 __END__
« InputMonster.pm ↑ Summary