line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
60575
|
use 5.006; use warnings; use strict; |
|
1
|
|
|
1
|
|
4
|
|
|
1
|
|
|
1
|
|
4
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
56
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Class::Closure; |
4
|
|
|
|
|
|
|
our $VERSION = '0.304'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Exporter (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
13
|
|
8
|
1
|
|
|
1
|
|
490
|
use Symbol (); |
|
1
|
|
|
|
|
746
|
|
|
1
|
|
|
|
|
92
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw( |
11
|
|
|
|
|
|
|
has |
12
|
|
|
|
|
|
|
public |
13
|
|
|
|
|
|
|
method |
14
|
|
|
|
|
|
|
accessor |
15
|
|
|
|
|
|
|
extends |
16
|
|
|
|
|
|
|
does |
17
|
|
|
|
|
|
|
destroy |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $PACKAGE; |
21
|
|
|
|
|
|
|
our $EXTENDS; |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
21
|
sub import { _make_new( scalar caller ); goto &Exporter::import } |
|
2
|
|
|
|
|
2152
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _install ($$) { |
26
|
64
|
|
|
64
|
|
97
|
my ( $name, $thing ) = @_; |
27
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
339
|
|
28
|
64
|
|
|
|
|
77
|
*{ "$PACKAGE\::$name" } = $thing; |
|
64
|
|
|
|
|
317
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _make_new { |
32
|
2
|
|
|
2
|
|
5
|
my ( $pkg ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
3
|
$PACKAGE = $pkg; |
35
|
|
|
|
|
|
|
_install new => sub { |
36
|
6
|
|
33
|
6
|
|
2405
|
my $base = ref $_[0] || $_[0]; |
37
|
6
|
|
|
|
|
15
|
local $PACKAGE = my $package = _make_package(); |
38
|
|
|
|
|
|
|
|
39
|
6
|
|
|
|
|
21
|
_install ISA => [ $base ]; |
40
|
|
|
|
|
|
|
|
41
|
6
|
|
|
|
|
12
|
my ( @reblessed, @subisa, %subobj ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
_install DESTROY => sub { |
44
|
6
|
|
|
6
|
|
628
|
bless $_->[0], $_->[1] for @reblessed; # bless them back into their original class |
45
|
6
|
|
|
|
|
20
|
Symbol::delete_package( $package ); |
46
|
6
|
|
|
|
|
29
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
_install isa => sub { |
49
|
0
|
|
|
0
|
|
0
|
my ( $self, $class ) = @_; |
50
|
0
|
0
|
|
|
|
0
|
do { return 1 if $base->isa( $class ) }; |
|
0
|
|
|
|
|
0
|
|
51
|
0
|
0
|
|
|
|
0
|
do { return 1 if $_->isa( $class ) } for @subisa; |
|
0
|
|
|
|
|
0
|
|
52
|
0
|
|
|
|
|
0
|
return; |
53
|
6
|
|
|
|
|
24
|
}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
local $EXTENDS = sub { |
56
|
4
|
|
|
4
|
|
7
|
my ( $var ) = @_; |
57
|
|
|
|
|
|
|
|
58
|
4
|
50
|
|
|
|
21
|
$var = $var->new if not ref $var; |
59
|
|
|
|
|
|
|
|
60
|
4
|
|
|
|
|
12
|
my $pkg = ref $var; |
61
|
4
|
|
|
|
|
10
|
bless $var, $PACKAGE; # Rebless for virtual behavior |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
9
|
push @reblessed, [ $var, $pkg ]; # bookkeeping for DESTROY |
64
|
|
|
|
|
|
|
|
65
|
4
|
|
|
|
|
5
|
push @subisa, $pkg; |
66
|
4
|
|
|
|
|
9
|
$subobj{ $pkg } = $var; |
67
|
|
|
|
|
|
|
|
68
|
4
|
|
|
|
|
7
|
return; |
69
|
6
|
|
|
|
|
20
|
}; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
_install can => sub { |
72
|
18
|
|
|
18
|
|
34
|
my ( $self, $method ) = @_; |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
1
|
|
7
|
my $code = do { no strict 'refs'; *{ "$package\::$method" }{'CODE'} }; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
116
|
|
|
18
|
|
|
|
|
24
|
|
|
18
|
|
|
|
|
21
|
|
|
18
|
|
|
|
|
62
|
|
75
|
18
|
100
|
|
|
|
55
|
return $code if $code; |
76
|
|
|
|
|
|
|
|
77
|
13
|
|
|
|
|
25
|
for my $pkg ( @subisa ) { |
78
|
6
|
|
|
|
|
10
|
my $obj = $subobj{ $pkg }; |
79
|
6
|
100
|
|
|
|
24
|
$code = $pkg->can( $method ) or next; |
80
|
|
|
|
|
|
|
my $delegate = sub { |
81
|
3
|
|
|
|
|
8
|
splice @_, 0, 1, $obj; |
82
|
3
|
|
|
|
|
9
|
goto &$code; |
83
|
3
|
|
|
|
|
14
|
}; |
84
|
1
|
|
|
1
|
|
5
|
{ no strict 'refs'; *{ "$package\::$method" } = $delegate }; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
156
|
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
9
|
|
85
|
3
|
|
|
|
|
9
|
return $delegate; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
10
|
|
|
|
|
60
|
return; |
89
|
6
|
|
|
|
|
37
|
}; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
_install AUTOLOAD => sub { |
92
|
5
|
|
|
5
|
|
490
|
our $AUTOLOAD =~ s/.*:://; |
93
|
5
|
100
|
|
|
|
14
|
if ( my $code = $_[0]->can( $AUTOLOAD ) ) { |
|
|
100
|
|
|
|
|
|
94
|
3
|
|
|
|
|
8
|
goto &$code; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
elsif ( my $fallback = $_[0]->can( 'FALLBACK' ) ) { |
97
|
1
|
|
|
1
|
|
20
|
no strict 'refs'; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
734
|
|
98
|
1
|
|
|
|
|
3
|
local *{ "$base\::AUTOLOAD" } = \$AUTOLOAD; |
|
1
|
|
|
|
|
7
|
|
99
|
1
|
|
|
|
|
7
|
goto &$fallback; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
else { |
102
|
1
|
|
|
|
|
174
|
Carp::croak "Method $AUTOLOAD not found in class $base"; |
103
|
|
|
|
|
|
|
} |
104
|
6
|
|
|
|
|
25
|
}; |
105
|
|
|
|
|
|
|
|
106
|
6
|
|
|
|
|
37
|
$pkg->can( 'CLASS' )->( @_ ); |
107
|
|
|
|
|
|
|
|
108
|
6
|
|
|
|
|
19
|
my $self = bless {}, $PACKAGE; |
109
|
|
|
|
|
|
|
|
110
|
6
|
100
|
|
|
|
17
|
$self->BUILD( @_[ 1 .. $#_ ] ) if $self->can( 'BUILD' ); |
111
|
|
|
|
|
|
|
|
112
|
6
|
|
|
|
|
37
|
$self; |
113
|
2
|
|
|
|
|
11
|
}; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
{ |
117
|
|
|
|
|
|
|
my $counter = 0; |
118
|
|
|
|
|
|
|
sub _make_package { |
119
|
6
|
|
|
6
|
|
22
|
"Class::Closure::_package_" . $counter++; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _find_name { |
124
|
10
|
|
|
10
|
|
85
|
my ( $var, $code ) = @_; |
125
|
10
|
|
|
|
|
32
|
require PadWalker; |
126
|
10
|
|
|
|
|
15
|
my %names = reverse %{ PadWalker::peek_sub( $code ) }; |
|
10
|
|
|
|
|
95
|
|
127
|
10
|
|
33
|
|
|
37
|
my $name = $names{ $var } || Carp::croak "Couldn't find lexical name for $var"; |
128
|
10
|
|
|
|
|
41
|
$name =~ s/^[\$\@%]//; |
129
|
10
|
|
|
|
|
30
|
$name; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub has (\$) : lvalue { |
133
|
6
|
|
|
6
|
0
|
28
|
my ( $var ) = @_; |
134
|
|
|
|
|
|
|
|
135
|
6
|
|
|
|
|
523
|
require Devel::Caller; |
136
|
6
|
|
|
|
|
2973
|
my $name = _find_name $var, Devel::Caller::caller_cv(1); |
137
|
|
|
|
|
|
|
|
138
|
6
|
|
|
3
|
|
25
|
_install $name, sub { $$var }; |
|
3
|
|
|
|
|
352
|
|
139
|
6
|
|
|
|
|
16
|
$$var; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub public (\$) : lvalue { |
143
|
4
|
|
|
4
|
0
|
18
|
my ( $var ) = @_; |
144
|
|
|
|
|
|
|
|
145
|
4
|
|
|
|
|
14
|
require Devel::Caller; |
146
|
4
|
|
|
|
|
11
|
my $name = _find_name $var, Devel::Caller::caller_cv(1); |
147
|
|
|
|
|
|
|
|
148
|
4
|
|
|
6
|
|
17
|
_install $name, sub : lvalue { $$var }; |
|
6
|
|
|
|
|
31
|
|
149
|
4
|
|
|
|
|
11
|
$$var; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub method ($&) { |
153
|
12
|
|
|
12
|
0
|
63
|
&_install; |
154
|
12
|
|
|
|
|
22
|
return; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub accessor ($@) { |
158
|
4
|
|
|
4
|
0
|
35
|
my ( $name, %arg ) = @_; |
159
|
4
|
50
|
33
|
|
|
22
|
Carp::croak "accessor needs 'get' and 'set' attributes" unless $arg{'get'} && $arg{'set'}; |
160
|
4
|
|
|
|
|
538
|
require Sentinel; |
161
|
|
|
|
|
|
|
_install $name, sub : lvalue { |
162
|
2
|
|
|
2
|
|
6
|
my $self = shift; |
163
|
|
|
|
|
|
|
Sentinel::sentinel( |
164
|
2
|
|
|
|
|
29
|
get => sub { $arg{'get'}->( $self ) }, |
165
|
1
|
|
|
|
|
4
|
set => sub { $arg{'set'}->( $self, @_ ) }, |
166
|
2
|
|
|
|
|
34
|
); |
167
|
4
|
|
|
|
|
937
|
}; |
168
|
4
|
|
|
|
|
9
|
return; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
4
|
|
|
4
|
0
|
19
|
sub extends($) { &$EXTENDS } |
172
|
|
|
|
|
|
|
|
173
|
6
|
|
|
6
|
0
|
41
|
sub destroy(&) { _install DESTROY => \Class::Closure::DestroyDelegate->new( $_[0] ) } |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
package Class::Closure::DestroyDelegate; |
176
|
|
|
|
|
|
|
our $VERSION = '0.304'; |
177
|
|
|
|
|
|
|
|
178
|
6
|
|
|
6
|
|
14
|
sub new { bless $_[1] } |
179
|
6
|
|
|
6
|
|
486
|
sub DESTROY { goto &{$_[0]} } |
|
6
|
|
|
|
|
28
|
|
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
1; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
__END__ |