Skip to content

Commit c1606be

Browse files
committed
Eliminate use vars, and add test that all vars are populated.
1 parent aa53885 commit c1606be

File tree

3 files changed

+87
-36
lines changed

3 files changed

+87
-36
lines changed

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ Makefile.PL
44
MANIFEST
55
README.md
66
t/00-load.t
7+
t/01-populated.t
78
t/pod.t

lib/HTML/Tagset.pm

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ Version 3.21
1212
1313
=cut
1414

15-
use vars qw( $VERSION );
16-
17-
$VERSION = '3.21_01';
15+
our $VERSION = '3.22';
1816

1917
=head1 SYNOPSIS
2018
@@ -34,20 +32,6 @@ set -- the hash conveys that its keys are there, and the actual values
3432
associated with the keys are not significant. (But what values are
3533
there, are always true.)
3634
37-
=cut
38-
39-
use vars qw(
40-
$VERSION
41-
%emptyElement %optionalEndTag %linkElements %boolean_attr
42-
%isHeadElement %isBodyElement %isPhraseMarkup
43-
%is_Possible_Strict_P_Content
44-
%isHeadOrBodyElement
45-
%isList %isTableElement %isFormElement
46-
%isKnown %canTighten
47-
@p_closure_barriers
48-
%isCDATA_Parent
49-
);
50-
5135
=head1 VARIABLES
5236
5337
Note that none of these variables are exported.
@@ -61,7 +45,8 @@ C<$HTML::Tagset::emptyElement{'dl'}> does not exist, and so is not true.
6145
6246
=cut
6347

64-
%emptyElement = map {; $_ => 1 } qw(base link meta isindex
48+
our %emptyElement = map { $_ => 1 } qw(
49+
base link meta isindex
6550
img br hr wbr
6651
input area param
6752
embed bgsound spacer
@@ -80,7 +65,9 @@ C<$HTML::Tagset::emptyElement{'li'}> exists and is true.
8065
8166
=cut
8267

83-
%optionalEndTag = map {; $_ => 1 } qw(p li dt dd); # option th tr td);
68+
our %optionalEndTag = map { $_ => 1 } qw(
69+
p li dt dd
70+
); # option th tr td);
8471

8572
=head2 hash %HTML::Tagset::linkElements
8673
@@ -90,7 +77,7 @@ of attributes whose values can be links.
9077
9178
=cut
9279

93-
%linkElements =
80+
our %linkElements =
9481
(
9582
'a' => ['href'],
9683
'applet' => ['archive', 'codebase', 'code'],
@@ -132,7 +119,7 @@ the value is a reference to a hashset containing all such attributes.
132119
133120
=cut
134121

135-
%boolean_attr = (
122+
our %boolean_attr = (
136123
# TODO: make these all hashes
137124
'area' => 'nohref',
138125
'dir' => 'compact',
@@ -177,7 +164,7 @@ This hashset contains all phrasal-level elements.
177164
178165
=cut
179166

180-
%isPhraseMarkup = map {; $_ => 1 } qw(
167+
our %isPhraseMarkup = map { $_ => 1 } qw(
181168
span abbr acronym q sub sup
182169
cite code em kbd samp strong var dfn strike
183170
b i u s tt small big
@@ -196,7 +183,8 @@ P element, for a strict model of HTML.
196183
197184
=cut
198185

199-
%is_Possible_Strict_P_Content = (
186+
our %isFormElement; # Forward declaration
187+
our %is_Possible_Strict_P_Content = (
200188
%isPhraseMarkup,
201189
%isFormElement,
202190
map {; $_ => 1} qw( object script map )
@@ -225,7 +213,7 @@ present only in the 'head' element of an HTML document.
225213
226214
=cut
227215

228-
%isHeadElement = map {; $_ => 1 }
216+
our %isHeadElement = map { $_ => 1 }
229217
qw(title base link meta isindex script style object bgsound);
230218

231219
=head2 hashset %HTML::Tagset::isList
@@ -234,7 +222,9 @@ This hashset contains all elements that can contain "li" elements.
234222
235223
=cut
236224

237-
%isList = map {; $_ => 1 } qw(ul ol dir menu);
225+
our %isList = map { $_ => 1 } qw(
226+
ul ol dir menu
227+
);
238228

239229
=head2 hashset %HTML::Tagset::isTableElement
240230
@@ -243,7 +233,7 @@ a "table" element.
243233
244234
=cut
245235

246-
%isTableElement = map {; $_ => 1 }
236+
our %isTableElement = map { $_ => 1 }
247237
qw(tr td th thead tbody tfoot caption col colgroup);
248238

249239
=head2 hashset %HTML::Tagset::isFormElement
@@ -253,7 +243,8 @@ a "form" element.
253243
254244
=cut
255245

256-
%isFormElement = map {; $_ => 1 }
246+
# Declared earlier in the file
247+
%isFormElement = map { $_ => 1 }
257248
qw(input select option optgroup textarea button label);
258249

259250
=head2 hashset %HTML::Tagset::isBodyElement
@@ -263,7 +254,7 @@ the "body" element of an HTML document.
263254
264255
=cut
265256

266-
%isBodyElement = map {; $_ => 1 } qw(
257+
our %isBodyElement = map { $_ => 1 } qw(
267258
h1 h2 h3 h4 h5 h6
268259
p div pre plaintext address blockquote
269260
xmp listing
@@ -277,9 +268,9 @@ the "body" element of an HTML document.
277268
ol ul dir menu li
278269
dl dt dd
279270
ins del
280-
271+
281272
fieldset legend
282-
273+
283274
map area
284275
applet param object
285276
isindex script noscript
@@ -300,7 +291,7 @@ the head or in the body.
300291
301292
=cut
302293

303-
%isHeadOrBodyElement = map {; $_ => 1 }
294+
our %isHeadOrBodyElement = map { $_ => 1 }
304295
qw(script isindex style object map area param noscript bgsound);
305296
# i.e., if we find 'script' in the 'body' or the 'head', don't freak out.
306297

@@ -311,8 +302,8 @@ This hashset lists all known HTML elements.
311302
312303
=cut
313304

314-
%isKnown = (%isHeadElement, %isBodyElement,
315-
map{; $_=>1 }
305+
our %isKnown = (%isHeadElement, %isBodyElement,
306+
map{ $_ => 1 }
316307
qw( head body html
317308
frame frameset noframes
318309
~comment ~pi ~directive ~literal
@@ -327,7 +318,7 @@ children or siblings.
327318
328319
=cut
329320

330-
%canTighten = %isKnown;
321+
our %canTighten = %isKnown;
331322
delete @canTighten{
332323
keys(%isPhraseMarkup), 'input', 'select',
333324
'xmp', 'listing', 'plaintext', 'pre',
@@ -387,7 +378,7 @@ barrier-tags.
387378
388379
=cut
389380

390-
@p_closure_barriers = qw(
381+
our @p_closure_barriers = qw(
391382
li blockquote
392383
ul ol menu dir
393384
dl dt dd
@@ -404,7 +395,7 @@ This hashset includes all elements whose content is CDATA.
404395
405396
=cut
406397

407-
%isCDATA_Parent = map {; $_ => 1 }
398+
our %isCDATA_Parent = map { $_ => 1 }
408399
qw(script style xmp listing plaintext);
409400

410401
# TODO: there's nothing else that takes CDATA children, right?

t/01-populated.t

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!perl
2+
3+
# Verify that all the hashes and arrays are populated.
4+
5+
use strict;
6+
use warnings;
7+
8+
use Test::More tests => 32;
9+
10+
use HTML::Tagset;
11+
12+
my @vars = qw(
13+
%emptyElement
14+
%optionalEndTag
15+
%linkElements
16+
%boolean_attr
17+
%isPhraseMarkup
18+
%is_Possible_Strict_P_Content
19+
%isHeadElement
20+
%isList
21+
%isTableElement
22+
%isFormElement
23+
%isBodyElement
24+
%isHeadOrBodyElement
25+
%isKnown
26+
%canTighten
27+
%isCDATA_Parent
28+
29+
@p_closure_barriers
30+
);
31+
32+
33+
HASHES: {
34+
for my $var ( grep { /%/ } @vars ) {
35+
$var =~ s/^%(.+)/%HTML::Tagset::$1/ or die;
36+
37+
my %h = eval "$var";
38+
cmp_ok( scalar keys %h, '>', 0, "$var is not an empty hash" );
39+
40+
my @undefs = grep { !defined } values %h;
41+
is( scalar @undefs, 0, "$var has no undef values" );
42+
}
43+
}
44+
45+
46+
ARRAYS: {
47+
for my $var ( grep { /@/ } @vars ) {
48+
$var =~ s/^\@(.+)/\@HTML::Tagset::$1/ or die;
49+
50+
my @a = eval "$var";
51+
cmp_ok( scalar @a, '>', 0, "$var is not an empty array" );
52+
53+
my @undefs = grep { !defined } @a;
54+
is( scalar @undefs, 0, "$var has no undef values" );
55+
}
56+
}
57+
58+
59+
exit;

0 commit comments

Comments
 (0)