line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Role::Multiton::New; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
## no critic (RequireUseStrict) - Role::Tiny does strict |
4
|
3
|
|
|
3
|
|
69294
|
use Role::Tiny; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
22
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$Role::Multiton::New::VERSION = '0.2'; |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
2095
|
use Role::_Multiton (); |
|
3
|
|
|
|
|
22
|
|
|
3
|
|
|
|
|
198
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub turn_new_into_multiton { |
11
|
4
|
|
|
4
|
1
|
3940
|
my ( $self, @args ) = @_; |
12
|
4
|
|
|
|
|
12
|
my $class = ref($self); |
13
|
4
|
100
|
|
|
|
33
|
die "turn_new_into_multiton() must be called by an object" if !$class; |
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
17
|
no strict 'refs'; ## no critic |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
572
|
|
16
|
|
|
|
|
|
|
|
17
|
3
|
100
|
|
|
|
5
|
die "turn_new_into_multiton() can not be called after turn_new_into_singleton()" if ${ $class . '::_singleton_orig_new' }; |
|
3
|
|
|
|
|
28
|
|
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
|
|
11
|
my $arg_key = Role::_Multiton::_get_arg_key( \@args ); |
20
|
2
|
|
|
|
|
9
|
my $multiton_hr = Role::_Multiton::_get_multiton_lookup_hr($self); |
21
|
|
|
|
|
|
|
|
22
|
2
|
100
|
|
|
|
4
|
if ( ${ $class . '::_multiton_orig_new' } ) { |
|
2
|
|
|
|
|
12
|
|
23
|
1
|
|
|
|
|
4
|
$multiton_hr->{$arg_key} = $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
else { |
26
|
1
|
|
|
|
|
2
|
${ $class . '::_multiton_orig_new' } = \&{ $class . '::new' }; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
27
|
1
|
|
|
|
|
4
|
$multiton_hr->{$arg_key} = $self; |
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
3
|
|
17
|
no warnings 'redefine'; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
547
|
|
30
|
1
|
|
|
|
|
5
|
*{ $class . '::new' } = sub { |
31
|
7
|
|
|
7
|
|
60
|
my ( $self, @args ) = @_; |
32
|
7
|
|
|
|
|
27
|
my $arg_key = Role::_Multiton::_get_arg_key( \@args ); |
33
|
7
|
|
|
|
|
23
|
my $multiton_hr = Role::_Multiton::_get_multiton_lookup_hr($self); |
34
|
7
|
|
66
|
|
|
49
|
return $multiton_hr->{$arg_key} ||= ${ $class . '::_multiton_orig_new' }->( $self, @args ); |
|
2
|
|
|
|
|
62
|
|
35
|
|
|
|
|
|
|
} |
36
|
1
|
|
|
|
|
6
|
} |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
40
|
return $multiton_hr->{$arg_key}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# around 'new' => sub { |
42
|
|
|
|
|
|
|
# my ( $orig, $self, @args ) = @_; |
43
|
|
|
|
|
|
|
# |
44
|
|
|
|
|
|
|
# my $arg_key = Role::_Multiton::_get_arg_key( \@args ); |
45
|
|
|
|
|
|
|
# |
46
|
|
|
|
|
|
|
# my $multiton_hr = Role::_Multiton::_get_multiton_lookup_hr($self); |
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
# return $multiton_hr->{$arg_key} ||= $orig->( $self, @args ); |
49
|
|
|
|
|
|
|
# }; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |