line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
59
|
|
3
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
77
|
|
4
|
|
|
|
|
|
|
{ |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package OOP::Perlish::Class::Singleton; |
7
|
2
|
|
|
2
|
|
1632
|
use OOP::Perlish::Class; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
15
|
|
8
|
2
|
|
|
2
|
|
15
|
use Scalar::Util qw(blessed); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
156
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
12
|
use base qw(OOP::Perlish::Class); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
429
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _magic_constructor_arg_handler_singleton(@) |
13
|
|
|
|
|
|
|
{ |
14
|
6
|
|
|
6
|
|
10
|
my ( $self, $opts ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
6
|
|
|
|
|
9
|
my $key = 'return'; |
17
|
6
|
|
|
|
|
9
|
my $singleton; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
### Handle some magical arguments used for internal purposes |
20
|
6
|
100
|
|
|
|
20
|
if( !exists( $opts->{_____oop_perlish_class__initialize_singleton} ) ) { |
21
|
4
|
|
|
|
|
5
|
$singleton = $self->_singleton( %{$opts} ); |
|
4
|
|
|
|
|
20
|
|
22
|
4
|
|
|
|
|
20
|
return ( $key, [$singleton] ); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
else { |
25
|
2
|
|
|
|
|
8
|
delete( $opts->{_____oop_perlish_class__initialize_singleton} ); |
26
|
|
|
|
|
|
|
} |
27
|
2
|
|
|
|
|
7
|
return; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _singleton(@) |
32
|
|
|
|
|
|
|
{ |
33
|
0
|
|
|
0
|
|
|
my ($proto, %opts) = @_; |
34
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
2
|
|
11
|
no strict 'refs'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
98
|
|
37
|
0
|
|
|
|
|
|
my $singleton = ${ $class . '::_SINGLETONREF' }; |
|
0
|
|
|
|
|
|
|
38
|
2
|
|
|
2
|
|
10
|
use strict 'refs'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
155
|
|
39
|
0
|
0
|
0
|
|
|
|
if( defined($singleton) && ref($singleton) && blessed($singleton) ) { |
|
|
|
0
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
$singleton->debug( 'Singleton of ' . $class . ' already initialized; NOT reinitialized!!' ) if( scalar keys %opts ); |
41
|
0
|
|
|
|
|
|
return $singleton; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
0
|
|
|
|
|
|
$singleton = $class->new( %opts, _____oop_perlish_class__initialize_singleton => 1 ); |
45
|
2
|
|
|
2
|
|
10
|
no strict 'refs'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
84
|
|
46
|
0
|
|
|
|
|
|
${ $class . '::_SINGLETONREF' } = $singleton; |
|
0
|
|
|
|
|
|
|
47
|
2
|
|
|
2
|
|
10
|
use strict 'refs'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
131
|
|
48
|
0
|
|
|
|
|
|
return $singleton; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |