blib/lib/List/Extract.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 18 | 18 | 100.0 |
branch | 2 | 2 | 100.0 |
condition | n/a | ||
subroutine | 4 | 4 | 100.0 |
pod | 1 | 1 | 100.0 |
total | 25 | 25 | 100.0 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package List::Extract; | ||||||
2 | 4 | 4 | 67049 | use 5.006001; | |||
4 | 15 | ||||||
4 | 204 | ||||||
3 | |||||||
4 | $VERSION = 0.03; | ||||||
5 | |||||||
6 | 4 | 4 | 22 | use Exporter; | |||
4 | 9 | ||||||
4 | 358 | ||||||
7 | @ISA = Exporter::; | ||||||
8 | @EXPORT_OK = qw/ extract /; | ||||||
9 | $EXPORT_TAGS{ALL} = \@EXPORT_OK; | ||||||
10 | |||||||
11 | 4 | 4 | 32 | use strict; | |||
4 | 8 | ||||||
4 | 675 | ||||||
12 | |||||||
13 | sub extract (&\@) { | ||||||
14 | 8 | 8 | 1 | 8877 | my ($code, $array) = @_; | ||
15 | |||||||
16 | 8 | 13 | my (@keep, @extracted); | ||||
17 | 8 | 16 | for my $orig (@$array) { | ||||
18 | 38 | 46 | local $_ = $orig; | ||||
19 | 38 | 100 | 73 | if ($code->()) { | |||
20 | 25 | 103 | push @extracted, $_; | ||||
21 | } | ||||||
22 | else { | ||||||
23 | 13 | 59 | push @keep, $orig; | ||||
24 | } | ||||||
25 | } | ||||||
26 | 8 | 25 | @$array = @keep; | ||||
27 | |||||||
28 | 8 | 29 | return @extracted; | ||||
29 | } | ||||||
30 | |||||||
31 | 1; | ||||||
32 | |||||||
33 | __END__ |