line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Role::Singleton::New; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
## no critic (RequireUseStrict) - Role::Tiny does strict |
4
|
3
|
|
|
3
|
|
38761
|
use Role::Tiny; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
24
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$Role::Singleton::New::VERSION = '0.2'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub turn_new_into_singleton { |
9
|
4
|
|
|
4
|
1
|
2657
|
my ($self) = @_; |
10
|
4
|
|
|
|
|
10
|
my $class = ref($self); |
11
|
4
|
100
|
|
|
|
26
|
die "turn_new_into_singleton() must be called by an object" if !$class; |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
2422
|
no strict 'refs'; ## no critic |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
316
|
|
14
|
|
|
|
|
|
|
|
15
|
3
|
100
|
|
|
|
6
|
die "turn_new_into_singleton() can not be called after turn_new_into_multiton()" if ${ $class . '::_multiton_orig_new' }; |
|
3
|
|
|
|
|
34
|
|
16
|
|
|
|
|
|
|
|
17
|
2
|
100
|
|
|
|
3
|
if ( ${ $class . '::_singleton_orig_new' } ) { |
|
2
|
|
|
|
|
8
|
|
18
|
1
|
|
|
|
|
2
|
${ $class . '::_singleton' } = $self; |
|
1
|
|
|
|
|
4
|
|
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
else { |
21
|
1
|
|
|
|
|
9
|
${ $class . '::_singleton_orig_new' } = \&{ $class . '::new' }; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
22
|
1
|
|
|
|
|
2
|
${ $class . '::_singleton' } = $self; |
|
1
|
|
|
|
|
4
|
|
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
3
|
|
335
|
no warnings 'redefine'; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
421
|
|
25
|
1
|
|
|
|
|
3
|
*{ $class . '::new' } = sub { |
26
|
6
|
|
|
6
|
|
9
|
return ${ $class . '::_singleton' }; |
|
6
|
|
|
|
|
25
|
|
27
|
|
|
|
|
|
|
} |
28
|
1
|
|
|
|
|
4
|
} |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
3
|
return ${ $class . '::_singleton' }; |
|
2
|
|
|
|
|
10
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# around 'new' => sub { |
34
|
|
|
|
|
|
|
# my ( $orig, $self, @args ) = @_; |
35
|
|
|
|
|
|
|
# my $class = ref($self) || $self; |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
# no strict 'refs'; ## no critic |
38
|
|
|
|
|
|
|
# return ${ $class . '::_singleton' } ||= $orig->( $self, @args ); |
39
|
|
|
|
|
|
|
# }; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |