line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Predicate::ClosurePredicate; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
25
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
158
|
|
4
|
6
|
|
|
6
|
|
28
|
use warnings; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
122
|
|
5
|
6
|
|
|
6
|
|
29
|
use Carp; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
515
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
28
|
use base qw(Data::Predicate); |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
3450
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
71
|
|
|
71
|
1
|
229
|
my ($class, %args) = @_; |
11
|
|
|
|
|
|
|
|
12
|
71
|
50
|
|
|
|
205
|
confess('No closure given; cannot create an object without one') |
13
|
|
|
|
|
|
|
unless defined $args{closure}; |
14
|
|
|
|
|
|
|
|
15
|
71
|
|
|
|
|
389
|
my $self = $class->SUPER::new(); |
16
|
71
|
|
|
|
|
197
|
$self->closure($args{closure}); |
17
|
71
|
|
|
|
|
160
|
$self->description($args{description}); |
18
|
71
|
|
|
|
|
439
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub closure { |
22
|
356
|
|
|
356
|
1
|
468
|
my ($self, $closure) = @_; |
23
|
356
|
100
|
|
|
|
709
|
if(defined $closure) { |
24
|
71
|
50
|
|
|
|
174
|
confess("${closure} is not a CodeRef; cannot continue") unless ref($closure) eq 'CODE'; |
25
|
71
|
|
|
|
|
222
|
$self->{closure} = $closure; |
26
|
|
|
|
|
|
|
} |
27
|
356
|
|
|
|
|
1114
|
return $self->{closure}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub description { |
31
|
71
|
|
|
71
|
1
|
106
|
my ($self, $description) = @_; |
32
|
71
|
50
|
|
|
|
182
|
$self->{description} = $description if defined $description; |
33
|
71
|
|
50
|
|
|
297
|
return $self->{description} || 'unknown'; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub apply { |
37
|
285
|
|
|
285
|
1
|
16414
|
my ($self, $object) = @_; |
38
|
285
|
|
|
|
|
515
|
return $self->closure()->($object); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
__END__ |