line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perinci::Object::Metadata; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2018-10-18'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.310'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
1938
|
use 5.010; |
|
5
|
|
|
|
|
22
|
|
7
|
5
|
|
|
5
|
|
25
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
96
|
|
8
|
5
|
|
|
5
|
|
22
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
4347
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# BEGIN COPY-PASTE FROM String::Trim::More |
11
|
|
|
|
|
|
|
sub __trim_blank_lines { |
12
|
39
|
|
|
39
|
|
70
|
local $_ = shift; |
13
|
39
|
50
|
|
|
|
72
|
return $_ unless defined; |
14
|
39
|
|
|
|
|
60
|
s/\A(?:\n\s*)+//; |
15
|
39
|
|
|
|
|
76
|
s/(?:\n\s*){2,}\z/\n/; |
16
|
39
|
|
|
|
|
78
|
$_; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
# END COPY-PASTE |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
19
|
|
|
19
|
1
|
43
|
my ($class, $meta) = @_; |
22
|
19
|
|
50
|
|
|
55
|
$meta //= {}; |
23
|
19
|
|
|
|
|
34
|
my $obj = \$meta; |
24
|
19
|
|
|
|
|
82
|
bless $obj, $class; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub v { |
28
|
8
|
|
|
8
|
1
|
20
|
my $self = shift; |
29
|
8
|
|
100
|
|
|
14
|
${$self}->{v} // 1.0; |
|
8
|
|
|
|
|
87
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub type { |
33
|
0
|
|
|
0
|
1
|
0
|
die "BUG: type() must be subclassed"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub as_struct { |
37
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
38
|
1
|
|
|
|
|
2
|
${$self}; |
|
1
|
|
|
|
|
8
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub langprop { |
42
|
39
|
|
|
39
|
1
|
4213
|
my $self = shift; |
43
|
39
|
|
|
|
|
63
|
my $opts; |
44
|
39
|
100
|
|
|
|
84
|
if (ref($_[0]) eq 'HASH') { |
45
|
32
|
|
|
|
|
64
|
$opts = shift; |
46
|
|
|
|
|
|
|
} else { |
47
|
7
|
|
|
|
|
11
|
$opts = {}; |
48
|
|
|
|
|
|
|
} |
49
|
39
|
|
|
|
|
65
|
my $prop = shift; |
50
|
|
|
|
|
|
|
|
51
|
39
|
|
100
|
|
|
52
|
my $deflang = ${$self}->{default_lang} // "en_US"; |
|
39
|
|
|
|
|
139
|
|
52
|
39
|
|
66
|
|
|
152
|
my $olang = $opts->{lang} || $ENV{LANGUAGE} || $ENV{LANG} || $deflang; |
53
|
39
|
|
|
|
|
102
|
$olang =~ s/\W.+//; # change "en_US.UTF-8" to "en_US" |
54
|
39
|
50
|
|
|
|
114
|
$olang = "en_US" if $olang eq 'C'; |
55
|
39
|
|
|
|
|
220
|
(my $olang2 = $olang) =~ s/\A([a-z]{2})_[A-Z]{2}\z/$1/; # change "en_US" to "en" |
56
|
39
|
|
100
|
|
|
128
|
my $mark = $opts->{mark_different_lang} // 1; |
57
|
|
|
|
|
|
|
#print "deflang=$deflang, olang=$olang, mark_different_lang=$mark\n"; |
58
|
|
|
|
|
|
|
|
59
|
39
|
|
|
|
|
69
|
my @k; |
60
|
39
|
100
|
|
|
|
77
|
if ($olang eq $deflang) { |
61
|
18
|
|
|
|
|
48
|
@k = ([$olang, $prop, 0]); |
62
|
|
|
|
|
|
|
} else { |
63
|
21
|
|
|
|
|
105
|
@k = ( |
64
|
|
|
|
|
|
|
[$olang, "$prop.alt.lang.$olang", 0], |
65
|
|
|
|
|
|
|
([$olang2, "$prop.alt.lang.$olang2", 0]) x !!($olang2 ne $olang), |
66
|
|
|
|
|
|
|
[$deflang, $prop, $mark], |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
39
|
|
|
|
|
59
|
my $v; |
71
|
|
|
|
|
|
|
GET: |
72
|
39
|
|
|
|
|
64
|
for my $k (@k) { |
73
|
|
|
|
|
|
|
#print "k=".join(", ", @$k)."\n"; |
74
|
47
|
|
|
|
|
80
|
$v = ${$self}->{$k->[1]}; |
|
47
|
|
|
|
|
97
|
|
75
|
47
|
100
|
|
|
|
102
|
if (defined $v) { |
76
|
39
|
100
|
|
|
|
70
|
if ($k->[2]) { |
77
|
3
|
|
|
|
|
8
|
my $has_nl = $v =~ s/\n\z//; |
78
|
3
|
100
|
|
|
|
14
|
$v = "{$olang|$k->[0] $v}" . ($has_nl ? "\n" : ""); |
79
|
|
|
|
|
|
|
} |
80
|
39
|
|
|
|
|
73
|
$v = __trim_blank_lines($v); |
81
|
39
|
|
|
|
|
75
|
last GET; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
39
|
100
|
|
|
|
77
|
if (@_) { |
86
|
|
|
|
|
|
|
# set value |
87
|
10
|
|
|
|
|
14
|
${$self}->{$k[0][1]} = $_[0]; |
|
10
|
|
|
|
|
26
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
39
|
|
|
|
|
177
|
$v; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub name { |
94
|
6
|
|
|
6
|
1
|
13
|
my $self = shift; |
95
|
6
|
|
|
|
|
10
|
my $opts; |
96
|
6
|
100
|
100
|
|
|
23
|
if (@_ && ref($_[0]) eq 'HASH') { |
97
|
3
|
|
|
|
|
6
|
$opts = shift; |
98
|
|
|
|
|
|
|
} else { |
99
|
3
|
|
|
|
|
5
|
$opts = {}; |
100
|
|
|
|
|
|
|
} |
101
|
6
|
|
|
|
|
14
|
$self->langprop($opts, "name", @_); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub caption { |
105
|
6
|
|
|
6
|
1
|
13
|
my $self = shift; |
106
|
6
|
|
|
|
|
8
|
my $opts; |
107
|
6
|
100
|
100
|
|
|
27
|
if (@_ && ref($_[0]) eq 'HASH') { |
108
|
3
|
|
|
|
|
6
|
$opts = shift; |
109
|
|
|
|
|
|
|
} else { |
110
|
3
|
|
|
|
|
6
|
$opts = {}; |
111
|
|
|
|
|
|
|
} |
112
|
6
|
|
|
|
|
14
|
$self->langprop($opts, "caption", @_); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub summary { |
116
|
6
|
|
|
6
|
1
|
13
|
my $self = shift; |
117
|
6
|
|
|
|
|
8
|
my $opts; |
118
|
6
|
100
|
100
|
|
|
27
|
if (@_ && ref($_[0]) eq 'HASH') { |
119
|
3
|
|
|
|
|
6
|
$opts = shift; |
120
|
|
|
|
|
|
|
} else { |
121
|
3
|
|
|
|
|
6
|
$opts = {}; |
122
|
|
|
|
|
|
|
} |
123
|
6
|
|
|
|
|
14
|
$self->langprop($opts, "summary", @_); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub description { |
127
|
6
|
|
|
6
|
1
|
14
|
my $self = shift; |
128
|
6
|
|
|
|
|
9
|
my $opts; |
129
|
6
|
100
|
100
|
|
|
26
|
if (@_ && ref($_[0]) eq 'HASH') { |
130
|
3
|
|
|
|
|
7
|
$opts = shift; |
131
|
|
|
|
|
|
|
} else { |
132
|
3
|
|
|
|
|
6
|
$opts = {}; |
133
|
|
|
|
|
|
|
} |
134
|
6
|
|
|
|
|
13
|
$self->langprop($opts, "description", @_); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
# ABSTRACT: Base class for Perinci::Object metadata classes |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
__END__ |