line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: perl; coding: utf-8 -*- |
2
|
|
|
|
|
|
|
package YATT::Fields; |
3
|
12
|
|
|
12
|
|
63
|
use strict; |
|
12
|
|
|
|
|
25
|
|
|
12
|
|
|
|
|
403
|
|
4
|
12
|
|
|
12
|
|
57
|
use warnings qw(FATAL all NONFATAL misc); |
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
493
|
|
5
|
12
|
|
|
12
|
|
64
|
use YATT::Util::Symbol; |
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
7442
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub import { |
8
|
166
|
|
|
166
|
|
744
|
require fields; |
9
|
166
|
|
|
|
|
369
|
my ($thispack) = shift; |
10
|
166
|
|
|
|
|
458
|
my ($callpack) = caller; |
11
|
166
|
|
|
|
|
306
|
my @public; |
12
|
|
|
|
|
|
|
my @setter; |
13
|
0
|
|
|
|
|
0
|
my @FIELDS; |
14
|
166
|
|
|
|
|
427
|
foreach my $desc (@_) { |
15
|
1149
|
|
|
|
|
1391
|
my ($slot, $default); |
16
|
1149
|
100
|
|
|
|
2106
|
if (ref $desc) { |
17
|
93
|
|
|
|
|
175
|
$slot = shift @$desc; |
18
|
93
|
|
|
|
|
181
|
$default = do { |
19
|
93
|
100
|
|
|
|
454
|
if (@$desc > 1) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
20
|
11
|
50
|
|
185
|
|
51
|
sub { wantarray ? @$desc : [@$desc]; }; |
|
185
|
|
|
|
|
1386
|
|
21
|
|
|
|
|
|
|
} elsif (! @$desc) { |
22
|
0
|
|
|
|
|
0
|
undef; |
23
|
|
|
|
|
|
|
} elsif (ref(my $value = $desc->[0]) eq 'CODE') { |
24
|
10
|
|
|
|
|
29
|
$value; |
25
|
|
|
|
|
|
|
} else { |
26
|
0
|
|
|
0
|
|
0
|
sub () { $value; } |
27
|
72
|
|
|
|
|
626
|
} |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
} else { |
30
|
1056
|
|
|
|
|
1459
|
$slot = $desc; |
31
|
|
|
|
|
|
|
} |
32
|
1149
|
100
|
|
|
|
3373
|
if ($slot =~ s/^([\^=]+)((?:cf_)?)//) { |
33
|
222
|
|
|
|
|
308
|
my $func_name = $slot; |
34
|
222
|
|
|
|
|
586
|
my $cf_slot = "$2$slot"; |
35
|
222
|
|
|
|
|
658
|
foreach my $ch (split //, $1) { |
36
|
249
|
100
|
|
|
|
1215
|
push @public, [$func_name, $cf_slot] if $ch eq '^'; |
37
|
249
|
100
|
|
|
|
801
|
push @setter, [$func_name, $cf_slot] if $ch eq '='; |
38
|
|
|
|
|
|
|
} |
39
|
222
|
|
|
|
|
557
|
push @FIELDS, $cf_slot; |
40
|
|
|
|
|
|
|
} else { |
41
|
927
|
|
|
|
|
1449
|
push @FIELDS, $slot; |
42
|
|
|
|
|
|
|
} |
43
|
1149
|
100
|
|
|
|
2782
|
if (defined $default) { |
44
|
93
|
|
|
|
|
153
|
*{globref($callpack, "default_$slot")} = $default; |
|
93
|
|
|
|
|
406
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
166
|
|
|
|
|
710
|
my $script = <
|
49
|
|
|
|
|
|
|
package $callpack; |
50
|
|
|
|
|
|
|
use fields qw(@FIELDS); |
51
|
|
|
|
|
|
|
sub MY () {__PACKAGE__} |
52
|
|
|
|
|
|
|
END |
53
|
|
|
|
|
|
|
|
54
|
166
|
|
|
|
|
327
|
$script .= join "", map {sprintf <<'END', @$_} @public; |
|
222
|
|
|
|
|
1350
|
|
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
|
|
|
|
|
337
|
$script .= join "", map {sprintf <<'END', @$_} @setter; |
|
27
|
|
|
|
|
120
|
|
64
|
|
|
|
|
|
|
sub set_%s { |
65
|
|
|
|
|
|
|
my MY $self = shift; |
66
|
|
|
|
|
|
|
$self->{%s} = shift; |
67
|
|
|
|
|
|
|
$self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
END |
70
|
|
|
|
|
|
|
|
71
|
166
|
|
|
|
|
10335
|
eval qq{#line 1 "/dev/null"\n}.$script; |
72
|
166
|
50
|
|
|
|
75290
|
die "$@\n$script" if $@; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |