| 1 | package Factory::Sub; | ||||||||||||||||||||
| 2 | 2 | ▶ | use 5.006; use strict; use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 2 | ▶ | use Import::Into; use Carp qw/croak/; use Coerce::Types::Standard qw//; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | our $VERSION = '0.03'; | |||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | use overload | ||||||||||||||||||||
| 7 | 4 | ▶ | "&{}" => sub {my $self = shift; sub { $self->call(@_) }}, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 2 | ▶ | fallback => 1; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | sub import { | ||||||||||||||||||||
| 11 | 2 | ▶ | my ($pkg, @import) = @_; | ||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 12 | 2 | ▶ | if (@import) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 13 | 1 | my $target = caller; | |||||||||||||||||||
| 14 | 1 | Coerce::Types::Standard->import::into($target, @import) | |||||||||||||||||||
| 15 | } | ||||||||||||||||||||
| 16 | } | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | sub new { | ||||||||||||||||||||
| 19 | 1 | ▶ | bless { factory => [ ] }, $_[0]; | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | sub add { | ||||||||||||||||||||
| 23 | 4 | ▶ | my ($self, @args) = @_; | ||||||||||||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 24 | 4 | push @{ $self->{factory} }, \@args; | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | sub call { | ||||||||||||||||||||
| 28 | 4 | ▶ | my ($self, @params) = @_; | ||||||||||||||||||
|
Subroutine
call: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||
| 29 | FACTORY: | ||||||||||||||||||||
| 30 | 4 | for my $factory ( @{ $self->{factory} } ) { | |||||||||||||||||||
| 31 | 10 | ▶ | if ( scalar @{$factory} - 1 == scalar @params) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 7 | my @factory_params = @{clone(\@params)}; | |||||||||||||||||||
| 33 | 7 | ▶ | for (my $i = 0; $i < scalar @factory_params; $i++) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 13 | ▶ | eval { $factory_params[$i] = $factory->[$i]->( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | ref $factory->[$i] eq 'Type::Tiny' | ||||||||||||||||||||
| 36 | 13 | ▶ | && scalar @{$factory->[$i]->{coercion}->{type_coercion_map}} | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $factory->[$i] eq "Type::Tiny" and scalar @{$factory->[$i]{"coercion"}{"type_coercion_map"};}
MC/DC0%0/1
ref $factory->[$i] eq "Type::Tiny" and scalar @{$factory->[$i]{"coercion"}{"type_coercion_map"};}
ref $factory->[$i] eq "Type::Tiny"
Truth table50%1/2
A
A= ref $factory->[$i] eq "Type::Tiny"
| |||||||||||||||||||||
| 37 | ? $factory->[$i]->coerce($factory_params[$i]) | ||||||||||||||||||||
| 38 | : $factory_params[$i] | ||||||||||||||||||||
| 39 | ) } or next FACTORY; | ||||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | 4 | return $factory->[-1]->(@factory_params); | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | 0 | croak "No matching factory sub for given params " . join " ", @params; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | sub clone { | ||||||||||||||||||||
| 48 | 37 | ▶ | my ($clone) = @_; | ||||||||||||||||||
|
Subroutine
clone: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||
| 49 | 37 | my $ref = ref $clone; | |||||||||||||||||||
| 50 | 37 | ▶ | if ($ref eq 'ARRAY') { return [ map { clone($_) } @{$clone} ]; } | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 51 | 6 | elsif ($ref eq 'HASH') { return { map +( $_ => clone($clone->{$_}) ), keys %{$clone} }; } | |||||||||||||||||||
| 52 | 0 | elsif ($ref eq 'SCALAR') { my $r = clone($$clone); return \$r; } | |||||||||||||||||||
| 53 | 21 | return $clone; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 2 | 1; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | __END__; | ||||||||||||||||||||