Predicate/ClosurePredicate.pm

filter: Statementstmt 100% 29 / 29 Branchbran 62.5% 5 / 8 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 90.3% 47 / 52 CC 6 SCAR 7.6
CC
6
Cov
90%
description
3.2
closure
3.0
new
2.0
CRAP 2.1
« Predicate/Predicates.pm ↑ Summary Predicate.pm »
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
BranchTrueFalseTotal
unless defined $args{"closure"} 0 77 77
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
BranchTrueFalseTotal
if (defined $closure) 77 285 362
24 77 ▶ confess("${closure} is not a CodeRef; cannot continue") unless ref($closure) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $closure eq "CODE" 0 77 77
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
BranchTrueFalseTotal
if defined $description 77 0 77
33 77 ▶ return $self->{description} || 'unknown';
Condition50%1/2
$self->{'description'} || 'unknown'
l!l
770
MC/DC0%0/1
$self->{'description'} || 'unknown'
$self->{'description'}
Truth table50%1/2
A
A= $self->{'description'}
Aresult
11
00
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__
« Predicate/Predicates.pm ↑ Summary Predicate.pm »