line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: perl; coding: utf-8 -*- |
2
|
|
|
|
|
|
|
package YATT::Fields; |
3
|
12
|
|
|
12
|
|
59
|
use strict; |
|
12
|
|
|
|
|
50
|
|
|
12
|
|
|
|
|
351
|
|
4
|
12
|
|
|
12
|
|
60
|
use warnings qw(FATAL all NONFATAL misc); |
|
12
|
|
|
|
|
22
|
|
|
12
|
|
|
|
|
521
|
|
5
|
12
|
|
|
12
|
|
69
|
use YATT::Util::Symbol; |
|
12
|
|
|
|
|
44
|
|
|
12
|
|
|
|
|
7078
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub import { |
8
|
166
|
|
|
166
|
|
712
|
require fields; |
9
|
166
|
|
|
|
|
313
|
my ($thispack) = shift; |
10
|
166
|
|
|
|
|
484
|
my ($callpack) = caller; |
11
|
166
|
|
|
|
|
297
|
my @public; |
12
|
|
|
|
|
|
|
my @setter; |
13
|
0
|
|
|
|
|
0
|
my @FIELDS; |
14
|
166
|
|
|
|
|
447
|
foreach my $desc (@_) { |
15
|
1149
|
|
|
|
|
1316
|
my ($slot, $default); |
16
|
1149
|
100
|
|
|
|
2035
|
if (ref $desc) { |
17
|
93
|
|
|
|
|
195
|
$slot = shift @$desc; |
18
|
93
|
|
|
|
|
136
|
$default = do { |
19
|
93
|
100
|
|
|
|
483
|
if (@$desc > 1) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
20
|
11
|
50
|
|
185
|
|
47
|
sub { wantarray ? @$desc : [@$desc]; }; |
|
185
|
|
|
|
|
1323
|
|
21
|
|
|
|
|
|
|
} elsif (! @$desc) { |
22
|
0
|
|
|
|
|
0
|
undef; |
23
|
|
|
|
|
|
|
} elsif (ref(my $value = $desc->[0]) eq 'CODE') { |
24
|
10
|
|
|
|
|
31
|
$value; |
25
|
|
|
|
|
|
|
} else { |
26
|
0
|
|
|
0
|
|
0
|
sub () { $value; } |
27
|
72
|
|
|
|
|
614
|
} |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
} else { |
30
|
1056
|
|
|
|
|
1373
|
$slot = $desc; |
31
|
|
|
|
|
|
|
} |
32
|
1149
|
100
|
|
|
|
3379
|
if ($slot =~ s/^([\^=]+)((?:cf_)?)//) { |
33
|
222
|
|
|
|
|
339
|
my $func_name = $slot; |
34
|
222
|
|
|
|
|
554
|
my $cf_slot = "$2$slot"; |
35
|
222
|
|
|
|
|
629
|
foreach my $ch (split //, $1) { |
36
|
249
|
100
|
|
|
|
1201
|
push @public, [$func_name, $cf_slot] if $ch eq '^'; |
37
|
249
|
100
|
|
|
|
740
|
push @setter, [$func_name, $cf_slot] if $ch eq '='; |
38
|
|
|
|
|
|
|
} |
39
|
222
|
|
|
|
|
466
|
push @FIELDS, $cf_slot; |
40
|
|
|
|
|
|
|
} else { |
41
|
927
|
|
|
|
|
1461
|
push @FIELDS, $slot; |
42
|
|
|
|
|
|
|
} |
43
|
1149
|
100
|
|
|
|
2797
|
if (defined $default) { |
44
|
93
|
|
|
|
|
133
|
*{globref($callpack, "default_$slot")} = $default; |
|
93
|
|
|
|
|
401
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
166
|
|
|
|
|
697
|
my $script = <
|
49
|
|
|
|
|
|
|
package $callpack; |
50
|
|
|
|
|
|
|
use fields qw(@FIELDS); |
51
|
|
|
|
|
|
|
sub MY () {__PACKAGE__} |
52
|
|
|
|
|
|
|
END |
53
|
|
|
|
|
|
|
|
54
|
166
|
|
|
|
|
313
|
$script .= join "", map {sprintf <<'END', @$_} @public; |
|
222
|
|
|
|
|
1319
|
|
55
|
|
|
|
|
|
|
sub %1$s { |
56
|
|
|
|
|
|
|
my MY $self = shift; |
57
|
|
|
|
|
|
|
return $self->{%2$s} if defined $self->{%2$s}; |
58
|
|
|
|
|
|
|
return undef unless my $sub = $self->can('default_%1$s'); |
59
|
|
|
|
|
|
|
$self->{%2$s} = $sub->(); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
END |
62
|
|
|
|
|
|
|
|
63
|
166
|
|
|
|
|
384
|
$script .= join "", map {sprintf <<'END', @$_} @setter; |
|
27
|
|
|
|
|
133
|
|
64
|
|
|
|
|
|
|
sub set_%s { |
65
|
|
|
|
|
|
|
my MY $self = shift; |
66
|
|
|
|
|
|
|
$self->{%s} = shift; |
67
|
|
|
|
|
|
|
$self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
END |
70
|
|
|
|
|
|
|
|
71
|
166
|
|
|
|
|
10232
|
eval qq{#line 1 "/dev/null"\n}.$script; |
72
|
166
|
50
|
|
|
|
75609
|
die "$@\n$script" if $@; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |