| 1 | package Data::Predicate::ClosurePredicate; | ||||||||||||
| 2 | |||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 7 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 7 | ▶ | use base qw(Data::Predicate); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 77 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 10 | 77 | my ($class, %args) = @_; | |||||||||||
| 11 | |||||||||||||
| 12 | confess('No closure given; cannot create an object without one') | ||||||||||||
| 13 | 77 | ▶ | unless defined $args{closure}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 14 | |||||||||||||
| 15 | 77 | my $self = $class->SUPER::new(); | |||||||||||
| 16 | 77 | $self->closure($args{closure}); | |||||||||||
| 17 | 77 | $self->description($args{description}); | |||||||||||
| 18 | 77 | return $self; | |||||||||||
| 19 | } | ||||||||||||
| 20 | |||||||||||||
| 21 | 362 | ▶ | sub closure { | ||||||||||
|
Subroutine
closure: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 22 | 362 | my ($self, $closure) = @_; | |||||||||||
| 23 | 362 | ▶ | if(defined $closure) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 24 | 77 | ▶ | confess("${closure} is not a CodeRef; cannot continue") unless ref($closure) eq 'CODE'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 25 | 77 | $self->{closure} = $closure; | |||||||||||
| 26 | } | ||||||||||||
| 27 | 362 | return $self->{closure}; | |||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | 77 | ▶ | sub description { | ||||||||||
|
Subroutine
description: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||
| 31 | 77 | my ($self, $description) = @_; | |||||||||||
| 32 | 77 | ▶ | $self->{description} = $description if defined $description; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | 77 | ▶ | return $self->{description} || 'unknown'; | ||||||||||
|
Condition50%1/2
$self->{'description'} || 'unknown'
MC/DC0%0/1
$self->{'description'} || 'unknown'
$self->{'description'}
Truth table50%1/2
A
A= $self->{'description'}
| |||||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | 285 | ▶ | sub apply { | ||||||||||
|
Subroutine
apply: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 37 | 285 | my ($self, $object) = @_; | |||||||||||
| 38 | 285 | return $self->closure()->($object); | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | 7 | 1; | |||||||||||
| 42 | __END__ | ||||||||||||