line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: perl; coding: utf-8 -*- |
2
|
|
|
|
|
|
|
package YATT::Fields; |
3
|
12
|
|
|
12
|
|
42
|
use strict; |
|
12
|
|
|
|
|
14
|
|
|
12
|
|
|
|
|
357
|
|
4
|
12
|
|
|
12
|
|
38
|
use warnings FATAL => qw(all); |
|
12
|
|
|
|
|
12
|
|
|
12
|
|
|
|
|
416
|
|
5
|
12
|
|
|
12
|
|
42
|
use YATT::Util::Symbol; |
|
12
|
|
|
|
|
15
|
|
|
12
|
|
|
|
|
4480
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub import { |
8
|
166
|
|
|
166
|
|
495
|
require fields; |
9
|
166
|
|
|
|
|
258
|
my ($thispack) = shift; |
10
|
166
|
|
|
|
|
305
|
my ($callpack) = caller; |
11
|
166
|
|
|
|
|
176
|
my @public; |
12
|
|
|
|
|
|
|
my @setter; |
13
|
0
|
|
|
|
|
0
|
my @FIELDS; |
14
|
166
|
|
|
|
|
335
|
foreach my $desc (@_) { |
15
|
1149
|
|
|
|
|
746
|
my ($slot, $default); |
16
|
1149
|
100
|
|
|
|
1152
|
if (ref $desc) { |
17
|
93
|
|
|
|
|
109
|
$slot = shift @$desc; |
18
|
93
|
|
|
|
|
133
|
$default = do { |
19
|
93
|
100
|
|
|
|
305
|
if (@$desc > 1) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
20
|
11
|
50
|
|
185
|
|
42
|
sub { wantarray ? @$desc : [@$desc]; }; |
|
185
|
|
|
|
|
995
|
|
21
|
|
|
|
|
|
|
} elsif (! @$desc) { |
22
|
0
|
|
|
|
|
0
|
undef; |
23
|
|
|
|
|
|
|
} elsif (ref(my $value = $desc->[0]) eq 'CODE') { |
24
|
10
|
|
|
|
|
19
|
$value; |
25
|
|
|
|
|
|
|
} else { |
26
|
0
|
|
|
0
|
|
0
|
sub () { $value; } |
27
|
72
|
|
|
|
|
464
|
} |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
} else { |
30
|
1056
|
|
|
|
|
707
|
$slot = $desc; |
31
|
|
|
|
|
|
|
} |
32
|
1149
|
100
|
|
|
|
2141
|
if ($slot =~ s/^([\^=]+)((?:cf_)?)//) { |
33
|
222
|
|
|
|
|
191
|
my $func_name = $slot; |
34
|
222
|
|
|
|
|
319
|
my $cf_slot = "$2$slot"; |
35
|
222
|
|
|
|
|
404
|
foreach my $ch (split //, $1) { |
36
|
249
|
100
|
|
|
|
812
|
push @public, [$func_name, $cf_slot] if $ch eq '^'; |
37
|
249
|
100
|
|
|
|
498
|
push @setter, [$func_name, $cf_slot] if $ch eq '='; |
38
|
|
|
|
|
|
|
} |
39
|
222
|
|
|
|
|
268
|
push @FIELDS, $cf_slot; |
40
|
|
|
|
|
|
|
} else { |
41
|
927
|
|
|
|
|
767
|
push @FIELDS, $slot; |
42
|
|
|
|
|
|
|
} |
43
|
1149
|
100
|
|
|
|
1721
|
if (defined $default) { |
44
|
93
|
|
|
|
|
68
|
*{globref($callpack, "default_$slot")} = $default; |
|
93
|
|
|
|
|
249
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
166
|
|
|
|
|
535
|
my $script = <
|
49
|
|
|
|
|
|
|
package $callpack; |
50
|
|
|
|
|
|
|
use fields qw(@FIELDS); |
51
|
|
|
|
|
|
|
sub MY () {__PACKAGE__} |
52
|
|
|
|
|
|
|
END |
53
|
|
|
|
|
|
|
|
54
|
166
|
|
|
|
|
208
|
$script .= join "", map {sprintf <<'END', @$_} @public; |
|
222
|
|
|
|
|
798
|
|
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
|
|
|
|
|
232
|
$script .= join "", map {sprintf <<'END', @$_} @setter; |
|
27
|
|
|
|
|
67
|
|
64
|
|
|
|
|
|
|
sub set_%s { |
65
|
|
|
|
|
|
|
my MY $self = shift; |
66
|
|
|
|
|
|
|
$self->{%s} = shift; |
67
|
|
|
|
|
|
|
$self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
END |
70
|
|
|
|
|
|
|
|
71
|
166
|
|
|
|
|
7763
|
eval qq{#line 1 "/dev/null"\n}.$script; |
72
|
166
|
50
|
|
|
|
46652
|
die "$@\n$script" if $@; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |