line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Factory::Sub; |
2
|
2
|
|
|
2
|
|
133720
|
use 5.006; use strict; use warnings; |
|
2
|
|
|
2
|
|
17
|
|
|
2
|
|
|
2
|
|
10
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
62
|
|
3
|
2
|
|
|
2
|
|
929
|
use Import::Into; use Carp qw/croak/; use Coerce::Types::Standard qw//; |
|
2
|
|
|
2
|
|
5320
|
|
|
2
|
|
|
2
|
|
61
|
|
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
94
|
|
|
2
|
|
|
|
|
1047
|
|
|
2
|
|
|
|
|
179934
|
|
|
2
|
|
|
|
|
183
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use overload |
7
|
4
|
|
|
4
|
|
2048
|
"&{}" => sub {my $self = shift; sub { $self->call(@_) }}, |
|
4
|
|
|
|
|
19
|
|
|
4
|
|
|
|
|
15
|
|
8
|
2
|
|
|
2
|
|
19
|
fallback => 1; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
18
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub import { |
11
|
2
|
|
|
2
|
|
23
|
my ($pkg, @import) = @_; |
12
|
2
|
100
|
|
|
|
24
|
if (@import) { |
13
|
1
|
|
|
|
|
3
|
my $target = caller; |
14
|
1
|
|
|
|
|
10
|
Coerce::Types::Standard->import::into($target, @import) |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
1
|
|
|
1
|
0
|
97
|
bless { factory => [ ] }, $_[0]; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub add { |
23
|
4
|
|
|
4
|
1
|
2922
|
my ($self, @args) = @_; |
24
|
4
|
|
|
|
|
7
|
push @{ $self->{factory} }, \@args; |
|
4
|
|
|
|
|
38
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub call { |
28
|
4
|
|
|
4
|
1
|
14
|
my ($self, @params) = @_; |
29
|
|
|
|
|
|
|
FACTORY: |
30
|
4
|
|
|
|
|
6
|
for my $factory ( @{ $self->{factory} } ) { |
|
4
|
|
|
|
|
21
|
|
31
|
10
|
100
|
|
|
|
11193
|
if ( scalar @{$factory} - 1 == scalar @params) { |
|
10
|
|
|
|
|
28
|
|
32
|
7
|
|
|
|
|
8
|
my @factory_params = @{clone(\@params)}; |
|
7
|
|
|
|
|
18
|
|
33
|
7
|
|
|
|
|
24
|
for (my $i = 0; $i < scalar @factory_params; $i++) { |
34
|
13
|
100
|
|
|
|
1770
|
eval { $factory_params[$i] = $factory->[$i]->( |
35
|
|
|
|
|
|
|
ref $factory->[$i] eq 'Type::Tiny' |
36
|
13
|
100
|
50
|
|
|
36
|
&& 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
|
|
|
|
|
858
|
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
|
50
|
my ($clone) = @_; |
49
|
37
|
|
|
|
|
55
|
my $ref = ref $clone; |
50
|
37
|
100
|
|
|
|
78
|
if ($ref eq 'ARRAY') { return [ map { clone($_) } @{$clone} ]; } |
|
10
|
100
|
|
|
|
16
|
|
|
24
|
50
|
|
|
|
53
|
|
|
10
|
|
|
|
|
17
|
|
51
|
6
|
|
|
|
|
9
|
elsif ($ref eq 'HASH') { return { map +( $_ => clone($clone->{$_}) ), keys %{$clone} }; } |
|
6
|
|
|
|
|
21
|
|
52
|
0
|
|
|
|
|
0
|
elsif ($ref eq 'SCALAR') { my $r = clone($$clone); return \$r; } |
|
0
|
|
|
|
|
0
|
|
53
|
21
|
|
|
|
|
66
|
return $clone; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__; |