blib/lib/Factory/Sub.pm

filter: Statementstmt 94.7% 54 / 57 Branchbran 93.7% 15 / 16 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 13 / 13 Podpod 50.0% 2 / 4 totaltotal 91.4% 85 / 93 CC 11 SCAR 12.4
CC
11
Cov
93%
call
7.0
clone
4.1
import
2.0
CRAP 3.5
↑ Summary
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
BranchTrueFalseTotal
if (@import) 1 1 2
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
BranchTrueFalseTotal
if (scalar @{$factory;} - 1 == scalar @params) 7 3 10
32 7 my @factory_params = @{clone(\@params)};
33 7 ▶ for (my $i = 0; $i < scalar @factory_params; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @factory_params) 13 4 17
34 13 ▶ eval { $factory_params[$i] = $factory->[$i]->(
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $factory_params[$i] = $factory->[$i]->(ref $factory->[$i] eq "Type::Tiny" && scalar @{$factory->[$i]{"coercion"}{"type_coercion_map"};} ? $factory->[$i]->coerce($factory_params[$i]) : $factory_params[$i]) } } or next FACTORY 3 10 13
35 ref $factory->[$i] eq 'Type::Tiny'
36 13 ▶ && scalar @{$factory->[$i]->{coercion}->{type_coercion_map}}
Branch: 1 branch
BranchTrueFalseTotal
ref $factory->[$i] eq 'Type::Tiny' && scalar @{$factory->[$i]{'coercion'}{'type_coercion_map'};} ? : 3 10 13
Condition50%1/2
ref $factory->[$i] eq "Type::Tiny" and scalar @{$factory->[$i]{"coercion"}{"type_coercion_map"};}
!ll
013
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"
Aresult
00
11
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
BranchTrueFalseTotal
if ($ref eq 'ARRAY') { } 10 27 37
elsif ($ref eq 'HASH') { } 6 21 27
elsif ($ref eq 'SCALAR') { } 0 21 21
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__;
↑ Summary