line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Predicate; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
22052
|
use strict; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
218
|
|
4
|
7
|
|
|
7
|
|
31
|
use warnings; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
288
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '2.1.1'; |
7
|
7
|
|
|
7
|
|
33
|
use Carp; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
3248
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
71
|
|
|
71
|
1
|
102
|
my ($class) = @_; |
11
|
71
|
|
33
|
|
|
304
|
$class = ref($class) || $class; |
12
|
71
|
|
|
|
|
211
|
my $self = bless({}, $class); |
13
|
71
|
|
|
|
|
193
|
return $self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub apply { |
17
|
0
|
|
|
0
|
1
|
0
|
confess('Not implemented at this level'); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub filter { |
21
|
1
|
|
|
1
|
1
|
25
|
my ($self, $values) = @_; |
22
|
1
|
|
|
|
|
2
|
return [ grep { $self->apply($_) } @{$values}]; |
|
7
|
|
|
|
|
21
|
|
|
1
|
|
|
|
|
4
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub filter_transform { |
26
|
1
|
|
|
1
|
1
|
706
|
my ($self, $values, $transformer) = @_; |
27
|
1
|
|
|
|
|
2
|
my @transformed; |
28
|
1
|
|
|
|
|
2
|
foreach my $value (@{$values}) { |
|
1
|
|
|
|
|
2
|
|
29
|
7
|
100
|
|
|
|
27
|
if($self->apply($value)) { |
30
|
3
|
|
|
|
|
9
|
push(@transformed, $transformer->($value)); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
1
|
|
|
|
|
5
|
return \@transformed; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub all_true { |
37
|
2
|
|
|
2
|
1
|
523
|
my ($self, $objects) = @_; |
38
|
2
|
|
|
|
|
10
|
my $count = $self->_count_truth($objects); |
39
|
2
|
100
|
|
|
|
3
|
return (scalar(@{$objects}) == $count) ? 1 : 0; |
|
2
|
|
|
|
|
15
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub all_false { |
43
|
2
|
|
|
2
|
1
|
5
|
my ($self, $objects) = @_; |
44
|
2
|
|
|
|
|
5
|
my $count = $self->_count_truth($objects); |
45
|
2
|
100
|
|
|
|
20
|
return ($count == 0) ? 1 : 0; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _count_truth { |
49
|
4
|
|
|
4
|
|
6
|
my ($self, $objects) = @_; |
50
|
4
|
|
|
|
|
5
|
my $count = 0; |
51
|
4
|
|
|
|
|
5
|
foreach my $obj (@{$objects}) { |
|
4
|
|
|
|
|
9
|
|
52
|
24
|
100
|
|
|
|
58
|
$count++ if $self->apply($obj); |
53
|
|
|
|
|
|
|
} |
54
|
4
|
|
|
|
|
8
|
return $count; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
__END__ |