blib/lib/List/Part.pm

filter: Statementstmt 86.0% 37 / 43 Branchbran 42.3% 11 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 73.7% 59 / 80 CC 17 SCAR 34.1
CC
17
Cov
70%
_matches
56.6
part
3.0
__ANON__
3.0
CRAP 30.4
↑ Summary
1 package List::Part;
2
3 #Prototypes
4 2 ▶BEGIN { require 5.002 }
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 @ISA = qw(Exporter);
10
11 2 @EXPORT_OK = qw( parta );
12 2 @EXPORT = qw( part );
13
14 2 $VERSION = '0.03';
15
16 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18
19 6 ▶sub part(&@) {
Subroutine part: called CC=3 SCAR=11.0
Pod documented
20 6 my $code=shift;
21 6 my @ret;
22
23 6 for(@_) {
24 27 my $i=$code->($_);
25 27 ▶ next unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 2 25 27
26 25 push @{$ret[$i]}, $_;
27 }
28
29 6 return @ret;
30 }
31
32 3 ▶sub parta($@) {
Subroutine parta: called CC=1 SCAR=0.0
Pod documented
33 3 my $ary=shift;
34
35 15 ▶ unshift @_, sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
36 15 for my $i(0..$#$ary) {
37 32 ▶ return $i if _matches($ary->[$i], $_);
Branch: 1 branch
BranchTrueFalseTotal
if _matches($ary->[$i], $_) 14 18 32
38 }
39 1 return undef;
40 3 };
41
42 3 goto ∂
43 }
44
45 32 ▶sub _matches {
Subroutine _matches: called CC=13 SCAR=40.4
46 32 my($thing, $value)=@_;
47
48 32 ▶ if(ref $thing) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $thing) { } 32 0 32
49 32 ▶ if(ref $thing eq 'ARRAY') {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $thing eq 'ARRAY') { } 0 32 32
elsif (ref $thing eq 'HASH') { } 0 32 32
elsif (ref $thing eq 'CODE') { } 0 32 32
elsif (ref $thing eq 'Regexp') { } 32 0 32
50 0 for(@$thing) {
51 0 ▶ return 1 if _matches($_, $value);
Branch: 1 branch
BranchTrueFalseTotal
if _matches($_, $value) 0 0 0
52 }
53 }
54 elsif(ref $thing eq 'HASH') {
55 0 ▶ return 1 if $thing->{$value};
Branch: 1 branch
BranchTrueFalseTotal
if $thing->{$value} 0 0 0
56 }
57 elsif(ref $thing eq 'CODE') {
58 0 ▶ return 1 if $thing->($value);
Branch: 1 branch
BranchTrueFalseTotal
if &$thing($value) 0 0 0
59 }
60 elsif(ref $thing eq 'Regexp') {
61 32 ▶ return 1 if $value =~ $thing;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /$thing/ 14 18 32
62 }
63 else {
64 0 ▶ return 1 if $thing eq $value;
Branch: 1 branch
BranchTrueFalseTotal
if $thing eq $value 0 0 0
65 }
66 }
67 else {
68 0 ▶ return 1 if $thing eq $value;
Branch: 1 branch
BranchTrueFalseTotal
if $thing eq $value 0 0 0
69 }
70
71 18 return 0;
72 }
73
74 2 1;
75
76 __END__
↑ Summary