line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::SingletonProxy; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
22300
|
use 5.008; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
35
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
237
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our %target; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import { |
13
|
1
|
|
|
1
|
|
15
|
my $class = shift; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
0
|
0
|
|
sub new { Carp::croak "new called on a singleton class" } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub singleton { |
19
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
20
|
0
|
0
|
|
|
|
|
@_ ? $target{$class} = shift : $target{$class} |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub SINGLETON { |
24
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
25
|
0
|
|
|
|
|
|
Carp::croak("SINGLETON subroutine not defined in class $class"); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $AUTOLOAD; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub AUTOLOAD { |
31
|
0
|
|
|
0
|
|
|
my $class = $_[0]; |
32
|
0
|
|
|
|
|
|
my ($method) = $AUTOLOAD =~ /([^:]*)$/; |
33
|
|
|
|
|
|
|
# print "autoloading ${class} -> ${method} ($AUTOLOAD)\n"; |
34
|
1
|
|
|
1
|
|
4
|
no strict 'refs'; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
109
|
|
35
|
0
|
|
|
|
|
|
*{$AUTOLOAD} = |
36
|
|
|
|
|
|
|
sub { |
37
|
0
|
|
|
0
|
|
|
my $class = shift; |
38
|
|
|
|
|
|
|
# print "class=$class target=$target{$class}\n"; |
39
|
0
|
|
0
|
|
|
|
my $self = $target{$class} ||= |
|
|
|
0
|
|
|
|
|
40
|
|
|
|
|
|
|
( $class->SINGLETON or Carp::croak "$class->SINGLETON returned undef" ); |
41
|
0
|
|
|
|
|
|
$self->$method(@_) |
42
|
0
|
|
|
|
|
|
}; |
43
|
0
|
|
|
|
|
|
goto &{$AUTOLOAD}; |
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
__END__ |