| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 49 | 32 | ▶ | if(ref $thing eq 'ARRAY') { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 50 | 0 | for(@$thing) { | |||||||||||||||||||||
| 51 | 0 | ▶ | return 1 if _matches($_, $value); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||
| 54 | elsif(ref $thing eq 'HASH') { | ||||||||||||||||||||||
| 55 | 0 | ▶ | return 1 if $thing->{$value}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||
| 57 | elsif(ref $thing eq 'CODE') { | ||||||||||||||||||||||
| 58 | 0 | ▶ | return 1 if $thing->($value); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||
| 60 | elsif(ref $thing eq 'Regexp') { | ||||||||||||||||||||||
| 61 | 32 | ▶ | return 1 if $value =~ $thing; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||
| 63 | else { | ||||||||||||||||||||||
| 64 | 0 | ▶ | return 1 if $thing eq $value; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||
| 68 | 0 | ▶ | return 1 if $thing eq $value; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||
| 70 | |||||||||||||||||||||||
| 71 | 18 | return 0; | |||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||
| 73 | |||||||||||||||||||||||
| 74 | 2 | 1; | |||||||||||||||||||||
| 75 | |||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||