line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#line 1 |
2
|
1
|
|
|
1
|
|
6
|
package Spiffy; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
16
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
4
|
use 5.006001; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
409
|
|
6
|
|
|
|
|
|
|
use Carp; |
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
our $VERSION = '0.30'; |
9
|
|
|
|
|
|
|
our @EXPORT = (); |
10
|
|
|
|
|
|
|
our @EXPORT_BASE = qw(field const stub super); |
11
|
|
|
|
|
|
|
our @EXPORT_OK = (@EXPORT_BASE, qw(id WWW XXX YYY ZZZ)); |
12
|
|
|
|
|
|
|
our %EXPORT_TAGS = (XXX => [qw(WWW XXX YYY ZZZ)]); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $stack_frame = 0; |
15
|
|
|
|
|
|
|
my $dump = 'yaml'; |
16
|
|
|
|
|
|
|
my $bases_map = {}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub WWW; sub XXX; sub YYY; sub ZZZ; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# This line is here to convince "autouse" into believing we are autousable. |
21
|
153
|
50
|
33
|
153
|
0
|
1278
|
sub can { |
22
|
|
|
|
|
|
|
($_[1] eq 'import' and caller()->isa('autouse')) |
23
|
|
|
|
|
|
|
? \&Exporter::import # pacify autouse's equality test |
24
|
|
|
|
|
|
|
: $_[0]->SUPER::can($_[1]) # normal case |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# TODO |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
# Exported functions like field and super should be hidden so as not to |
30
|
|
|
|
|
|
|
# be confused with methods that can be inherited. |
31
|
|
|
|
|
|
|
# |
32
|
|
|
|
|
|
|
|
33
|
82
|
|
|
82
|
0
|
97
|
sub new { |
34
|
82
|
|
33
|
|
|
294
|
my $class = shift; |
35
|
82
|
|
|
|
|
190
|
$class = ref($class) || $class; |
36
|
82
|
|
|
|
|
185
|
my $self = bless {}, $class; |
37
|
0
|
|
|
|
|
0
|
while (@_) { |
38
|
0
|
|
|
|
|
0
|
my $method = shift; |
39
|
|
|
|
|
|
|
$self->$method(shift); |
40
|
82
|
|
|
|
|
186
|
} |
41
|
|
|
|
|
|
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $filtered_files = {}; |
45
|
|
|
|
|
|
|
my $filter_dump = 0; |
46
|
|
|
|
|
|
|
my $filter_save = 0; |
47
|
|
|
|
|
|
|
our $filter_result = ''; |
48
|
1
|
|
|
1
|
|
6
|
sub import { |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
49
|
1
|
|
|
1
|
|
4
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1861
|
|
50
|
5
|
|
|
5
|
|
11
|
no warnings; |
51
|
|
|
|
|
|
|
my $self_package = shift; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# XXX Using parse_arguments here might cause confusion, because the |
54
|
|
|
|
|
|
|
# subclass's boolean_arguments and paired_arguments can conflict, causing |
55
|
5
|
|
|
|
|
9
|
# difficult debugging. Consider using something truly local. |
56
|
|
|
|
|
|
|
my ($args, @export_list) = do { |
57
|
5
|
|
|
5
|
|
21
|
local *boolean_arguments = sub { |
58
|
|
|
|
|
|
|
qw( |
59
|
|
|
|
|
|
|
-base -Base -mixin -selfless |
60
|
|
|
|
|
|
|
-XXX -dumper -yaml |
61
|
|
|
|
|
|
|
-filter_dump -filter_save |
62
|
5
|
|
|
|
|
28
|
) |
63
|
5
|
|
|
5
|
|
22
|
}; |
|
5
|
|
|
|
|
10
|
|
64
|
5
|
|
|
|
|
26
|
local *paired_arguments = sub { qw(-package) }; |
65
|
|
|
|
|
|
|
$self_package->parse_arguments(@_); |
66
|
5
|
50
|
|
|
|
19
|
}; |
67
|
|
|
|
|
|
|
return spiffy_mixin_import(scalar(caller(0)), $self_package, @export_list) |
68
|
|
|
|
|
|
|
if $args->{-mixin}; |
69
|
5
|
50
|
|
|
|
17
|
|
70
|
5
|
50
|
|
|
|
15
|
$filter_dump = 1 if $args->{-filter_dump}; |
71
|
5
|
50
|
|
|
|
20
|
$filter_save = 1 if $args->{-filter_save}; |
72
|
5
|
50
|
|
|
|
15
|
$dump = 'yaml' if $args->{-yaml}; |
73
|
|
|
|
|
|
|
$dump = 'dumper' if $args->{-dumper}; |
74
|
5
|
|
|
|
|
19
|
|
75
|
|
|
|
|
|
|
local @EXPORT_BASE = @EXPORT_BASE; |
76
|
5
|
50
|
|
|
|
15
|
|
77
|
0
|
0
|
|
|
|
0
|
if ($args->{-XXX}) { |
|
0
|
|
|
|
|
0
|
|
78
|
|
|
|
|
|
|
push @EXPORT_BASE, @{$EXPORT_TAGS{XXX}} |
79
|
|
|
|
|
|
|
unless grep /^XXX$/, @EXPORT_BASE; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
5
|
100
|
66
|
|
|
50
|
spiffy_filter() |
|
|
|
66
|
|
|
|
|
83
|
|
|
|
|
|
|
if ($args->{-selfless} or $args->{-Base}) and |
84
|
|
|
|
|
|
|
not $filtered_files->{(caller($stack_frame))[1]}++; |
85
|
5
|
|
33
|
|
|
58
|
|
86
|
5
|
100
|
66
|
|
|
28
|
my $caller_package = $args->{-package} || caller($stack_frame); |
|
2
|
|
|
|
|
25
|
|
87
|
|
|
|
|
|
|
push @{"$caller_package\::ISA"}, $self_package |
88
|
|
|
|
|
|
|
if $args->{-Base} or $args->{-base}; |
89
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
14
|
|
90
|
6
|
50
|
|
|
|
44
|
for my $class (@{all_my_bases($self_package)}) { |
91
|
55
|
|
|
|
|
238
|
next unless $class->isa('Spiffy'); |
92
|
55
|
|
|
|
|
47
|
my @export = grep { |
|
6
|
|
|
|
|
40
|
|
93
|
2
|
|
|
|
|
6
|
not defined &{"$caller_package\::$_"}; |
94
|
|
|
|
|
|
|
} ( @{"$class\::EXPORT"}, |
95
|
6
|
100
|
66
|
|
|
10
|
($args->{-Base} or $args->{-base}) |
96
|
|
|
|
|
|
|
? @{"$class\::EXPORT_BASE"} : (), |
97
|
45
|
|
|
|
|
172
|
); |
98
|
45
|
|
|
|
|
51
|
my @export_ok = grep { |
|
6
|
|
|
|
|
21
|
|
99
|
6
|
|
|
|
|
11
|
not defined &{"$caller_package\::$_"}; |
100
|
|
|
|
|
|
|
} @{"$class\::EXPORT_OK"}; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Avoid calling the expensive Exporter::export |
103
|
6
|
|
|
|
|
12
|
# if there is nothing to do (optimization) |
|
88
|
|
|
|
|
159
|
|
104
|
6
|
50
|
|
|
|
25
|
my %exportable = map { ($_, 1) } @export, @export_ok; |
105
|
|
|
|
|
|
|
next unless keys %exportable; |
106
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
19
|
|
107
|
6
|
|
|
|
|
8
|
my @export_save = @{"$class\::EXPORT"}; |
|
6
|
|
|
|
|
19
|
|
108
|
6
|
|
|
|
|
9
|
my @export_ok_save = @{"$class\::EXPORT_OK"}; |
|
6
|
|
|
|
|
26
|
|
109
|
6
|
|
|
|
|
11
|
@{"$class\::EXPORT"} = @export; |
|
6
|
|
|
|
|
20
|
|
110
|
2
|
|
|
|
|
9
|
@{"$class\::EXPORT_OK"} = @export_ok; |
111
|
6
|
|
|
|
|
13
|
my @list = grep { |
112
|
2
|
50
|
|
|
|
9
|
(my $v = $_) =~ s/^[\!\:]//; |
|
0
|
|
|
|
|
0
|
|
113
|
|
|
|
|
|
|
$exportable{$v} or ${"$class\::EXPORT_TAGS"}{$v}; |
114
|
6
|
|
|
|
|
768
|
} @export_list; |
115
|
6
|
|
|
|
|
10
|
Exporter::export($class, $caller_package, @list); |
|
6
|
|
|
|
|
27
|
|
116
|
6
|
|
|
|
|
11
|
@{"$class\::EXPORT"} = @export_save; |
|
6
|
|
|
|
|
979
|
|
117
|
|
|
|
|
|
|
@{"$class\::EXPORT_OK"} = @export_ok_save; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
2
|
|
|
2
|
0
|
1023
|
sub spiffy_filter { |
122
|
2
|
|
|
|
|
1061
|
require Filter::Util::Call; |
123
|
|
|
|
|
|
|
my $done = 0; |
124
|
|
|
|
|
|
|
Filter::Util::Call::filter_add( |
125
|
2
|
50
|
|
2
|
|
7
|
sub { |
126
|
2
|
|
|
|
|
3
|
return 0 if $done; |
127
|
2
|
|
|
|
|
33
|
my ($data, $end) = ('', ''); |
128
|
963
|
50
|
|
|
|
1456
|
while (my $status = Filter::Util::Call::filter_read()) { |
129
|
963
|
100
|
|
|
|
1702
|
return $status if $status < 0; |
130
|
2
|
|
|
|
|
6
|
if (/^__(?:END|DATA)__\r?$/) { |
131
|
2
|
|
|
|
|
5
|
$end = $_; |
132
|
|
|
|
|
|
|
last; |
133
|
961
|
|
|
|
|
1076
|
} |
134
|
961
|
|
|
|
|
2716
|
$data .= $_; |
135
|
|
|
|
|
|
|
$_ = ''; |
136
|
2
|
|
|
|
|
19
|
} |
137
|
2
|
|
|
|
|
4
|
$_ = $data; |
138
|
2
|
|
|
|
|
251
|
my @my_subs; |
139
|
|
|
|
|
|
|
s[^(sub\s+\w+\s+\{)(.*\n)] |
140
|
2
|
|
|
|
|
185
|
[${1}my \$self = shift;$2]gm; |
141
|
|
|
|
|
|
|
s[^(sub\s+\w+)\s*\(\s*\)(\s+\{.*\n)] |
142
|
2
|
|
|
|
|
91
|
[${1}${2}]gm; |
143
|
0
|
|
|
|
|
0
|
s[^my\s+sub\s+(\w+)(\s+\{)(.*)((?s:.*?\n))\}\n] |
|
0
|
|
|
|
|
0
|
|
144
|
2
|
|
|
|
|
4
|
[push @my_subs, $1; "\$$1 = sub$2my \$self = shift;$3$4\};\n"]gem; |
145
|
2
|
50
|
|
|
|
8
|
my $preclare = ''; |
146
|
0
|
|
|
|
|
0
|
if (@my_subs) { |
147
|
0
|
|
|
|
|
0
|
$preclare = join ',', map "\$$_", @my_subs; |
148
|
|
|
|
|
|
|
$preclare = "my($preclare);"; |
149
|
2
|
|
|
|
|
49
|
} |
150
|
2
|
50
|
|
|
|
11
|
$_ = "use strict;use warnings;$preclare${_};1;\n$end"; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
151
|
2
|
50
|
|
|
|
68
|
if ($filter_dump) { print; exit } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
152
|
2
|
|
|
|
|
134
|
if ($filter_save) { $filter_result = $_; $_ = $filter_result; } |
153
|
|
|
|
|
|
|
$done = 1; |
154
|
2
|
|
|
|
|
21
|
} |
155
|
|
|
|
|
|
|
); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
0
|
0
|
0
|
sub base { |
159
|
0
|
|
|
|
|
0
|
push @_, -base; |
160
|
|
|
|
|
|
|
goto &import; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
6
|
|
|
6
|
0
|
8
|
sub all_my_bases { |
164
|
|
|
|
|
|
|
my $class = shift; |
165
|
6
|
100
|
|
|
|
28
|
|
166
|
|
|
|
|
|
|
return $bases_map->{$class} |
167
|
|
|
|
|
|
|
if defined $bases_map->{$class}; |
168
|
2
|
|
|
|
|
4
|
|
169
|
1
|
|
|
1
|
|
7
|
my @bases = ($class); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
257
|
|
170
|
2
|
|
|
|
|
3
|
no strict 'refs'; |
|
2
|
|
|
|
|
8
|
|
171
|
1
|
|
|
|
|
2
|
for my $base_class (@{"${class}::ISA"}) { |
|
1
|
|
|
|
|
4
|
|
172
|
|
|
|
|
|
|
push @bases, @{all_my_bases($base_class)}; |
173
|
2
|
|
|
|
|
5
|
} |
174
|
2
|
|
|
|
|
3
|
my $used = {}; |
|
3
|
|
|
|
|
14
|
|
175
|
|
|
|
|
|
|
$bases_map->{$class} = [grep {not $used->{$_}++} @bases]; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
my %code = ( |
179
|
|
|
|
|
|
|
sub_start => |
180
|
|
|
|
|
|
|
"sub {\n", |
181
|
|
|
|
|
|
|
set_default => |
182
|
|
|
|
|
|
|
" \$_[0]->{%s} = %s\n unless exists \$_[0]->{%s};\n", |
183
|
|
|
|
|
|
|
init => |
184
|
|
|
|
|
|
|
" return \$_[0]->{%s} = do { my \$self = \$_[0]; %s }\n" . |
185
|
|
|
|
|
|
|
" unless \$#_ > 0 or defined \$_[0]->{%s};\n", |
186
|
|
|
|
|
|
|
weak_init => |
187
|
|
|
|
|
|
|
" return do {\n" . |
188
|
|
|
|
|
|
|
" \$_[0]->{%s} = do { my \$self = \$_[0]; %s };\n" . |
189
|
|
|
|
|
|
|
" Scalar::Util::weaken(\$_[0]->{%s}) if ref \$_[0]->{%s};\n" . |
190
|
|
|
|
|
|
|
" \$_[0]->{%s};\n" . |
191
|
|
|
|
|
|
|
" } unless \$#_ > 0 or defined \$_[0]->{%s};\n", |
192
|
|
|
|
|
|
|
return_if_get => |
193
|
|
|
|
|
|
|
" return \$_[0]->{%s} unless \$#_ > 0;\n", |
194
|
|
|
|
|
|
|
set => |
195
|
|
|
|
|
|
|
" \$_[0]->{%s} = \$_[1];\n", |
196
|
|
|
|
|
|
|
weaken => |
197
|
|
|
|
|
|
|
" Scalar::Util::weaken(\$_[0]->{%s}) if ref \$_[0]->{%s};\n", |
198
|
|
|
|
|
|
|
sub_end => |
199
|
|
|
|
|
|
|
" return \$_[0]->{%s};\n}\n", |
200
|
|
|
|
|
|
|
); |
201
|
|
|
|
|
|
|
|
202
|
17
|
|
|
17
|
0
|
62
|
sub field { |
203
|
17
|
|
|
|
|
18
|
my $package = caller; |
204
|
1
|
|
|
1
|
|
6
|
my ($args, @values) = do { |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
399
|
|
205
|
17
|
|
|
17
|
|
61
|
no warnings; |
|
17
|
|
|
|
|
27
|
|
206
|
17
|
|
|
17
|
|
52
|
local *boolean_arguments = sub { (qw(-weak)) }; |
|
17
|
|
|
|
|
33
|
|
207
|
17
|
|
|
|
|
50
|
local *paired_arguments = sub { (qw(-package -init)) }; |
208
|
|
|
|
|
|
|
Spiffy->parse_arguments(@_); |
209
|
17
|
|
|
|
|
33
|
}; |
210
|
17
|
50
|
|
|
|
43
|
my ($field, $default) = @values; |
211
|
17
|
50
|
66
|
|
|
56
|
$package = $args->{-package} if defined $args->{-package}; |
212
|
|
|
|
|
|
|
die "Cannot have a default for a weakened field ($field)" |
213
|
17
|
50
|
|
|
|
17
|
if defined $default && $args->{-weak}; |
|
17
|
|
|
|
|
101
|
|
214
|
17
|
50
|
|
|
|
35
|
return if defined &{"${package}::$field"}; |
215
|
17
|
100
|
100
|
|
|
97
|
require Scalar::Util if $args->{-weak}; |
|
|
100
|
66
|
|
|
|
|
216
|
|
|
|
|
|
|
my $default_string = |
217
|
|
|
|
|
|
|
( ref($default) eq 'ARRAY' and not @$default ) |
218
|
|
|
|
|
|
|
? '[]' |
219
|
|
|
|
|
|
|
: (ref($default) eq 'HASH' and not keys %$default ) |
220
|
|
|
|
|
|
|
? '{}' |
221
|
|
|
|
|
|
|
: default_as_code($default); |
222
|
17
|
|
|
|
|
37
|
|
223
|
17
|
100
|
|
|
|
47
|
my $code = $code{sub_start}; |
224
|
4
|
50
|
|
|
|
12
|
if ($args->{-init}) { |
225
|
4
|
|
|
|
|
17
|
my $fragment = $args->{-weak} ? $code{weak_init} : $code{init}; |
226
|
|
|
|
|
|
|
$code .= sprintf $fragment, $field, $args->{-init}, ($field) x 4; |
227
|
17
|
100
|
|
|
|
49
|
} |
228
|
|
|
|
|
|
|
$code .= sprintf $code{set_default}, $field, $default_string, $field |
229
|
17
|
|
|
|
|
50
|
if defined $default; |
230
|
17
|
|
|
|
|
28
|
$code .= sprintf $code{return_if_get}, $field; |
231
|
17
|
50
|
|
|
|
35
|
$code .= sprintf $code{set}, $field; |
232
|
|
|
|
|
|
|
$code .= sprintf $code{weaken}, $field, $field |
233
|
17
|
|
|
|
|
33
|
if $args->{-weak}; |
234
|
|
|
|
|
|
|
$code .= sprintf $code{sub_end}, $field; |
235
|
17
|
50
|
33
|
1
|
|
1943
|
|
|
1
|
0
|
100
|
|
|
9
|
|
|
1
|
0
|
66
|
|
|
2
|
|
|
1
|
0
|
66
|
|
|
18
|
|
|
0
|
50
|
|
|
|
0
|
|
|
0
|
50
|
|
|
|
0
|
|
|
0
|
100
|
|
|
|
0
|
|
|
0
|
50
|
|
|
|
0
|
|
|
0
|
100
|
|
|
|
0
|
|
|
0
|
100
|
|
|
|
0
|
|
|
0
|
50
|
|
|
|
0
|
|
|
1
|
100
|
|
|
|
7
|
|
|
1
|
100
|
|
|
|
8
|
|
|
0
|
100
|
|
|
|
0
|
|
|
0
|
50
|
|
|
|
0
|
|
|
24
|
50
|
|
|
|
75
|
|
|
24
|
50
|
|
|
|
164
|
|
|
0
|
100
|
|
|
|
0
|
|
|
0
|
50
|
|
|
|
0
|
|
|
24
|
100
|
|
|
|
136
|
|
|
8
|
50
|
|
|
|
22
|
|
|
8
|
0
|
|
|
|
24
|
|
|
24
|
0
|
|
|
|
90
|
|
|
24
|
100
|
|
|
|
139
|
|
|
0
|
50
|
|
|
|
0
|
|
|
0
|
50
|
|
|
|
0
|
|
|
3
|
50
|
|
|
|
19
|
|
|
1
|
50
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
18
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
4
|
|
|
128
|
|
|
|
|
1460
|
|
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
13
|
|
|
72
|
|
|
|
|
182
|
|
|
72
|
|
|
|
|
159
|
|
|
72
|
|
|
|
|
144
|
|
|
1
|
|
|
|
|
11
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
18
|
|
|
25
|
|
|
|
|
86
|
|
|
25
|
|
|
|
|
131
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
10
|
|
|
|
|
53
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
34
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
9
|
|
|
|
|
51
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
|
8
|
|
|
|
|
31
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
19
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
22
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
236
|
17
|
50
|
|
|
|
46
|
my $sub = eval $code; |
237
|
1
|
|
|
1
|
|
5
|
die $@ if $@; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
177
|
|
238
|
17
|
|
|
|
|
13
|
no strict 'refs'; |
|
17
|
|
|
|
|
211
|
|
239
|
17
|
50
|
|
|
|
74
|
*{"${package}::$field"} = $sub; |
240
|
|
|
|
|
|
|
return $code if defined wantarray; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
14
|
|
|
14
|
0
|
1186
|
sub default_as_code { |
244
|
14
|
|
|
|
|
10791
|
require Data::Dumper; |
245
|
14
|
|
|
|
|
37
|
local $Data::Dumper::Sortkeys = 1; |
246
|
14
|
|
|
|
|
700
|
my $code = Data::Dumper::Dumper(shift); |
247
|
14
|
|
|
|
|
38
|
$code =~ s/^\$VAR1 = //; |
248
|
14
|
|
|
|
|
42
|
$code =~ s/;$//; |
249
|
|
|
|
|
|
|
return $code; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
0
|
|
|
0
|
0
|
0
|
sub const { |
253
|
0
|
|
|
|
|
0
|
my $package = caller; |
254
|
1
|
|
|
1
|
|
3
|
my ($args, @values) = do { |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
139
|
|
255
|
0
|
|
|
0
|
|
0
|
no warnings; |
|
0
|
|
|
|
|
0
|
|
256
|
0
|
|
|
|
|
0
|
local *paired_arguments = sub { (qw(-package)) }; |
257
|
|
|
|
|
|
|
Spiffy->parse_arguments(@_); |
258
|
0
|
|
|
|
|
0
|
}; |
259
|
0
|
0
|
|
|
|
0
|
my ($field, $default) = @values; |
260
|
1
|
|
|
1
|
|
6
|
$package = $args->{-package} if defined $args->{-package}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
112
|
|
261
|
0
|
0
|
|
|
|
0
|
no strict 'refs'; |
|
0
|
|
|
|
|
0
|
|
262
|
0
|
|
|
0
|
|
0
|
return if defined &{"${package}::$field"}; |
|
0
|
|
|
|
|
0
|
|
263
|
0
|
|
|
|
|
0
|
*{"${package}::$field"} = sub { $default } |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
0
|
|
|
0
|
0
|
0
|
sub stub { |
267
|
0
|
|
|
|
|
0
|
my $package = caller; |
268
|
1
|
|
|
1
|
|
4
|
my ($args, @values) = do { |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
86
|
|
269
|
0
|
|
|
0
|
|
0
|
no warnings; |
|
0
|
|
|
|
|
0
|
|
270
|
0
|
|
|
|
|
0
|
local *paired_arguments = sub { (qw(-package)) }; |
271
|
|
|
|
|
|
|
Spiffy->parse_arguments(@_); |
272
|
0
|
|
|
|
|
0
|
}; |
273
|
0
|
0
|
|
|
|
0
|
my ($field, $default) = @values; |
274
|
1
|
|
|
1
|
|
4
|
$package = $args->{-package} if defined $args->{-package}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
450
|
|
275
|
0
|
0
|
|
|
|
0
|
no strict 'refs'; |
|
0
|
|
|
|
|
0
|
|
276
|
0
|
|
|
|
|
0
|
return if defined &{"${package}::$field"}; |
277
|
|
|
|
|
|
|
*{"${package}::$field"} = |
278
|
0
|
|
|
0
|
|
0
|
sub { |
279
|
0
|
|
|
|
|
0
|
require Carp; |
280
|
|
|
|
|
|
|
Carp::confess |
281
|
|
|
|
|
|
|
"Method $field in package $package must be subclassed"; |
282
|
0
|
|
|
|
|
0
|
} |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
|
285
|
22
|
|
|
22
|
0
|
34
|
sub parse_arguments { |
286
|
22
|
|
|
|
|
35
|
my $class = shift; |
287
|
22
|
|
|
|
|
59
|
my ($args, @values) = ({}, ()); |
|
62
|
|
|
|
|
148
|
|
288
|
22
|
|
|
|
|
73
|
my %booleans = map { ($_, 1) } $class->boolean_arguments; |
|
39
|
|
|
|
|
86
|
|
289
|
22
|
|
|
|
|
65
|
my %pairs = map { ($_, 1) } $class->paired_arguments; |
290
|
32
|
|
|
|
|
36
|
while (@_) { |
291
|
32
|
100
|
66
|
|
|
247
|
my $elem = shift; |
|
|
100
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
292
|
2
|
50
|
33
|
|
|
14
|
if (defined $elem and defined $booleans{$elem}) { |
293
|
|
|
|
|
|
|
$args->{$elem} = (@_ and $_[0] =~ /^[01]$/) |
294
|
|
|
|
|
|
|
? shift |
295
|
|
|
|
|
|
|
: 1; |
296
|
|
|
|
|
|
|
} |
297
|
4
|
|
|
|
|
15
|
elsif (defined $elem and defined $pairs{$elem} and @_) { |
298
|
|
|
|
|
|
|
$args->{$elem} = shift; |
299
|
|
|
|
|
|
|
} |
300
|
26
|
|
|
|
|
69
|
else { |
301
|
|
|
|
|
|
|
push @values, $elem; |
302
|
|
|
|
|
|
|
} |
303
|
22
|
50
|
|
|
|
224
|
} |
304
|
|
|
|
|
|
|
return wantarray ? ($args, @values) : $args; |
305
|
|
|
|
|
|
|
} |
306
|
0
|
|
|
0
|
0
|
0
|
|
307
|
0
|
|
|
0
|
0
|
0
|
sub boolean_arguments { () } |
308
|
|
|
|
|
|
|
sub paired_arguments { () } |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
# get a unique id for any node |
311
|
0
|
0
|
|
0
|
0
|
0
|
sub id { |
312
|
0
|
0
|
|
|
|
0
|
if (not ref $_[0]) { |
313
|
0
|
0
|
|
|
|
0
|
return 'undef' if not defined $_[0]; |
314
|
0
|
|
|
|
|
0
|
\$_[0] =~ /\((\w+)\)$/o or die; |
315
|
|
|
|
|
|
|
return "$1-S"; |
316
|
0
|
|
|
|
|
0
|
} |
317
|
0
|
0
|
|
|
|
0
|
require overload; |
318
|
0
|
|
|
|
|
0
|
overload::StrVal($_[0]) =~ /\((\w+)\)$/o or die; |
319
|
|
|
|
|
|
|
return $1; |
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
#=============================================================================== |
323
|
|
|
|
|
|
|
# It's super, man. |
324
|
|
|
|
|
|
|
#=============================================================================== |
325
|
|
|
|
|
|
|
package DB; |
326
|
1
|
|
|
1
|
|
5
|
{ |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
236
|
|
327
|
|
|
|
|
|
|
no warnings 'redefine'; |
328
|
0
|
0
|
|
0
|
0
|
0
|
sub super_args { |
329
|
0
|
|
|
|
|
0
|
my @dummy = caller(@_ ? $_[0] : 2); |
330
|
|
|
|
|
|
|
return @DB::args; |
331
|
|
|
|
|
|
|
} |
332
|
|
|
|
|
|
|
} |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
package Spiffy; |
335
|
0
|
|
|
0
|
0
|
0
|
sub super { |
336
|
0
|
|
|
|
|
0
|
my $method; |
337
|
0
|
|
|
|
|
0
|
my $frame = 1; |
338
|
0
|
0
|
|
|
|
0
|
while ($method = (caller($frame++))[3]) { |
339
|
|
|
|
|
|
|
$method =~ s/.*::// and last; |
340
|
0
|
|
|
|
|
0
|
} |
341
|
0
|
0
|
|
|
|
0
|
my @args = DB::super_args($frame); |
342
|
0
|
0
|
|
|
|
0
|
@_ = @_ ? ($args[0], @_) : @args; |
343
|
0
|
|
|
|
|
0
|
my $class = ref $_[0] ? ref $_[0] : $_[0]; |
344
|
0
|
|
|
|
|
0
|
my $caller_class = caller; |
345
|
0
|
0
|
0
|
|
|
0
|
my $seen = 0; |
346
|
0
|
|
|
|
|
0
|
my @super_classes = reverse grep { |
347
|
0
|
|
|
|
|
0
|
($seen or $seen = ($_ eq $caller_class)) ? 0 : 1; |
348
|
0
|
|
|
|
|
0
|
} reverse @{all_my_bases($class)}; |
349
|
1
|
|
|
1
|
|
5
|
for my $super_class (@super_classes) { |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
199
|
|
350
|
0
|
0
|
|
|
|
0
|
no strict 'refs'; |
351
|
0
|
0
|
|
|
|
0
|
next if $super_class eq $class; |
|
0
|
|
|
|
|
0
|
|
352
|
0
|
0
|
|
|
|
0
|
if (defined &{"${super_class}::$method"}) { |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
353
|
|
|
|
|
|
|
${"$super_class\::AUTOLOAD"} = ${"$class\::AUTOLOAD"} |
354
|
0
|
|
|
|
|
0
|
if $method eq 'AUTOLOAD'; |
|
0
|
|
|
|
|
0
|
|
355
|
|
|
|
|
|
|
return &{"${super_class}::$method"}; |
356
|
|
|
|
|
|
|
} |
357
|
0
|
|
|
|
|
0
|
} |
358
|
|
|
|
|
|
|
return; |
359
|
|
|
|
|
|
|
} |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
#=============================================================================== |
362
|
|
|
|
|
|
|
# This code deserves a spanking, because it is being very naughty. |
363
|
|
|
|
|
|
|
# It is exchanging base.pm's import() for its own, so that people |
364
|
|
|
|
|
|
|
# can use base.pm with Spiffy modules, without being the wiser. |
365
|
|
|
|
|
|
|
#=============================================================================== |
366
|
|
|
|
|
|
|
my $real_base_import; |
367
|
|
|
|
|
|
|
my $real_mixin_import; |
368
|
|
|
|
|
|
|
|
369
|
1
|
50
|
|
1
|
|
6
|
BEGIN { |
370
|
1
|
|
50
|
|
|
23
|
require base unless defined $INC{'base.pm'}; |
371
|
1
|
|
|
|
|
2
|
$INC{'mixin.pm'} ||= 'Spiffy/mixin.pm'; |
372
|
1
|
|
|
|
|
3
|
$real_base_import = \&base::import; |
373
|
1
|
|
|
1
|
|
4
|
$real_mixin_import = \&mixin::import; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
49
|
|
374
|
1
|
|
|
|
|
13
|
no warnings; |
375
|
1
|
|
|
|
|
44
|
*base::import = \&spiffy_base_import; |
376
|
|
|
|
|
|
|
*mixin::import = \&spiffy_mixin_import; |
377
|
|
|
|
|
|
|
} |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
# my $i = 0; |
380
|
|
|
|
|
|
|
# while (my $caller = caller($i++)) { |
381
|
|
|
|
|
|
|
# next unless $caller eq 'base' or $caller eq 'mixin'; |
382
|
|
|
|
|
|
|
# croak <
|
383
|
|
|
|
|
|
|
# Spiffy.pm must be loaded before calling 'use base' or 'use mixin' with a |
384
|
|
|
|
|
|
|
# Spiffy module. See the documentation of Spiffy.pm for details. |
385
|
|
|
|
|
|
|
# END |
386
|
|
|
|
|
|
|
# } |
387
|
|
|
|
|
|
|
|
388
|
1
|
|
|
1
|
0
|
94
|
sub spiffy_base_import { |
389
|
1
|
|
|
|
|
2
|
my @base_classes = @_; |
390
|
1
|
|
|
1
|
|
4
|
shift @base_classes; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
310
|
|
391
|
1
|
|
|
|
|
6
|
no strict 'refs'; |
392
|
|
|
|
|
|
|
goto &$real_base_import |
393
|
1
|
50
|
|
|
|
3
|
unless grep { |
|
1
|
50
|
|
|
|
2
|
|
394
|
1
|
|
|
|
|
89
|
eval "require $_" unless %{"$_\::"}; |
395
|
|
|
|
|
|
|
$_->isa('Spiffy'); |
396
|
0
|
|
|
|
|
|
} @base_classes; |
397
|
0
|
|
|
|
|
|
my $inheritor = caller(0); |
398
|
0
|
0
|
|
|
|
|
for my $base_class (@base_classes) { |
399
|
0
|
0
|
|
|
|
|
next if $inheritor->isa($base_class); |
400
|
|
|
|
|
|
|
croak "Can't mix Spiffy and non-Spiffy classes in 'use base'.\n", |
401
|
|
|
|
|
|
|
"See the documentation of Spiffy.pm for details\n " |
402
|
0
|
|
|
|
|
|
unless $base_class->isa('Spiffy'); |
403
|
0
|
|
|
|
|
|
$stack_frame = 1; # tell import to use different caller |
404
|
0
|
|
|
|
|
|
import($base_class, '-base'); |
405
|
|
|
|
|
|
|
$stack_frame = 0; |
406
|
|
|
|
|
|
|
} |
407
|
|
|
|
|
|
|
} |
408
|
|
|
|
|
|
|
|
409
|
0
|
|
|
0
|
0
|
|
sub mixin { |
410
|
0
|
|
|
|
|
|
my $self = shift; |
411
|
0
|
|
|
|
|
|
my $target_class = ref($self); |
412
|
|
|
|
|
|
|
spiffy_mixin_import($target_class, @_) |
413
|
|
|
|
|
|
|
} |
414
|
|
|
|
|
|
|
|
415
|
0
|
|
|
0
|
0
|
|
sub spiffy_mixin_import { |
416
|
0
|
0
|
|
|
|
|
my $target_class = shift; |
417
|
|
|
|
|
|
|
$target_class = caller(0) |
418
|
0
|
0
|
|
|
|
|
if $target_class eq 'mixin'; |
419
|
|
|
|
|
|
|
my $mixin_class = shift |
420
|
0
|
|
|
|
|
|
or die "Nothing to mixin"; |
421
|
0
|
|
|
|
|
|
eval "require $mixin_class"; |
422
|
0
|
|
|
|
|
|
my @roles = @_; |
423
|
0
|
|
|
|
|
|
my $pseudo_class = join '-', $target_class, $mixin_class, @roles; |
424
|
1
|
|
|
1
|
|
5
|
my %methods = spiffy_mixin_methods($mixin_class, @roles); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
425
|
1
|
|
|
1
|
|
4
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
306
|
|
426
|
0
|
|
|
|
|
|
no warnings; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
427
|
0
|
|
|
|
|
|
@{"$pseudo_class\::ISA"} = @{"$target_class\::ISA"}; |
|
0
|
|
|
|
|
|
|
428
|
0
|
|
|
|
|
|
@{"$target_class\::ISA"} = ($pseudo_class); |
429
|
0
|
|
|
|
|
|
for (keys %methods) { |
|
0
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
*{"$pseudo_class\::$_"} = $methods{$_}; |
431
|
|
|
|
|
|
|
} |
432
|
|
|
|
|
|
|
} |
433
|
|
|
|
|
|
|
|
434
|
0
|
|
|
0
|
0
|
|
sub spiffy_mixin_methods { |
435
|
1
|
|
|
1
|
|
5
|
my $mixin_class = shift; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
441
|
|
436
|
0
|
|
|
|
|
|
no strict 'refs'; |
437
|
0
|
|
|
|
|
|
my %methods = spiffy_all_methods($mixin_class); |
438
|
0
|
0
|
|
|
|
|
map { |
439
|
0
|
|
|
|
|
|
$methods{$_} |
440
|
0
|
0
|
|
|
|
|
? ($_, \ &{"$methods{$_}\::$_"}) |
441
|
|
|
|
|
|
|
: ($_, \ &{"$mixin_class\::$_"}) |
442
|
|
|
|
|
|
|
} @_ |
443
|
|
|
|
|
|
|
? (get_roles($mixin_class, @_)) |
444
|
|
|
|
|
|
|
: (keys %methods); |
445
|
|
|
|
|
|
|
} |
446
|
|
|
|
|
|
|
|
447
|
0
|
|
|
0
|
0
|
|
sub get_roles { |
448
|
0
|
|
|
|
|
|
my $mixin_class = shift; |
449
|
0
|
|
|
|
|
|
my @roles = @_; |
450
|
0
|
|
|
|
|
|
while (grep /^!*:/, @roles) { |
451
|
0
|
|
|
|
|
|
@roles = map { |
452
|
|
|
|
|
|
|
s/!!//g; |
453
|
0
|
|
|
|
|
|
/^!:(.*)/ ? do { |
454
|
0
|
|
|
|
|
|
my $m = "_role_$1"; |
455
|
|
|
|
|
|
|
map("!$_", $mixin_class->$m); |
456
|
0
|
0
|
|
|
|
|
} : |
|
|
0
|
|
|
|
|
|
457
|
0
|
|
|
|
|
|
/^:(.*)/ ? do { |
458
|
0
|
|
|
|
|
|
my $m = "_role_$1"; |
459
|
|
|
|
|
|
|
($mixin_class->$m); |
460
|
|
|
|
|
|
|
} : |
461
|
|
|
|
|
|
|
($_) |
462
|
|
|
|
|
|
|
} @roles; |
463
|
0
|
0
|
0
|
|
|
|
} |
464
|
0
|
|
|
|
|
|
if (@roles and $roles[0] =~ /^!/) { |
465
|
0
|
|
|
|
|
|
my %methods = spiffy_all_methods($mixin_class); |
466
|
|
|
|
|
|
|
unshift @roles, keys(%methods); |
467
|
0
|
|
|
|
|
|
} |
468
|
0
|
|
|
|
|
|
my %roles; |
469
|
0
|
|
|
|
|
|
for (@roles) { |
470
|
0
|
0
|
|
|
|
|
s/!!//g; |
471
|
|
|
|
|
|
|
delete $roles{$1}, next |
472
|
0
|
|
|
|
|
|
if /^!(.*)/; |
473
|
|
|
|
|
|
|
$roles{$_} = 1; |
474
|
0
|
|
|
|
|
|
} |
475
|
|
|
|
|
|
|
keys %roles; |
476
|
|
|
|
|
|
|
} |
477
|
|
|
|
|
|
|
|
478
|
1
|
|
|
1
|
|
5
|
sub spiffy_all_methods { |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
190
|
|
479
|
0
|
|
|
0
|
0
|
|
no strict 'refs'; |
480
|
0
|
0
|
|
|
|
|
my $class = shift; |
481
|
0
|
|
|
|
|
|
return if $class eq 'Spiffy'; |
482
|
0
|
|
|
|
|
|
my %methods = map { |
483
|
|
|
|
|
|
|
($_, $class) |
484
|
0
|
0
|
|
|
|
|
} grep { |
|
0
|
|
|
|
|
|
|
485
|
0
|
|
|
|
|
|
defined &{"$class\::$_"} and not /^_/ |
486
|
0
|
|
|
|
|
|
} keys %{"$class\::"}; |
487
|
0
|
|
|
|
|
|
my %super_methods; |
|
0
|
|
|
|
|
|
|
488
|
0
|
0
|
|
|
|
|
%super_methods = spiffy_all_methods(${"$class\::ISA"}[0]) |
489
|
0
|
|
|
|
|
|
if @{"$class\::ISA"}; |
|
0
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
%{{%super_methods, %methods}}; |
491
|
|
|
|
|
|
|
} |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
# END of naughty code. |
495
|
|
|
|
|
|
|
#=============================================================================== |
496
|
|
|
|
|
|
|
# Debugging support |
497
|
|
|
|
|
|
|
#=============================================================================== |
498
|
1
|
|
|
1
|
|
6
|
sub spiffy_dump { |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
317
|
|
499
|
0
|
0
|
|
0
|
0
|
|
no warnings; |
500
|
0
|
|
|
|
|
|
if ($dump eq 'dumper') { |
501
|
0
|
|
|
|
|
|
require Data::Dumper; |
502
|
0
|
|
|
|
|
|
$Data::Dumper::Sortkeys = 1; |
503
|
0
|
|
|
|
|
|
$Data::Dumper::Indent = 1; |
504
|
|
|
|
|
|
|
return Data::Dumper::Dumper(@_); |
505
|
0
|
|
|
|
|
|
} |
506
|
0
|
|
|
|
|
|
require YAML; |
507
|
0
|
|
|
|
|
|
$YAML::UseVersion = 0; |
508
|
|
|
|
|
|
|
return YAML::Dump(@_) . "...\n"; |
509
|
|
|
|
|
|
|
} |
510
|
|
|
|
|
|
|
|
511
|
0
|
|
|
0
|
0
|
|
sub at_line_number { |
512
|
0
|
|
|
|
|
|
my ($file_path, $line_number) = (caller(1))[1,2]; |
513
|
|
|
|
|
|
|
" at $file_path line $line_number\n"; |
514
|
|
|
|
|
|
|
} |
515
|
|
|
|
|
|
|
|
516
|
0
|
|
|
0
|
0
|
|
sub WWW { |
517
|
0
|
0
|
|
|
|
|
warn spiffy_dump(@_) . at_line_number; |
518
|
|
|
|
|
|
|
return wantarray ? @_ : $_[0]; |
519
|
|
|
|
|
|
|
} |
520
|
|
|
|
|
|
|
|
521
|
0
|
|
|
0
|
0
|
|
sub XXX { |
522
|
|
|
|
|
|
|
die spiffy_dump(@_) . at_line_number; |
523
|
|
|
|
|
|
|
} |
524
|
|
|
|
|
|
|
|
525
|
0
|
|
|
0
|
0
|
|
sub YYY { |
526
|
0
|
0
|
|
|
|
|
print spiffy_dump(@_) . at_line_number; |
527
|
|
|
|
|
|
|
return wantarray ? @_ : $_[0]; |
528
|
|
|
|
|
|
|
} |
529
|
|
|
|
|
|
|
|
530
|
0
|
|
|
0
|
0
|
|
sub ZZZ { |
531
|
0
|
|
|
|
|
|
require Carp; |
532
|
|
|
|
|
|
|
Carp::confess spiffy_dump(@_); |
533
|
|
|
|
|
|
|
} |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
1; |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
__END__ |