| 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
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 18 | ▶ | unless (exists $args{finders}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 1 | _croak 'required finders'; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 17 | ▶ | unless (ref $args{finders} && ref $args{finders} eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $args{"finders"} and ref $args{"finders"} eq "ARRAY"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 47 | 7 | return $self->sub_meta_class->new($materials) | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 3 | return; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 6 | 1; | |||||||||||||||||||||||||||
| 53 | __END__ | ||||||||||||||||||||||||||||