| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XAS::Singleton; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use XAS::Class |
|
6
|
1
|
|
|
|
|
7
|
debug => 0, |
|
7
|
|
|
|
|
|
|
version => $VERSION, |
|
8
|
|
|
|
|
|
|
base => 'XAS::Base', |
|
9
|
|
|
|
|
|
|
constants => 'HASH', |
|
10
|
1
|
|
|
1
|
|
2612
|
; |
|
|
1
|
|
|
|
|
3
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
13
|
|
|
|
|
|
|
# Here be the best of cut-and-paste programming. This combines |
|
14
|
|
|
|
|
|
|
# the guts of Class::Singleton with Badger::Base to make singletons! |
|
15
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
18
|
|
|
|
|
|
|
# Public Methods |
|
19
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
|
22
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# already got an object |
|
25
|
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
return $class if ref $class; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# we store the instance in the _instance variable in the $class package. |
|
29
|
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
449
|
no strict 'refs'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
157
|
|
|
31
|
0
|
|
|
|
|
|
my $instance = \${ "$class\::_instance" }; |
|
|
0
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
defined $$instance |
|
34
|
|
|
|
|
|
|
? $$instance |
|
35
|
|
|
|
|
|
|
: ($$instance = $class->_new_instance(@_)); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
40
|
|
|
|
|
|
|
# Private Methods |
|
41
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _new_instance { |
|
44
|
0
|
|
|
0
|
|
|
my $class = shift; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# install warning handling for odd number of parameters when DEBUG enabled |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
local $SIG{__WARN__} = sub { |
|
49
|
0
|
|
|
0
|
|
|
Badger::Utils::odd_params(@_); |
|
50
|
0
|
|
|
|
|
|
} if DEBUG; |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
0
|
0
|
|
|
|
my $args = @_ && ref $_[0] eq HASH ? shift : { @_ }; |
|
53
|
0
|
|
0
|
|
|
|
my $self = bless { }, ref $class || $class; |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$self = $self->init($args); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# be careful to account for object that overload the boolean comparison |
|
58
|
|
|
|
|
|
|
# operator and may return false to a simple truth test. |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
return defined $self |
|
61
|
|
|
|
|
|
|
? $self |
|
62
|
|
|
|
|
|
|
: $self->error("init() method failed\n"); |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |