line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::WebMake::Util; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
66
|
|
7
|
1
|
|
|
1
|
|
5
|
use File::Basename; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
8
|
1
|
|
|
1
|
|
6
|
use File::Path; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
58
|
|
9
|
1
|
|
|
1
|
|
5
|
use File::Spec; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
23
|
|
10
|
1
|
|
|
1
|
|
5
|
use Cwd; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
70
|
|
11
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
41
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
|
|
2118
|
use vars qw{ |
14
|
|
|
|
|
|
|
@ISA |
15
|
1
|
|
|
1
|
|
5
|
}; |
|
1
|
|
|
|
|
2
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
########################################################################### |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new ($) { |
23
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
24
|
0
|
|
0
|
|
|
|
$class = ref($class) || $class; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my $self = { |
27
|
|
|
|
|
|
|
'last_tag_text' => undef, |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
bless ($self, $class); |
31
|
0
|
|
|
|
|
|
$self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
0
|
|
sub dbg { HTML::WebMake::Main::dbg (@_); } |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
########################################################################### |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub glob_to_re ($$) { |
39
|
0
|
|
|
0
|
0
|
|
my ($self, $patt) = @_; |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
if (!defined $patt) { return $patt; } |
|
0
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
if ($patt =~ s/^RE://) { return $patt; } |
|
0
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$patt =~ s:([].+^\-\${}[|]):\\$1:g; |
45
|
0
|
|
|
|
|
|
$patt =~ s/\\\.\\\.\\\./.*/g; |
46
|
0
|
|
|
|
|
|
$patt =~ s/\*/[^\/]*/g; |
47
|
0
|
|
|
|
|
|
$patt =~ s/\?/./g; |
48
|
0
|
|
|
|
|
|
'^'.$patt.'$'; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
########################################################################### |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub parse_boolean ($$) { |
54
|
0
|
|
|
0
|
0
|
|
my ($self, $val) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
0
|
|
|
|
if (defined $val && $val =~ /^(?:true|yes|on|y|1)$/i) { |
57
|
0
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
} else { |
59
|
0
|
|
|
|
|
|
0; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
########################################################################### |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub parse_xml_tag_attributes ($$$$$) { |
66
|
0
|
|
|
0
|
0
|
|
my ($self, $tag, $origtxt, $filename, @reqd_attrs) = @_; |
67
|
0
|
|
|
|
|
|
my $attrtxt = " ".$origtxt." "; |
68
|
0
|
|
|
|
|
|
my $attrs = { }; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#dbg ("tag: <$tag$origtxt>"); |
71
|
0
|
|
|
|
|
|
while ($attrtxt =~ s{\s([A-Z0-9a-z_]+)\s*=\s*\"([^\"]*?)\"\s}{ }is) { |
72
|
|
|
|
|
|
|
#dbg ("tag: <$tag$attrtxt>: $1=$2"); |
73
|
0
|
|
|
|
|
|
my ($atname, $atval) = ($1, $2); $atname =~ tr/A-Z/a-z/; |
|
0
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$attrs->{$atname} = $atval; |
75
|
|
|
|
|
|
|
} # fix vim highlighting: " |
76
|
0
|
|
|
|
|
|
while ($attrtxt =~ s{\s([A-Z0-9a-z_]+)\s*=\s*\'([^\']*?)\'\s}{ }is) { |
77
|
0
|
|
|
|
|
|
my ($atname, $atval) = ($1, $2); $atname =~ tr/A-Z/a-z/; |
|
0
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$attrs->{$atname} = $atval; |
79
|
|
|
|
|
|
|
} # fix vim highlighting: ' |
80
|
0
|
|
|
|
|
|
while ($attrtxt =~ s{\s([A-Z0-9a-z_]+)\s*=\s*(\S*)\s}{ }is) { |
81
|
0
|
|
|
|
|
|
my ($atname, $atval) = ($1, $2); $atname =~ tr/A-Z/a-z/; |
|
0
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$attrs->{$atname} = $atval; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
foreach my $attr (@reqd_attrs) { |
86
|
0
|
0
|
|
|
|
|
if (!defined $attrs->{$attr}) { |
87
|
0
|
|
|
|
|
|
warn ($filename.": tag \"".$tag. |
88
|
|
|
|
|
|
|
"\" is missing required attribute \"$attr\": <$tag $origtxt>\n"); |
89
|
0
|
|
|
|
|
|
return; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
return $attrs; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
########################################################################### |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub set_filename ($$) { |
99
|
0
|
|
|
0
|
0
|
|
my ($self, $filename) = @_; |
100
|
0
|
|
|
|
|
|
$self->{filename} = $filename; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub strip_tags ($$$$$@) { |
104
|
0
|
|
|
0
|
0
|
|
my ($self, $file, $tag, $taghandler, $tagfn, @reqd_attrs) = @_; |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
return unless $file =~ m{<${tag}\b}is; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$file =~ s{<${tag}([^>]*?)/>}{ |
109
|
0
|
|
|
|
|
|
$self->_found_tag ($tag, $1, '', 1, \@reqd_attrs, $taghandler, $tagfn); |
110
|
|
|
|
|
|
|
}gies; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$file =~ s{<${tag}([^>]*?)>(.*?)<\/\s*${tag}\s*>}{ |
113
|
0
|
|
|
|
|
|
$self->_found_tag ($tag, $1, $2, 0, \@reqd_attrs, $taghandler, $tagfn); |
114
|
|
|
|
|
|
|
}gies; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$file; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _strip_first_tag ($$$$$$@) { |
120
|
0
|
|
|
0
|
|
|
my ($self, $paired, $textref, $tag, $taghandler, $tagfn, @reqd_attrs) = @_; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$self->{last_tag_text} = $self->{last_tag_regexp} = undef; |
123
|
0
|
0
|
|
|
|
|
return unless $$textref =~ m{^\s*<${tag}\b}is; |
124
|
|
|
|
|
|
|
|
125
|
0
|
0
|
0
|
|
|
|
if ($paired == 0 || $paired == 2) { |
126
|
0
|
0
|
|
|
|
|
$$textref =~ s{^\s*<\S+([^>]*?)/>}{ |
127
|
0
|
|
|
|
|
|
$self->_found_tag ($tag, $1, '', 1, \@reqd_attrs, $taghandler, $tagfn); |
128
|
|
|
|
|
|
|
}gies and return; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
0
|
0
|
0
|
|
|
|
if ($paired == 1 || $paired == 2) { |
132
|
0
|
0
|
|
|
|
|
$$textref =~ s{^\s*<\S+([^>]*?)>(.*?)<\/\s*${tag}\s*>}{ |
133
|
0
|
|
|
|
|
|
$self->_found_tag ($tag, $1, $2, 0, \@reqd_attrs, $taghandler, $tagfn); |
134
|
|
|
|
|
|
|
}gies and return; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub strip_first_tag ($$$$$@) { |
139
|
0
|
|
|
0
|
0
|
|
return shift->_strip_first_tag (2, @_); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
sub strip_first_lone_tag ($$$$$@) { |
142
|
0
|
|
|
0
|
0
|
|
return shift->_strip_first_tag (0, @_); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
sub strip_first_tag_block ($$$$$@) { |
145
|
0
|
|
|
0
|
0
|
|
return shift->_strip_first_tag (1, @_); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub _found_tag ($$$$$$$) { |
149
|
0
|
|
|
0
|
|
|
my ($self, $tag, $origtxt, $text, $isempty, |
150
|
|
|
|
|
|
|
$reqd_attrs, $taghandler, $tagfn) = @_; |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
$self->{last_tag_text} = '<'.$tag.$origtxt.'> ... '.$tag.'>'; |
153
|
|
|
|
|
|
|
|
154
|
0
|
0
|
|
|
|
|
if ($self->{generate_tag_regexps}) { |
155
|
0
|
0
|
|
|
|
|
if ($isempty) { |
156
|
0
|
|
|
|
|
|
$self->{last_tag_regexp} = qr/ \Q<${tag}${origtxt}\/>\E /isx; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
} else { |
159
|
0
|
|
|
|
|
|
$self->{last_tag_regexp} = qr/ \Q<${tag}${origtxt}>\E |
160
|
|
|
|
|
|
|
.*? <\/\s*\Q${tag}\E\s*> /isx; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
my $attrs = $self->parse_xml_tag_attributes ($tag, $origtxt, |
165
|
0
|
|
|
|
|
|
$self->{filename}, @{$reqd_attrs}); |
166
|
0
|
0
|
|
|
|
|
if (!defined $attrs) { return; } |
|
0
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
&{$tagfn} ($taghandler, $tag, $attrs, $text); |
|
0
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
########################################################################### |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item @sorted = sort_by_score_title (@list); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
A sort function (see C) which sorts a list of content items in |
176
|
|
|
|
|
|
|
order of their C metadata, with alphanumeric sorting by C used |
177
|
|
|
|
|
|
|
for items of the same score. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub sort_by_score_title { |
182
|
0
|
|
|
0
|
1
|
|
my $cmp = $a->get_score() <=> $b->get_score(); |
183
|
0
|
0
|
|
|
|
|
if ($cmp != 0) { return $cmp; } |
|
0
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
$a->get_title() cmp $b->get_title(); |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# a convenience function to do the sort for us, otherwise some package |
189
|
|
|
|
|
|
|
# twiddling is required (as $a and $b are set in the caller's pkg). |
190
|
|
|
|
|
|
|
# |
191
|
|
|
|
|
|
|
sub sort_list_by_score_title { |
192
|
0
|
|
|
0
|
0
|
|
my ($self, @list) = @_; |
193
|
0
|
|
|
|
|
|
return sort sort_by_score_title @list; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
########################################################################### |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub text_eol { |
199
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
200
|
0
|
0
|
|
|
|
|
if ($^O =~ /(?:win|os2)/i) { |
|
|
0
|
|
|
|
|
|
201
|
0
|
|
|
|
|
|
return "\r\n"; |
202
|
|
|
|
|
|
|
} elsif ($^O =~ /(?:mac)/i) { |
203
|
0
|
|
|
|
|
|
return "\r"; |
204
|
|
|
|
|
|
|
} else { |
205
|
0
|
|
|
|
|
|
return "\n"; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
########################################################################### |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
1; |
212
|
|
|
|
|
|
|
|