Sub/Meta/Creator.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 14 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 5 / 5 totaltotal 100% 76 / 76 CC 10 SCAR 11.0
CC
10
Cov
100%
new
6.0
find_materials
3.0
__ANON__
2.0
CRAP 3.0
« Sub/Meta/Type.pm ↑ Summary Sub/Meta/Finder/SubWrapInType.pm »
1 package Sub::Meta::Creator;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 our $VERSION = "0.15";
6  
7 6 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Sub::Meta;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶sub _croak { require Carp; goto &Carp::croak }
Subroutine _croak: called CC=1 SCAR=0.0
11  
12 18 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod documented
13 18 my ($class, @args) = @_;
14 18 ▶ my %args = @args == 1 ? %{$args[0]} : @args;
Branch: 1 branch
BranchTrueFalseTotal
@args == 1 ? : 1 17 18
15  
16 18 ▶ unless (exists $args{finders}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args{"finders"}) 1 17 18
17 1 _croak 'required finders';
18 }
19  
20 17 ▶ unless (ref $args{finders} && ref $args{finders} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $args{"finders"} and ref $args{"finders"} eq "ARRAY") 2 15 17
Condition100%3/3
ref $args{"finders"} and ref $args{"finders"} eq "ARRAY"
!ll&&!rl&&r
1115
MC/DC100%2/2
ref $args{"finders"} and ref $args{"finders"} eq "ARRAY"
ref $args{"finders"} ref $args{"finders"} eq "ARRAY"
Truth table100%3/3
A and B
A= ref $args{"finders"}B= ref $args{"finders"} eq "ARRAY"
ABresult
0X0
100
111
21 2 _croak 'finders must be an arrayref'
22 }
23  
24 15 ▶ unless (List::Util::all { ref $_ && ref $_ eq 'CODE' } @{$args{finders}}) {
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 2 branches
BranchTrueFalseTotal
unless (&List::Util::all(sub { ref $_ and ref $_ eq "CODE"; } , @{$args{"finders"};})) 2 13 15
ref $_ and ref $_ eq "CODE" 16 1 17
25 2 _croak 'elements of finders have to be a code reference'
26 }
27  
28 13 return bless \%args => $class;
29 }
30  
31 8 ▶sub sub_meta_class { return 'Sub::Meta' }
Subroutine sub_meta_class: called CC=1 SCAR=0.0
Pod documented
32  
33 15 ▶sub finders { my $self = shift; return $self->{finders} }
Subroutine finders: called CC=1 SCAR=0.0
Pod documented
34  
35 14 ▶sub find_materials {
Subroutine find_materials: called CC=3 SCAR=11.0
Pod documented
36 14 my ($self, $sub) = @_;
37 14 for my $finder (@{$self->finders}) {
38 18 my $materials = $finder->($sub);
39 18 ▶ return $materials if defined $materials;
Branch: 1 branch
BranchTrueFalseTotal
if defined $materials 9 9 18
40 }
41 5 return;
42 }
43  
44 10 ▶sub create {
Subroutine create: called CC=2 SCAR=6.9
Pod documented
45 10 my ($self, $sub) = @_;
46 10 ▶ if (my $materials = $self->find_materials($sub)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $materials = $self->find_materials($sub)) 7 3 10
47 7 return $self->sub_meta_class->new($materials)
48 }
49 3 return;
50 }
51  
52 6 1;
53 __END__
« Sub/Meta/Type.pm ↑ Summary Sub/Meta/Finder/SubWrapInType.pm »