line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::WebMake::Metadata; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
########################################################################### |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
75
|
|
9
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
191
|
use HTML::WebMake::Main; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
|
|
2151
|
use vars qw{ |
14
|
|
|
|
|
|
|
@ISA %BUILTIN_TYPES $NUM $STR |
15
|
1
|
|
|
1
|
|
6
|
}; |
|
1
|
|
|
|
|
3
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$NUM = 1; |
20
|
|
|
|
|
|
|
$STR = 2; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
%BUILTIN_TYPES = ( |
23
|
|
|
|
|
|
|
'score' => { type => $NUM, default => 50 }, |
24
|
|
|
|
|
|
|
'title' => { type => $STR, default => '(Untitled)' }, |
25
|
|
|
|
|
|
|
'abstract' => { type => $STR, default => '' }, |
26
|
|
|
|
|
|
|
'section' => { type => $STR, default => '' }, |
27
|
|
|
|
|
|
|
'declared' => { type => $NUM, default => 0 }, |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# some pseudo-metadata types. These are not strictly metadata, but |
30
|
|
|
|
|
|
|
# they are available through Content::get_metadata(). |
31
|
|
|
|
|
|
|
'url' => { type => $STR, default => '' }, |
32
|
|
|
|
|
|
|
'is_generated' => { type => $NUM, default => 0 }, |
33
|
|
|
|
|
|
|
'mtime' => { type => $NUM, default => 0 }, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
########################################################################### |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new ($$$$$) { |
44
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
45
|
0
|
|
0
|
|
|
|
$class = ref($class) || $class; |
46
|
0
|
|
|
|
|
|
my ($main) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $self = { |
49
|
|
|
|
|
|
|
'main' => $main, |
50
|
|
|
|
|
|
|
'metadefaults' => { }, |
51
|
|
|
|
|
|
|
'attrdefaults' => { }, |
52
|
|
|
|
|
|
|
}; |
53
|
0
|
|
|
|
|
|
bless ($self, $class); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$self; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
0
|
0
|
|
sub dbg { HTML::WebMake::Main::dbg (@_); } |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub get_type { |
63
|
0
|
|
|
0
|
0
|
|
my ($self, $meta) = @_; |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
croak "no meta defined in get_type" unless defined($meta); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $info = $BUILTIN_TYPES{$meta}; |
68
|
0
|
0
|
|
|
|
|
if (!defined $info) { return undef; } |
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return $info->{type}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub get_default_value { |
74
|
0
|
|
|
0
|
0
|
|
my ($self, $meta) = @_; |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
croak "no meta defined in get_default_value" unless defined($meta); |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $info = $BUILTIN_TYPES{$meta}; |
79
|
0
|
0
|
|
|
|
|
if (!defined $info) { return undef; } |
|
0
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return $info->{default}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub convert_to_type { |
87
|
0
|
|
|
0
|
0
|
|
my ($self, $meta, $val) = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
croak "no meta defined in get_type" unless defined($meta); |
90
|
0
|
0
|
|
|
|
|
croak "no val defined in get_type" unless defined($val); |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $info = $BUILTIN_TYPES{$meta}; |
93
|
0
|
0
|
|
|
|
|
if (!defined $info) { return undef; } |
|
0
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
if ($info->{type} == $NUM) { |
96
|
0
|
|
|
|
|
|
$val+0; # convert to numeric |
97
|
|
|
|
|
|
|
} else { |
98
|
0
|
|
|
|
|
|
$val; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub string_to_sort_sub { |
105
|
0
|
|
|
0
|
0
|
|
my ($self, $sortstring) = @_; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my @substrs = (); |
108
|
0
|
|
|
|
|
|
foreach my $item (split (' ', $sortstring)) { |
109
|
0
|
|
|
|
|
|
my $aname = '$a'; |
110
|
0
|
|
|
|
|
|
my $bname = '$b'; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# !value means reverse-sort by that value, ie. swap $a and $b. |
113
|
0
|
0
|
|
|
|
|
if ($item =~ s/^!//) { $aname = '$b'; $bname = '$a'; } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $type = $self->get_type ($item); |
116
|
0
|
0
|
|
|
|
|
if (!defined $type) { |
117
|
0
|
|
|
|
|
|
carp "no type defined for metadatum \"$item\"\n"; |
118
|
0
|
|
|
|
|
|
next; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $cmpstr = ''; |
122
|
0
|
0
|
|
|
|
|
if ($type eq $NUM) { |
|
|
0
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$cmpstr = " <=> "; |
124
|
|
|
|
|
|
|
} elsif ($type eq $STR) { |
125
|
0
|
|
|
|
|
|
$cmpstr = " cmp "; |
126
|
|
|
|
|
|
|
} else { |
127
|
0
|
|
|
|
|
|
die "oops? unknown type $type for $item"; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
push (@substrs , '('. #) |
131
|
|
|
|
|
|
|
$aname.'->get_metadata(q{'.$item.'})'.$cmpstr. |
132
|
|
|
|
|
|
|
$bname.'->get_metadata(q{'.$item.'}))'); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
if ($#substrs < 0) { |
136
|
0
|
|
|
|
|
|
croak "no usable sort items defined\n"; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
my $substr = 'sub {'.join (' || ', @substrs).'}'; #} |
140
|
0
|
|
|
|
|
|
dbg ("string to sort-sub: \"$sortstring\": $substr"); |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
$substr; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub set_metadefault { |
148
|
0
|
|
|
0
|
0
|
|
my ($self, $name, $value) = @_; |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
$name = lc $name; |
151
|
|
|
|
|
|
|
|
152
|
0
|
0
|
0
|
|
|
|
if (defined $value && $value eq '[POP]') { |
|
|
0
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
shift (@{$self->{metadefaults}->{$name}}); |
|
0
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
} elsif (defined $value) { |
156
|
0
|
0
|
|
|
|
|
if (!defined $self->{metadefaults}->{$name}) { |
157
|
0
|
|
|
|
|
|
$self->{metadefaults}->{$name} = [ ]; |
158
|
|
|
|
|
|
|
} |
159
|
0
|
|
|
|
|
|
unshift (@{$self->{metadefaults}->{$name}}, $value); |
|
0
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
} else { |
161
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
unshift (@{$self->{metadefaults}->{$name}}, undef); |
|
0
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub add_metadefaults { |
169
|
0
|
|
|
0
|
0
|
|
my ($self, $contobj) = @_; |
170
|
0
|
|
|
|
|
|
my ($metaname, $val); |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
while (($metaname, $val) = each %{$self->{metadefaults}}) { |
|
0
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# dbg ("adding metadefault: \"$metaname\" => \"$val\""); |
174
|
0
|
0
|
0
|
|
|
|
if (defined $val && defined $val->[0]) { |
175
|
0
|
|
|
|
|
|
$contobj->create_extra_metas_if_needed(); |
176
|
0
|
|
|
|
|
|
$contobj->{extra_metas}->{$metaname} = $val->[0]; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub set_attrdefault { |
184
|
0
|
|
|
0
|
0
|
|
my ($self, $name, $value) = @_; |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
$name = lc $name; |
187
|
|
|
|
|
|
|
|
188
|
0
|
0
|
0
|
|
|
|
if (defined $value && $value eq '[POP]') { |
|
|
0
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
shift (@{$self->{attrdefaults}->{$name}}); |
|
0
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
} elsif (defined $value) { |
192
|
0
|
0
|
|
|
|
|
if (!defined $self->{attrdefaults}->{$name}) { |
193
|
0
|
|
|
|
|
|
$self->{attrdefaults}->{$name} = [ ]; |
194
|
|
|
|
|
|
|
} |
195
|
0
|
|
|
|
|
|
unshift (@{$self->{attrdefaults}->{$name}}, $value); |
|
0
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
} else { |
198
|
0
|
|
|
|
|
|
unshift (@{$self->{attrdefaults}->{$name}}, undef); |
|
0
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub get_attrdefault { |
203
|
0
|
|
|
0
|
0
|
|
my ($self, $name) = @_; |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
my $ary = $self->{attrdefaults}->{$name}; |
206
|
0
|
0
|
|
|
|
|
if (!defined $ary) { return undef; } |
|
0
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
$ary->[0]; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
1; |