line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Factory::Sub; |
2
|
2
|
|
|
2
|
|
96303
|
use 5.006; use strict; use warnings; |
|
2
|
|
|
2
|
|
16
|
|
|
2
|
|
|
2
|
|
6
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
42
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
45
|
|
3
|
2
|
|
|
2
|
|
643
|
use Import::Into; use Carp qw/croak/; use Coerce::Types::Standard qw//; |
|
2
|
|
|
2
|
|
3690
|
|
|
2
|
|
|
2
|
|
45
|
|
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
78
|
|
|
2
|
|
|
|
|
718
|
|
|
2
|
|
|
|
|
134493
|
|
|
2
|
|
|
|
|
133
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use overload |
7
|
4
|
|
|
4
|
|
2225
|
"&{}" => sub {my $self = shift; sub { $self->call(@_) }}, |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
12
|
|
8
|
2
|
|
|
2
|
|
13
|
fallback => 1; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
12
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub import { |
11
|
2
|
|
|
2
|
|
16
|
my ($pkg, @import) = @_; |
12
|
2
|
100
|
|
|
|
14
|
if (@import) { |
13
|
1
|
|
|
|
|
1
|
my $target = caller; |
14
|
1
|
|
|
|
|
7
|
Coerce::Types::Standard->import::into($target, @import) |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
1
|
|
|
1
|
0
|
67
|
bless { factory => [ ] }, $_[0]; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub add { |
23
|
4
|
|
|
4
|
1
|
2190
|
my ($self, @args) = @_; |
24
|
4
|
|
|
|
|
3
|
push @{ $self->{factory} }, \@args; |
|
4
|
|
|
|
|
29
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub call { |
28
|
4
|
|
|
4
|
1
|
9
|
my ($self, @params) = @_; |
29
|
|
|
|
|
|
|
FACTORY: |
30
|
4
|
|
|
|
|
5
|
for my $factory ( @{ $self->{factory} } ) { |
|
4
|
|
|
|
|
25
|
|
31
|
10
|
100
|
|
|
|
8901
|
if ( scalar @{$factory} - 1 == scalar @params) { |
|
10
|
|
|
|
|
21
|
|
32
|
7
|
|
|
|
|
8
|
my @factory_params = @{clone(\@params)}; |
|
7
|
|
|
|
|
14
|
|
33
|
7
|
|
|
|
|
18
|
for (my $i = 0; $i < scalar @factory_params; $i++) { |
34
|
13
|
100
|
|
|
|
1648
|
eval { $factory_params[$i] = $factory->[$i]->( |
35
|
|
|
|
|
|
|
ref $factory->[$i] eq 'Type::Tiny' |
36
|
13
|
100
|
50
|
|
|
28
|
&& scalar @{$factory->[$i]->{coercion}->{type_coercion_map}} |
37
|
|
|
|
|
|
|
? $factory->[$i]->coerce($factory_params[$i]) |
38
|
|
|
|
|
|
|
: $factory_params[$i] |
39
|
|
|
|
|
|
|
) } or next FACTORY; |
40
|
|
|
|
|
|
|
} |
41
|
4
|
|
|
|
|
583
|
return $factory->[-1]->(@factory_params); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
0
|
croak "No matching factory sub for given params " . join " ", @params; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub clone { |
48
|
37
|
|
|
37
|
0
|
41
|
my ($clone) = @_; |
49
|
37
|
|
|
|
|
37
|
my $ref = ref $clone; |
50
|
37
|
100
|
|
|
|
60
|
if ($ref eq 'ARRAY') { return [ map { clone($_) } @{$clone} ]; } |
|
10
|
100
|
|
|
|
10
|
|
|
24
|
50
|
|
|
|
50
|
|
|
10
|
|
|
|
|
14
|
|
51
|
6
|
|
|
|
|
5
|
elsif ($ref eq 'HASH') { return { map +( $_ => clone($clone->{$_}) ), keys %{$clone} }; } |
|
6
|
|
|
|
|
17
|
|
52
|
0
|
|
|
|
|
0
|
elsif ($ref eq 'SCALAR') { my $r = clone($$clone); return \$r; } |
|
0
|
|
|
|
|
0
|
|
53
|
21
|
|
|
|
|
51
|
return $clone; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__; |