line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package List::Part;
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#Prototypes
|
4
|
2
|
|
|
2
|
|
134763
|
BEGIN { require 5.002 }
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
14
|
use Carp qw(croak);
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
156
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
11
|
use Exporter;
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
140
|
|
9
|
|
|
|
|
|
|
@ISA = qw(Exporter);
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
@EXPORT_OK = qw( parta );
|
12
|
|
|
|
|
|
|
@EXPORT = qw( part );
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = '0.03';
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
22
|
use strict;
|
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
94
|
|
17
|
2
|
|
|
2
|
|
11
|
use warnings;
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
994
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub part(&@) {
|
20
|
6
|
|
|
6
|
1
|
207
|
my $code=shift;
|
21
|
6
|
|
|
|
|
9
|
my @ret;
|
22
|
|
|
|
|
|
|
|
23
|
6
|
|
|
|
|
15
|
for(@_) {
|
24
|
27
|
|
|
|
|
57
|
my $i=$code->($_);
|
25
|
27
|
100
|
|
|
|
108
|
next unless defined $i;
|
26
|
25
|
|
|
|
|
25
|
push @{$ret[$i]}, $_;
|
|
25
|
|
|
|
|
80
|
|
27
|
|
|
|
|
|
|
}
|
28
|
|
|
|
|
|
|
|
29
|
6
|
|
|
|
|
70
|
return @ret;
|
30
|
|
|
|
|
|
|
}
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub parta($@) {
|
33
|
3
|
|
|
3
|
1
|
23
|
my $ary=shift;
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
unshift @_, sub {
|
36
|
15
|
|
|
15
|
|
34
|
for my $i(0..$#$ary) {
|
37
|
32
|
100
|
|
|
|
57
|
return $i if _matches($ary->[$i], $_);
|
38
|
|
|
|
|
|
|
}
|
39
|
1
|
|
|
|
|
3
|
return undef;
|
40
|
3
|
|
|
|
|
22
|
};
|
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
|
|
13
|
goto ∂
|
43
|
|
|
|
|
|
|
}
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _matches {
|
46
|
32
|
|
|
32
|
|
43
|
my($thing, $value)=@_;
|
47
|
|
|
|
|
|
|
|
48
|
32
|
50
|
|
|
|
53
|
if(ref $thing) {
|
49
|
32
|
50
|
|
|
|
111
|
if(ref $thing eq 'ARRAY') {
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
for(@$thing) {
|
51
|
0
|
0
|
|
|
|
0
|
return 1 if _matches($_, $value);
|
52
|
|
|
|
|
|
|
}
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
elsif(ref $thing eq 'HASH') {
|
55
|
0
|
0
|
|
|
|
0
|
return 1 if $thing->{$value};
|
56
|
|
|
|
|
|
|
}
|
57
|
|
|
|
|
|
|
elsif(ref $thing eq 'CODE') {
|
58
|
0
|
0
|
|
|
|
0
|
return 1 if $thing->($value);
|
59
|
|
|
|
|
|
|
}
|
60
|
|
|
|
|
|
|
elsif(ref $thing eq 'Regexp') {
|
61
|
32
|
100
|
|
|
|
163
|
return 1 if $value =~ $thing;
|
62
|
|
|
|
|
|
|
}
|
63
|
|
|
|
|
|
|
else {
|
64
|
0
|
0
|
|
|
|
0
|
return 1 if $thing eq $value;
|
65
|
|
|
|
|
|
|
}
|
66
|
|
|
|
|
|
|
}
|
67
|
|
|
|
|
|
|
else {
|
68
|
0
|
0
|
|
|
|
0
|
return 1 if $thing eq $value;
|
69
|
|
|
|
|
|
|
}
|
70
|
|
|
|
|
|
|
|
71
|
18
|
|
|
|
|
49
|
return 0;
|
72
|
|
|
|
|
|
|
}
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1;
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__
|