line
stmt
bran
cond
sub
pod
time
code
1
my $for_the_benefit_of_module_install_metadata = q{
2
package HTML::HTML5::DOM;
3
};
4
5
{ package HTML::HTML5::DOM;
6
7
2
2
71700
use 5.010;
2
10
2
104
8
2
2
13
use strict qw(vars subs);
2
4
2
70
9
2
2
2128
use match::simple ();
2
28348
2
72
10
2
2
3290
use mro 'c3';
2
2054
2
13
11
12
BEGIN {
13
2
2
104
$HTML::HTML5::DOM::AUTHORITY = 'cpan:TOBYINK';
14
2
89
$HTML::HTML5::DOM::VERSION = '0.002';
15
};
16
17
2
2
14
use constant XHTML_NS => 'http://www.w3.org/1999/xhtml';
2
4
2
173
18
19
my $me;
20
2
2
36
BEGIN { $me = bless {}, __PACKAGE__ }
21
22
2
2
3377
use DateTime qw//;
2
661755
2
91
23
2
2
4378
use IO::Detect qw//;
2
78275
2
61
24
2
2
23
use Scalar::Util qw/blessed/;
2
4
2
243
25
2
2
22
use URI qw//;
2
4
2
1862
26
27
sub getDOMImplementation
28
{
29
0
0
return $me;
30
}
31
32
our @FEATURES = (
33
HTML::HTML5::DOMutil::Feature->new(Core => '3.0'),
34
HTML::HTML5::DOMutil::Feature->new(XML => '3.0'),
35
HTML::HTML5::DOMutil::Feature->new(XMLVersion => '1.1'),
36
HTML::HTML5::DOMutil::Feature->new(HTML => '2.0'),
37
HTML::HTML5::DOMutil::Feature->new(XHTML => '2.0'),
38
);
39
40
sub getFeature
41
{
42
0
0
my $self = shift;
43
0
my @has = $self->hasFeature(@_);
44
0
0
@has ? $has[0] : undef;
45
}
46
47
sub hasFeature
48
{
49
0
0
my $self = shift;
50
0
0
my $test = blessed $_[0] ? $_[0] : HTML::HTML5::DOMutil::Feature->new(@_);
51
0
grep match::simple::match($_, $test), @FEATURES;
52
}
53
54
sub registerFeature
55
{
56
0
0
my ($class, $feature) = @_;
57
0
push @FEATURES, $feature;
58
0
$feature->install_subs;
59
}
60
61
sub parseString
62
{
63
0
0
my ($self, $string, %options) = @_;
64
0
0
my $pclass = $options{using} =~ /libxml/i ? 'XML::LibXML' : 'HTML::HTML5::Parser';
65
0
my $dom = $pclass->new->parse_string($string);
66
0
XML::LibXML::Augment->upgrade($dom);
67
0
return $dom;
68
}
69
70
sub parse
71
{
72
0
0
my ($self, $file, %options) = @_;
73
0
0
my $pclass = $options{using} =~ /libxml/i ? 'XML::LibXML' : 'HTML::HTML5::Parser';
74
0
0
my $dom = IO::Detect::is_filehandle $file
75
? $pclass->new->parse_fh($file)
76
: $pclass->new->parse_file($file);
77
0
XML::LibXML::Augment->upgrade($dom);
78
0
return $dom;
79
}
80
81
sub createDocument
82
{
83
0
0
my $self = shift;
84
0
0
0
die "Can only be used to create HTML documents."
85
unless (shift//XHTML_NS) eq XHTML_NS;
86
0
0
0
die "Can only be used to create HTML documents."
87
unless lc(shift//'html') eq 'html';
88
0
0
my $dtd = shift//$self->createDocumentType;
89
0
0
$dtd = $dtd->toString if ref $dtd;
90
0
my $html = "$dtd";
91
0
my $dom = $self->parseString($html);
92
0
$dom->setURI('about:blank');
93
0
return $dom;
94
}
95
96
sub createDocumentType
97
{
98
0
0
my ($self, $qname, $public, $system) = @_;
99
0
0
$qname ||= 'html';
100
101
0
0
0
if ($public and $system)
0
0
102
{
103
0
return sprintf('', $qname, $public, $system);
104
}
105
106
elsif ($public)
107
{
108
0
return sprintf('', $qname, $public);
109
}
110
111
elsif ($system)
112
{
113
0
return sprintf('', $qname, $system);
114
}
115
116
0
return sprintf('', $qname);
117
}
118
}
119
120
{ package HTML::HTML5::DOMutil::AutoDoc;
121
122
2
2
55
use 5.010;
2
6
2
287
123
2
2
14
use strict qw(vars subs);
2
4
2
1110
124
2
2
14
use mro 'c3';
2
4
2
19
125
126
BEGIN {
127
2
2
644
$HTML::HTML5::DOMutil::AutoDoc::AUTHORITY = 'cpan:TOBYINK';
128
2
38
$HTML::HTML5::DOMutil::AutoDoc::VERSION = '0.002';
129
};
130
131
2
2
2695
use Capture::Attribute;
2
309034
2
15
132
133
sub psay
134
{
135
0
0
foreach my $line (@_)
136
{
137
0
say $line;
138
0
say "";
139
}
140
}
141
142
sub add
143
{
144
0
0
my ($class, $package, $sub, $doc) = @_;
145
0
my $docs = \%{"$package\::DOCUMENTATION"};
0
146
0
$docs->{$sub} = $doc;
147
}
148
149
sub pod_for :Capture
150
{
151
0
0
my ($class, $package) = @_;
152
153
0
0
my ($interface) = ($package =~ m{ :: ([^:]+) $ }x);
154
155
0
0
psay
156
q{=head1 NAME},
157
"$package - implementation of the $interface interface of the HTML DOM";
158
0
0
psay
159
q{=head1 DESCRIPTION},
160
"$package is an implementation of the $interface interface of the HTML DOM. See L for a list of the conventions that have been used when translating the DOM to Perl.";
161
162
0
0
foreach my $s (qw/_pod_elements _pod_isa _pod_methods/)
163
{
164
0
0
print $class->$s($package);
165
}
166
167
psay
168
0
0
q{=head1 BUGS},
169
q{L.},
170
q{=head1 SEE ALSO},
171
q{L.},
172
q{=head1 AUTHOR},
173
q{Toby Inkster Etobyink@cpan.orgE.},
174
q{=head1 COPYRIGHT AND LICENCE},
175
q{This software is copyright (c) 2012, 2014 by Toby Inkster.},
176
q{This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.},
177
q{=head1 DISCLAIMER OF WARRANTIES},
178
q{THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.},
179
q{};
180
2
2
1253
}
2
5
2
20
181
182
sub _pod_elements :Capture
183
{
184
0
0
my ($class, $package) = @_;
185
186
0
0
psay
187
q{=head2 HTML Elements},
188
q{This class applies to the following HTML elements.},
189
q{=over};
190
191
0
0
my $elements = \@{"$package\::ELEMENTS"};
0
0
192
193
0
0
foreach my $element (sort @$elements)
194
{
195
0
0
psay qq{=item * C<< $element >>};
196
}
197
198
0
0
psay q{=back};
199
2
2
1202
}
2
4
2
9
200
201
sub _pod_isa :Capture
202
{
203
0
0
my ($class, $package) = @_;
204
205
0
0
psay
206
q{=head2 Inheritance},
207
qq{$package inherits methods from the following Perl classes.},
208
q{=over};
209
210
0
0
foreach my $parent (@{ mro::get_linear_isa($package) })
0
0
211
{
212
0
0
0
next if $parent eq $package;
213
0
0
psay qq{=item * L<$parent>};
214
}
215
216
0
0
psay q{=back};
217
2
2
906
}
2
4
2
10
218
219
sub _pod_methods :Capture
220
{
221
0
0
my ($class, $package) = @_;
222
223
0
0
my $docs = \%{"$package\::DOCUMENTATION"};
0
0
224
225
0
0
0
unless (keys %$docs)
226
{
227
0
0
psay
228
q{=head2 Additional Methods},
229
q{This class provides no additional methods over those it inherits.},
230
q{It is mostly pointless, but its existance is required by the HTML DOM.};
231
0
0
return;
232
}
233
234
psay
235
0
0
q{=head2 Additional Methods},
236
q{As well as its inherited methods, this class provides the following methods.},
237
q{=over};
238
239
0
0
foreach my $meth (sort keys %$docs)
240
{
241
0
0
psay
242
qq{=item * C<< $meth >>},
243
$docs->{$meth};
244
}
245
246
0
0
psay q{=back};
247
2
2
1048
}
2
5
2
9
248
}
249
250
{ package HTML::HTML5::DOMutil::Feature;
251
252
BEGIN {
253
2
2
426
$HTML::HTML5::DOMutil::Feature::AUTHORITY = 'cpan:TOBYINK';
254
2
42
$HTML::HTML5::DOMutil::Feature::VERSION = '0.002';
255
};
256
257
2
2
9
use strict qw(vars subs);
2
4
2
73
258
2
2
16
use Carp qw[carp];
2
3
2
687
259
2
2
13
use Scalar::Util qw[blessed];
2
4
2
171
260
use overload
261
q[~~] => 'smart_match',
262
q[""] => 'to_string',
263
0
0
0
q[bool] => sub { 1 },
264
2
21
fallback => 1,
265
2
2
11
;
2
3
266
267
sub new
268
{
269
0
0
my $class = shift;
270
0
0
die sprintf("Usage: %s->new(\$name, \$version)", __PACKAGE__) unless @_==2;
271
0
bless [@_], $class;
272
}
273
274
sub feature_name
275
{
276
0
0
lc(shift->[0]);
277
}
278
279
sub feature_version
280
{
281
0
0
0+(shift->[1]);
282
}
283
284
sub subs
285
{
286
0
0
my $self = shift;
287
0
@$self[2 .. $#$self];
288
}
289
290
sub add_sub
291
{
292
0
0
my ($self, $class, $name, $coderef) = @_;
293
0
push @$self, {
294
class => $class,
295
name => $name,
296
coderef => $coderef,
297
};
298
}
299
300
sub install_subs
301
{
302
0
0
my $self = shift;
303
0
for ($self->subs)
304
{
305
0
my ($class, $name, $coderef) = @$_{qw(class name coderef)};
306
0
0
$class = 'HTML::HTML5::DOM::'.$class unless $class =~ /::/;
307
0
0
if ($class->can($name))
308
{
309
0
carp "$class already has a method called $name. Not replacing.";
310
}
311
else
312
{
313
0
*{"$class\::$name"} = $coderef;
0
314
}
315
}
316
}
317
318
sub to_string
319
{
320
0
0
my $self = shift;
321
0
sprintf('%s %s', $self->feature_name, $self->feature_version);
322
}
323
324
sub smart_match
325
{
326
0
0
my ($self, $test, $swap) = @_;
327
0
0
($test, $self) = ($self, $test) if $swap;
328
329
0
0
my ($test_name, $test_version) = do {
330
0
0
0
if (blessed $test and $test->isa(__PACKAGE__))
0
331
0
{ ($test->feature_name, $test->feature_version) }
332
elsif (!ref $test)
333
0
{ split /\s+/, $test }
334
else
335
0
{ () }
336
} or return;
337
338
0
0
return unless $self->feature_name eq lc($test_name);
339
0
0
0
return if defined $test_version and $test_version > $self->feature_version;
340
0
return 1;
341
}
342
}
343
344
{ package HTML::HTML5::DOMutil::FancyISA;
345
346
2
2
2214
use 5.010;
2
7
2
575
347
2
2
13
use strict qw(vars subs);
2
5
2
70
348
2
2
11
use mro 'c3';
2
3
2
15
349
350
BEGIN {
351
2
2
115
$HTML::HTML5::DOMutil::FancyISA::AUTHORITY = 'cpan:TOBYINK';
352
2
203
$HTML::HTML5::DOMutil::FancyISA::VERSION = '0.002';
353
};
354
355
2
2
6666
use Object::AUTHORITY ();
0
0
356
*AUTHORITY = \&Object::AUTHORITY::AUTHORITY;
357
358
sub isa
359
{
360
my ($self, $isa) = @_;
361
362
if ($isa !~ m{::}
363
and $self->SUPER::isa('XML::LibXML::Element')
364
and $self->tagName eq $isa) {
365
return 1;
366
}
367
368
$isa =~ s/^-/HTML::HTML5::DOM::/;
369
return $self->SUPER::isa($isa);
370
}
371
}
372
373
{ package HTML::HTML5::DOM::HTMLDocument;
374
375
use 5.010;
376
use strict qw(vars subs);
377
use mro 'c3';
378
379
BEGIN {
380
$HTML::HTML5::DOM::HTMLDocument::AUTHORITY = 'cpan:TOBYINK';
381
$HTML::HTML5::DOM::HTMLDocument::VERSION = '0.002';
382
};
383
384
use base qw/HTML::HTML5::DOMutil::FancyISA/;
385
use XML::LibXML::Augment 0
386
'-type' => 'Document',
387
'-names' => ['{'.HTML::HTML5::DOM->XHTML_NS.'}html'];
388
389
use Carp qw//;
390
391
foreach my $elem (qw/body head/)
392
{
393
*{$elem} = sub
394
{
395
my ($self) = @_;
396
my ($node1) = $self->getElementsByTagName($elem);
397
return $node1;
398
};
399
400
HTML::HTML5::DOMutil::AutoDoc->add(
401
__PACKAGE__,
402
$elem,
403
"Returns the document ${elem}.",
404
);
405
}
406
407
{
408
my @things = (
409
[ images => '//*[local-name()="img"]', 'images' ],
410
[ embeds => '//*[local-name()="embed"]', 'C<< >> elements' ],
411
[ plugins => '//*[local-name()="embed"]', 'C<< >> elements' ],
412
[ applets => '//*[(local-name()="applet") or (local-name()="object" and @codetype="application/java")]', 'C<< >> elements (and C<< >> elements)' ],
413
[ links => '//*[(local-name()="a" or local-name()="area") and @href]', 'C<< >> and C<< >> elements with an "href" attribute' ],
414
[ anchors => '//*[local-name()="a" and @name]', 'C<< >> with a "name" attribute' ],
415
[ forms => '//*[local-name()="form"]', 'forms' ],
416
[ scripts => '//*[local-name()="script"]', 'scripts' ],
417
[ p5_tables => '//*[local-name()="table"]', 'tables' ],
418
);
419
foreach my $x (@things)
420
{
421
*{$x->[0]} = sub
422
{
423
my ($self) = @_;
424
my (@nodes) = $self->findnodes($x->[1]);
425
wantarray ? @nodes : HTML::HTML5::DOM::HTMLCollection->new(@nodes);
426
};
427
HTML::HTML5::DOMutil::AutoDoc->add(
428
__PACKAGE__,
429
$x->[0],
430
"Returns all $x->[2] found in the document.",
431
);
432
}
433
}
434
435
sub compatMode
436
{
437
my ($self) = @_;
438
if (UNIVERSAL::can('HTML::HTML5::Parser', 'can'))
439
{
440
if (HTML::HTML5::Parser->can('compat_mode'))
441
{
442
my $mode = HTML::HTML5::Parser->compat_mode($self);
443
return $mode if $mode;
444
}
445
}
446
return;
447
}
448
449
HTML::HTML5::DOMutil::AutoDoc->add(
450
__PACKAGE__,
451
'compatMode',
452
"Returns the string 'quirks' or 'limited quirks' or undef.",
453
);
454
455
sub URL
456
{
457
my $self = shift;
458
$self->setURI(shift) if @_;
459
return URI->new($self->URI);
460
}
461
462
*documentURI = \&URL;
463
464
HTML::HTML5::DOMutil::AutoDoc->add(
465
__PACKAGE__,
466
'URL',
467
"Get/set the document's URL.",
468
);
469
470
HTML::HTML5::DOMutil::AutoDoc->add(
471
__PACKAGE__,
472
'documentURI',
473
"Alias for C.",
474
);
475
476
sub domain
477
{
478
(shift)->URL->host;
479
}
480
481
HTML::HTML5::DOMutil::AutoDoc->add(
482
__PACKAGE__,
483
'domain',
484
"The documents URL's host name.",
485
);
486
487
*cookie = *referrer = *referer = sub { q() };
488
489
HTML::HTML5::DOMutil::AutoDoc->add(
490
__PACKAGE__,
491
'cookie',
492
"Ostensibly returns cookies associated with the document, but in this implementation always returns an empty string.",
493
);
494
495
HTML::HTML5::DOMutil::AutoDoc->add(
496
__PACKAGE__,
497
'referrer',
498
"Ostensibly returns the HTTP referer for the document, but in this implementation always returns an empty string.",
499
);
500
501
HTML::HTML5::DOMutil::AutoDoc->add(
502
__PACKAGE__,
503
'referer',
504
"An alias for 'referrer' provided for the benefit of those who learnt to spell by reading HTTP RFCs.",
505
);
506
507
sub lastModified
508
{
509
return DateTime->now;
510
}
511
512
HTML::HTML5::DOMutil::AutoDoc->add(
513
__PACKAGE__,
514
'lastModified',
515
"Ostensibly returns the HTTP Last-Modified date for the document, but this implementation always returns the current date and time. Returns a L object.",
516
);
517
518
{
519
my $cs = HTML::HTML::Parser->can('charset');
520
521
sub charset
522
{
523
my $self = @_;
524
if (@_)
525
{
526
$self->setEncoding(@_);
527
}
528
return $self->encoding;
529
}
530
531
HTML::HTML5::DOMutil::AutoDoc->add(
532
__PACKAGE__,
533
'charset',
534
"Getter/setter for the document encoding.",
535
);
536
537
sub defaultCharset
538
{
539
return 'utf-8';
540
}
541
542
HTML::HTML5::DOMutil::AutoDoc->add(
543
__PACKAGE__,
544
'defaultCharset',
545
"Returns the string 'utf-8'.",
546
);
547
548
sub characterSet
549
{
550
return unless $cs;
551
return $cs->( shift );
552
}
553
554
HTML::HTML5::DOMutil::AutoDoc->add(
555
__PACKAGE__,
556
'characterSet',
557
"Returns the character set that the document was parsed as (if known). As C can be used as a setter, this is not necessarily the same as C.",
558
);
559
}
560
561
sub readyState
562
{
563
'complete';
564
}
565
566
HTML::HTML5::DOMutil::AutoDoc->add(
567
__PACKAGE__,
568
'lastModified',
569
"Ostensibly returns the current document readiness, but this implementation always returns the string 'complete'.",
570
);
571
572
sub title
573
{
574
my ($self) = @_;
575
my ($title) = $self->getElementsByTagName('title')->get_node(1)->textContent;
576
$title =~ s/\s+/ /g;
577
$title =~ s/(^\s|\s$)//g;
578
return $title;
579
}
580
581
HTML::HTML5::DOMutil::AutoDoc->add(
582
__PACKAGE__,
583
'title',
584
"Returns the document's title, from its C<< >> element, with a little whitespace canonicalisation.",
585
);
586
587
sub getElementById
588
{
589
my ($self, $id) = @_;
590
my @nodes = $self->findnodes("*[\@id=\"$id\"]");
591
return $nodes[0];
592
}
593
594
HTML::HTML5::DOMutil::AutoDoc->add(
595
__PACKAGE__,
596
'getElementById',
597
'The world-famous C method. The default XML::LibXML implementation of this does not work with HTML::HTML5::Parser documents, because HTML::HTML5::Parser lacks the ability to inform libxml which element to use as an ID. (libxml defaults to xml:id.) This implementation is XPath-based, thus slower.',
598
);
599
600
*getElementsById = \&getElementById; # common typo
601
602
sub xmlVersion
603
{
604
my $self = shift;
605
return undef
606
if defined HTML::HTML5::Parser->source_line($self);
607
return $self->version;
608
}
609
610
HTML::HTML5::DOMutil::AutoDoc->add(
611
__PACKAGE__,
612
'xmlVersion',
613
"Returrns undef for documents parsed using an HTML parser; 1.0 or 1.1 if parsed using libxml.",
614
);
615
616
our $AUTOLOAD;
617
sub AUTOLOAD
618
{
619
my $self = shift;
620
my ($func) = ($AUTOLOAD =~ m{ :: (\w+) $ }x);
621
if ($func)
622
{
623
my $coderef = HTML::HTML5::DOM::HTMLHtmlElement->can($func);
624
if ($coderef)
625
{
626
unshift @_, $self->documentElement;
627
goto $coderef;
628
}
629
}
630
Carp::croak "Method '$AUTOLOAD' could not be autoloaded";
631
}
632
633
HTML::HTML5::DOMutil::AutoDoc->add(
634
__PACKAGE__,
635
'AUTOLOAD',
636
"See L if you don't know the significance of the AUTOLOAD function. HTML::HTML5::DOM::HTMLDocument will pass through unknown menthods to the document's root element. So for example, C<< \$document->setAttribute >> will actually set an attribute on the document's root element.",
637
);
638
639
sub implementation { HTML::HTML5::DOM->getDOMImplementation }
640
641
HTML::HTML5::DOMutil::AutoDoc->add(
642
__PACKAGE__,
643
'implementation',
644
"Returns the same as HTML::HTML5::DOM->getDOMImplementation.",
645
);
646
647
sub xmlStandalone
648
{
649
my $self = shift;
650
$self->setStandalone(@_) if @_;
651
$self->standalone;
652
}
653
654
HTML::HTML5::DOMutil::AutoDoc->add(
655
__PACKAGE__,
656
'xmlStandalone',
657
"Called with an argument, acts as C; called without an argument, acts as C.",
658
);
659
660
sub strictErrorChecking { return; }
661
662
HTML::HTML5::DOMutil::AutoDoc->add(
663
__PACKAGE__,
664
'strictErrorChecking',
665
"DOM seems a little vague as to what exactly constitutes 'strict'. This returns false.",
666
);
667
668
*normalizeDocument = __PACKAGE__->can('normalize');
669
670
HTML::HTML5::DOMutil::AutoDoc->add(
671
__PACKAGE__,
672
'normalizeDocument',
673
"Alias for C.",
674
);
675
676
sub domConfig
677
{
678
state $domConfig = +{};
679
return $domConfig;
680
}
681
682
HTML::HTML5::DOMutil::AutoDoc->add(
683
__PACKAGE__,
684
'domConfig',
685
"Ostensibly an object representing settings which will be used when C is called. In practise, just returns an empty hashref that you can do with what you like.",
686
);
687
688
*renameNode =
689
*doctype =
690
*inputEncoding =
691
*xmlEncoding =
692
sub { die "TODO" };
693
694
HTML::HTML5::DOMutil::AutoDoc->add(
695
__PACKAGE__,
696
$_,
697
"This method is not implemented yet, but will eventually support the functionality defined in DOM Core 3.",
698
) for qw(renameNode doctype inputEncoding xmlEncoding);
699
}
700
701
{ package HTML::HTML5::DOM::HTMLCollection;
702
703
use 5.010;
704
use strict;
705
use mro 'c3';
706
707
BEGIN {
708
$HTML::HTML5::DOM::HTMLCollection::AUTHORITY = 'cpan:TOBYINK';
709
$HTML::HTML5::DOM::HTMLCollection::VERSION = '0.002';
710
};
711
712
use base qw/
713
XML::LibXML::NodeList
714
HTML::HTML5::DOMutil::FancyISA
715
/;
716
}
717
718
{ package HTML::HTML5::DOM::HTMLElement;
719
720
use 5.010;
721
use strict qw(vars subs);
722
use mro 'c3';
723
724
BEGIN {
725
$HTML::HTML5::DOM::HTMLElement::AUTHORITY = 'cpan:TOBYINK';
726
$HTML::HTML5::DOM::HTMLElement::VERSION = '0.002';
727
};
728
729
our @ELEMENTS;
730
BEGIN {
731
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
732
qw/abbr address article aside b bdi bdo cite code
733
dd dfn dt em figcaption figure footer header
734
hgroup i kbd mark nav noscript rp rt ruby s samp
735
section small strong sub summary sup u var wbr/;
736
}
737
738
use HTML::HTML5::Parser 0.110;
739
use HTML::HTML5::Writer 0.104;
740
use List::Util 0 qw//;
741
use Scalar::Util 0 qw//;
742
use HTTP::Request 6.00 qw//;
743
use XML::LibXML 1.91 qw/:all/;
744
use XML::LibXML::Augment 0 -names => [@ELEMENTS];
745
use XML::LibXML::QuerySelector 0;
746
747
use base qw/HTML::HTML5::DOMutil::FancyISA/;
748
749
sub _mk_attribute_accessors
750
{
751
my ($class, @attribs) = @_;
752
foreach (@attribs)
753
{
754
my ($subname, $xmlname, $type) = split /=/;
755
$xmlname ||= $subname;
756
757
if ($type eq 'LIST')
758
{
759
*{"$class\::$subname"} = sub
760
{
761
my $self = shift;
762
my $i = 1;
763
my %seen;
764
return
765
grep { not $seen{$_}++ } # filter out duplicates
766
grep { length $_ } # ignore nulls
767
split /\s+/, # space separated list
768
$self->getAttribute($xmlname);
769
};
770
HTML::HTML5::DOMutil::AutoDoc->add(
771
$class,
772
$subname,
773
sprintf(
774
'Splits C<< $elem->getAttribute("%s") >> into a list on whitespace.',
775
$xmlname,
776
),
777
);
778
}
779
elsif ($type eq 'URI' || $type eq 'URL')
780
{
781
*{"$class\::$subname"} = sub
782
{
783
my $elem = shift;
784
if (@_)
785
{
786
my $newval = shift;
787
defined $newval ?
788
$elem->setAttribute($xmlname, $newval) :
789
$elem->removeAttribute($xmlname);
790
}
791
my $base = $elem->baseURI // $elem->ownerDocument->URI;
792
return $base ?
793
URI->new_abs($elem->getAttribute($xmlname), $base):
794
URI->new($elem->getAttribute($xmlname));
795
};
796
HTML::HTML5::DOMutil::AutoDoc->add(
797
$class,
798
$subname,
799
sprintf(
800
'Called with no arguments, is a shortcut for C<< $elem->getAttribute("%s") >> but as a blessed L object. Called with a defined argument, acts as C. Called with undef as an argument, acts as C.',
801
$xmlname,
802
),
803
);
804
}
805
elsif ($type eq 'TEXT')
806
{
807
*{"$class\::$subname"} = sub
808
{
809
my $self = shift;
810
if (@_)
811
{
812
$self->removeChildNodes;
813
$self->appendText(join qq(\n), @_);
814
}
815
$self->textContent;
816
};
817
HTML::HTML5::DOMutil::AutoDoc->add(
818
$class,
819
$subname,
820
sprintf(
821
'Called with no arguments, acts as an alias for C<< $elem->textContent >>. Called with an arguments, sets the content for the element. Any existing content will be overwritten. If multiple arguments are provided, they\'ll be joined using "\n".',
822
),
823
);
824
}
825
elsif ($type eq 'boolean')
826
{
827
*{"$class\::$subname"} = sub
828
{
829
my $elem = shift;
830
if (@_)
831
{
832
my $newval = shift;
833
$newval ?
834
$elem->setAttribute($xmlname, $xmlname) :
835
$elem->removeAttribute($xmlname);
836
}
837
$elem->hasAttribute($xmlname)
838
};
839
HTML::HTML5::DOMutil::AutoDoc->add(
840
$class,
841
$subname,
842
sprintf(
843
'Called with no arguments, is a shortcut for C<< $elem->hasAttribute("%s") >>. If called with a true argument, will C; if called with a false argument will C.',
844
$xmlname,
845
),
846
);
847
}
848
else
849
{
850
*{"$class\::$subname"} = sub
851
{
852
my $elem = shift;
853
if (@_)
854
{
855
my $newval = shift;
856
defined $newval ?
857
$elem->setAttribute($xmlname, $newval) :
858
$elem->removeAttribute($xmlname);
859
}
860
$elem->{$xmlname}
861
};
862
HTML::HTML5::DOMutil::AutoDoc->add(
863
$class,
864
$subname,
865
sprintf(
866
'Called with no arguments, is a shortcut for C<< $elem->getAttribute("%s") >>. Called with a defined argument, acts as C. Called with undef as an argument, acts as C.',
867
$xmlname,
868
),
869
);
870
}
871
}
872
}
873
874
sub _mk_url_decomposition
875
{
876
my ($class, $via, $bits) = @_;
877
$via ||= 'href';
878
$bits ||= {
879
protocol => 'scheme',
880
host => 'host_port',
881
hostname => 'host',
882
port => 'port',
883
pathname => 'path',
884
search => 'query',
885
hash => 'fragment',
886
};
887
foreach my $bit (keys %$bits)
888
{
889
my $method = $bits->{$bit};
890
*{"$class\::$bit"} = sub { (shift)->$via->$method };
891
HTML::HTML5::DOMutil::AutoDoc->add(
892
$class,
893
$bit,
894
sprintf(
895
'A shortcut for C<< $elem->%s->%s >>. (Does not act as a setter.)',
896
$via,
897
$method,
898
),
899
);
900
}
901
}
902
903
sub _mk_labels_method
904
{
905
my ($class, $subname) = @_;
906
$subname ||= 'labels';
907
908
*{"$class\::$subname"} = sub {
909
my $self = shift;
910
my @labels = grep
911
{ $_->can('control') && $_->control eq $self }
912
$self->ownerDocument->getElementsByTagName('label');
913
return wantarray ? @labels : XML::LibXML::NodeList->new(@labels);
914
};
915
916
HTML::HTML5::DOMutil::AutoDoc->add(
917
$class,
918
$subname,
919
'A list of C<< >> elements which label this element.',
920
);
921
}
922
923
sub _mk_follow_method
924
{
925
my ($class, $subname, $via) = @_;
926
$subname ||= 'p5_follow';
927
$via ||= 'href';
928
929
*{"$class\::$subname"} = sub {
930
my $self = shift;
931
my $url = $self->$via;
932
return HTTP::Request->new(GET => "$url");
933
};
934
935
HTML::HTML5::DOMutil::AutoDoc->add(
936
$class,
937
$subname,
938
sprintf('Shortcut for C<< HTTP::Request->new(GET => $elem->%s) >>', $via),
939
);
940
}
941
942
sub _mk_form_methods
943
{
944
my ($class, $todo) = @_;
945
$todo ||= sub { 1 };
946
947
if (match::simple::match('form', $todo))
948
{
949
*{"$class\::form"} = sub
950
{
951
my $self = shift;
952
if ($self->hasAttribute('form'))
953
{
954
my $form = $self->documentElement->getElementById(
955
$self->getAttribute('form'));
956
return $form if $form;
957
}
958
return
959
List::Util::first { $_->nodeName eq 'form' }
960
$self->p5_ancestors;
961
};
962
HTML::HTML5::DOMutil::AutoDoc->add(
963
$class,
964
'form',
965
'Returns the "form owner" for this element.',
966
);
967
}
968
969
foreach my $x (qw/Action Enctype Method NoValidate Target/)
970
{
971
next unless match::simple::match(lc("form$x"), $todo);
972
973
*{"$class\::form$x"} = sub
974
{
975
my $self = shift;
976
if ($self->hasAttribute(lc "form$x"))
977
{
978
return $self->getAttribute(lc "form$x")
979
}
980
return $self->form->getAttribute(lc $x);
981
};
982
HTML::HTML5::DOMutil::AutoDoc->add(
983
$class,
984
'form',
985
sprintf('Returns the "form%s" attribute for this element if it exists, or otherwise the "%s" attribute of this element\'s form owner.', lc $x, lc $x),
986
);
987
}
988
}
989
990
sub getElementById
991
{
992
my ($self, $id) = @_;
993
my @nodes = $self->findnodes("*[\@id=\"$id\"]");
994
return $nodes[0];
995
}
996
997
HTML::HTML5::DOMutil::AutoDoc->add(
998
__PACKAGE__,
999
'getElementById',
1000
'The world-famous C method. The default XML::LibXML implementation of this does not work with HTML::HTML5::Parser documents, because HTML::HTML5::Parser lacks the ability to inform libxml which element to use as an ID. (libxml defaults to xml:id.) This implementation is XPath-based, thus slower.',
1001
);
1002
1003
*getElementsById = \&getElementById; # common typo
1004
1005
sub getElementsByClassName
1006
{
1007
my $self = shift;
1008
my $conditions = join q{ or },
1009
map { "contains(concat(' ', normalize-space(\@class), ' '), ' $_ ')" }
1010
@_;
1011
my @rv = $self->findnodes("*[$conditions]");
1012
return wantarray ? @rv : HTML::HTML5::DOM::HTMLCollection->new(@rv);
1013
}
1014
1015
HTML::HTML5::DOMutil::AutoDoc->add(
1016
__PACKAGE__,
1017
'getElementsByClassName',
1018
'Given one or more class names, returns a list of elements bearing those classes.',
1019
);
1020
1021
sub outerHTML
1022
{
1023
my $self = shift;
1024
1025
if (@_)
1026
{
1027
my $parser = HTML::HTML5::Parser->new;
1028
if ($self->parentNode and $self->parentNode->nodeType==XML_ELEMENT_NODE)
1029
{
1030
my @nodes = $parser->parse_balanced_chunk(
1031
(join qq(\n), @_),
1032
{ within => $self->parentNode->nodeName, as => 'list' },
1033
);
1034
$self->parentNode->insertBefore($_, $self) for @nodes;
1035
$self->parentNode->removeChild($self);
1036
}
1037
else
1038
{
1039
$self
1040
-> ownerDocument
1041
-> setDocumentElement(
1042
$parser->parse_string(join qq(\n), @_)->documentElement
1043
);
1044
}
1045
return join qq(\n), @_;
1046
}
1047
1048
my $writer = HTML::HTML5::Writer->new(markup => 'html', polyglot => 1);
1049
$writer->element($self);
1050
}
1051
1052
HTML::HTML5::DOMutil::AutoDoc->add(
1053
__PACKAGE__,
1054
'outerHTML',
1055
'As per innerHTML, but includes the element itself. Can be used as a setter, but that\'s a bit of a weird thing to do.',
1056
);
1057
1058
sub innerHTML
1059
{
1060
my $self = shift;
1061
if (@_)
1062
{
1063
my $parser = HTML::HTML5::Parser->new;
1064
my @nodes = $parser->parse_balanced_chunk(
1065
(join qq(\n), @_),
1066
{ within => $self->nodeName, as => 'list' },
1067
);
1068
$self->removeChildNodes;
1069
$self->appendChild($_) for @nodes;
1070
}
1071
1072
my $writer;
1073
join q{},
1074
map
1075
{
1076
$writer ||= HTML::HTML5::Writer->new(markup => 'html', polyglot => 1);
1077
1078
if ($_->nodeType == XML_ELEMENT_NODE)
1079
{
1080
$writer->element($_)
1081
}
1082
elsif ($_->nodeType == XML_TEXT_NODE)
1083
{
1084
$writer->text($_)
1085
}
1086
else
1087
{
1088
$_->toString
1089
}
1090
}
1091
$self->childNodes
1092
}
1093
1094
HTML::HTML5::DOMutil::AutoDoc->add(
1095
__PACKAGE__,
1096
'innerHTML',
1097
'When called without arguments, serialises the contents of the element (but not the element itself) to a single string. When called with a string argument, parses the string as HTML and uses it to set the content of this element. When possible, attempts to use polyglot HTML (i.e. markup that works as HTML and XHTML).',
1098
);
1099
1100
sub p5_ancestors
1101
{
1102
my ($self) = @_;
1103
my $x = $self->parentNode;
1104
my @rv;
1105
while (defined $x and Scalar::Util::blessed $x and $x->isa('XML::LibXML::Element'))
1106
{
1107
push @rv, $x;
1108
$x = $x->parentNode;
1109
}
1110
return wantarray ? @rv : HTML::HTML5::DOM::HTMLCollection->new(@rv);
1111
}
1112
1113
HTML::HTML5::DOMutil::AutoDoc->add(
1114
__PACKAGE__,
1115
'p5_ancestors',
1116
'Returns a (Perl or XML::LibXML::NodeList) list of this element\'s ancestors - i.e. the parentNode, the parentNode of the parentNode, etc.',
1117
);
1118
1119
sub p5_contains
1120
{
1121
my ($self, $thing) = @_;
1122
my @results = grep {
1123
$_ == $self
1124
} $thing->p5_ancestors;
1125
return 1 if @results;
1126
return;
1127
}
1128
1129
HTML::HTML5::DOMutil::AutoDoc->add(
1130
__PACKAGE__,
1131
'p5_contains',
1132
'Given an argument, returns true if that argument is an element nested within this element.',
1133
);
1134
1135
__PACKAGE__->_mk_attribute_accessors(qw/
1136
id
1137
title lang translate==boolean dir className=class
1138
hidden==boolean tabIndex=tabindex accessKey=accesskey
1139
classList=class=LIST
1140
/);
1141
1142
sub dataset
1143
{
1144
my $self = shift;
1145
my %rv;
1146
foreach my $attr ($self->attributes)
1147
{
1148
if ($attr->nodeName =~ /^data-[^A-Z]$/)
1149
{
1150
my $key = $1;
1151
$key =~ s{ \- ([a-z]) }{ uc('-'.$1) }gex;
1152
$rv{$key} = $attr->value;
1153
}
1154
}
1155
return \%rv;
1156
}
1157
1158
HTML::HTML5::DOMutil::AutoDoc->add(
1159
__PACKAGE__,
1160
'dataset',
1161
'Gets a hashref based on C<< data-foo >> attributes. This is currently read-only, but in future may be implemented as a tied hash to allow read/write access.',
1162
);
1163
1164
sub XML::LibXML::Node::_p5_numericPath
1165
{
1166
join q{:},
1167
map { sprintf('%09d', $_) }
1168
map {
1169
if (m{^[*]\[(\d+)]$}) { $1; }
1170
elsif (m{^[*]$}) { 0; }
1171
elsif (m{^$}) { 0; }
1172
else { 999_999_999 }
1173
}
1174
split m{/}, (shift)->nodePath;
1175
}
1176
1177
sub compareDocumentPosition
1178
{
1179
my ($self, $other) = @_;
1180
$self->_p5_numericPath cmp $other->_p5_numericPath;
1181
}
1182
1183
HTML::HTML5::DOMutil::AutoDoc->add(
1184
__PACKAGE__,
1185
'compareDocumentPosition',
1186
'Compares this node with another based on document order.',
1187
);
1188
1189
*getUserData =
1190
*setUserData =
1191
sub { die "TODO" };
1192
1193
HTML::HTML5::DOMutil::AutoDoc->add(
1194
__PACKAGE__,
1195
$_,
1196
'Not implemented - perhaps never will be. Try C instead.',
1197
) for qw( getUserData setUserData );
1198
1199
sub getFeature { (shift)->ownerDocument->implementation->getFeature(@_) }
1200
1201
HTML::HTML5::DOMutil::AutoDoc->add(
1202
__PACKAGE__,
1203
'getFeature',
1204
'Acts as a shortcut for C<< $element->ownerDocument->implementation->getFeature >>.',
1205
);
1206
1207
sub isDefaultNamespace { my $self = shift; !$self->lookupNamespacePrefix("".shift) }
1208
1209
HTML::HTML5::DOMutil::AutoDoc->add(
1210
__PACKAGE__,
1211
'isDefaultNamespace',
1212
'Given a URI, returns true if that is the default namespace prefix.',
1213
);
1214
1215
*lookupPrefix = XML::LibXML::Augment::Element->can('lookupNamespacePrefix');
1216
1217
HTML::HTML5::DOMutil::AutoDoc->add(
1218
__PACKAGE__,
1219
'lookupPrefix',
1220
'Alias for C.',
1221
);
1222
1223
sub isSupported { (shift)->ownerDocument->implementation->hasFeature(@_) }
1224
1225
HTML::HTML5::DOMutil::AutoDoc->add(
1226
__PACKAGE__,
1227
'isSupported',
1228
'Acts as a shortcut for C<< $element->ownerDocument->implementation->hasFeature >>.',
1229
);
1230
1231
*schemaTypeInfo =
1232
*setIdAttribute =
1233
*setIdAttributeNS =
1234
*setIdAttributeNode =
1235
sub { die "TODO" };
1236
1237
HTML::HTML5::DOMutil::AutoDoc->add(
1238
__PACKAGE__,
1239
$_,
1240
'Not implemented.',
1241
) for qw( schemaTypeInfo setIdAttribute setIdAttributeNS setIdAttributeNode );
1242
}
1243
1244
{ package HTML::HTML5::DOM::HTMLUnknownElement;
1245
1246
use 5.010;
1247
use strict qw(vars subs);
1248
use mro 'c3';
1249
1250
BEGIN {
1251
$HTML::HTML5::DOM::HTMLUnknownElement::AUTHORITY = 'cpan:TOBYINK';
1252
$HTML::HTML5::DOM::HTMLUnknownElement::VERSION = '0.002';
1253
};
1254
1255
our @ELEMENTS;
1256
BEGIN {
1257
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1258
qw/*/;
1259
}
1260
1261
use XML::LibXML::Augment 0
1262
-names => [@ELEMENTS],
1263
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1264
}
1265
1266
{ package HTML::HTML5::DOM::HTMLAnchorElement;
1267
1268
use 5.010;
1269
use strict qw(vars subs);
1270
use mro 'c3';
1271
1272
BEGIN {
1273
$HTML::HTML5::DOM::HTMLAnchorElement::AUTHORITY = 'cpan:TOBYINK';
1274
$HTML::HTML5::DOM::HTMLAnchorElement::VERSION = '0.002';
1275
};
1276
1277
our @ELEMENTS;
1278
BEGIN {
1279
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) } qw/a/;
1280
}
1281
1282
use XML::LibXML::Augment 0
1283
-names => [@ELEMENTS],
1284
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1285
1286
__PACKAGE__->_mk_attribute_accessors(qw/
1287
href==URI target rel rev media hreflang target type
1288
relList=rel=LIST revList=rev=LIST text==TEXT
1289
name
1290
/);
1291
__PACKAGE__->_mk_url_decomposition;
1292
__PACKAGE__->_mk_follow_method;
1293
}
1294
1295
{ package HTML::HTML5::DOM::HTMLAreaElement;
1296
1297
use 5.010;
1298
use strict qw(vars subs);
1299
use mro 'c3';
1300
1301
BEGIN {
1302
$HTML::HTML5::DOM::HTMLAreaElement::AUTHORITY = 'cpan:TOBYINK';
1303
$HTML::HTML5::DOM::HTMLAreaElement::VERSION = '0.002';
1304
};
1305
1306
our @ELEMENTS;
1307
BEGIN {
1308
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1309
qw/area/;
1310
}
1311
1312
use XML::LibXML::Augment 0
1313
-names => [@ELEMENTS],
1314
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1315
1316
__PACKAGE__->_mk_attribute_accessors(qw/
1317
alt coords shape href==URI target rel rev media hreflang type
1318
relList=rel=LIST revList=rev=LIST
1319
/);
1320
__PACKAGE__->_mk_url_decomposition;
1321
__PACKAGE__->_mk_follow_method;
1322
}
1323
1324
{ package HTML::HTML5::DOM::HTMLAudioElement;
1325
1326
use 5.010;
1327
use strict qw(vars subs);
1328
use mro 'c3';
1329
1330
BEGIN {
1331
$HTML::HTML5::DOM::HTMLAudioElement::AUTHORITY = 'cpan:TOBYINK';
1332
$HTML::HTML5::DOM::HTMLAudioElement::VERSION = '0.002';
1333
};
1334
1335
our @ELEMENTS;
1336
BEGIN {
1337
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1338
qw/audio/;
1339
}
1340
1341
use XML::LibXML::Augment 0
1342
-names => [@ELEMENTS],
1343
-isa => ['HTML::HTML5::DOM::HTMLMediaElement'];
1344
}
1345
1346
{ package HTML::HTML5::DOM::HTMLMediaElement;
1347
1348
use 5.010;
1349
use strict qw(vars subs);
1350
use mro 'c3';
1351
1352
BEGIN {
1353
$HTML::HTML5::DOM::HTMLMediaElement::AUTHORITY = 'cpan:TOBYINK';
1354
$HTML::HTML5::DOM::HTMLMediaElement::VERSION = '0.002';
1355
};
1356
1357
our @ELEMENTS;
1358
BEGIN {
1359
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1360
qw//;
1361
}
1362
1363
use XML::LibXML::Augment 0
1364
-names => [@ELEMENTS],
1365
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1366
1367
__PACKAGE__->_mk_attribute_accessors(qw/
1368
src==URI crossOrigin=crossorigin preload controls
1369
/);
1370
__PACKAGE__->_mk_follow_method('src');
1371
}
1372
1373
{ package HTML::HTML5::DOM::HTMLBaseElement;
1374
1375
use 5.010;
1376
use strict qw(vars subs);
1377
use mro 'c3';
1378
1379
BEGIN {
1380
$HTML::HTML5::DOM::HTMLBaseElement::AUTHORITY = 'cpan:TOBYINK';
1381
$HTML::HTML5::DOM::HTMLBaseElement::VERSION = '0.002';
1382
};
1383
1384
our @ELEMENTS;
1385
BEGIN {
1386
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1387
qw/base/;
1388
}
1389
1390
use XML::LibXML::Augment 0
1391
-names => [@ELEMENTS],
1392
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1393
1394
__PACKAGE__->_mk_attribute_accessors(qw/href==URI target/);
1395
__PACKAGE__->_mk_url_decomposition;
1396
}
1397
1398
{ package HTML::HTML5::DOM::HTMLQuoteElement;
1399
1400
use 5.010;
1401
use strict qw(vars subs);
1402
use mro 'c3';
1403
1404
BEGIN {
1405
$HTML::HTML5::DOM::HTMLQuoteElement::AUTHORITY = 'cpan:TOBYINK';
1406
$HTML::HTML5::DOM::HTMLQuoteElement::VERSION = '0.002';
1407
};
1408
1409
our @ELEMENTS;
1410
BEGIN {
1411
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1412
qw/blockquote q/;
1413
}
1414
1415
use XML::LibXML::Augment 0
1416
-names => [@ELEMENTS],
1417
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1418
1419
__PACKAGE__->_mk_attribute_accessors(qw/cite==URI/);
1420
}
1421
1422
{ package HTML::HTML5::DOM::HTMLBodyElement;
1423
1424
use 5.010;
1425
use strict qw(vars subs);
1426
use mro 'c3';
1427
1428
BEGIN {
1429
$HTML::HTML5::DOM::HTMLBodyElement::AUTHORITY = 'cpan:TOBYINK';
1430
$HTML::HTML5::DOM::HTMLBodyElement::VERSION = '0.002';
1431
};
1432
1433
our @ELEMENTS;
1434
BEGIN {
1435
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1436
qw/body/;
1437
}
1438
1439
use XML::LibXML::Augment 0
1440
-names => [@ELEMENTS],
1441
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1442
}
1443
1444
{ package HTML::HTML5::DOM::HTMLBRElement;
1445
1446
use 5.010;
1447
use strict qw(vars subs);
1448
use mro 'c3';
1449
1450
BEGIN {
1451
$HTML::HTML5::DOM::HTMLBRElement::AUTHORITY = 'cpan:TOBYINK';
1452
$HTML::HTML5::DOM::HTMLBRElement::VERSION = '0.002';
1453
};
1454
1455
our @ELEMENTS;
1456
BEGIN {
1457
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1458
qw/br/;
1459
}
1460
1461
use XML::LibXML::Augment 0
1462
-names => [@ELEMENTS],
1463
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1464
}
1465
1466
{ package HTML::HTML5::DOM::HTMLButtonElement;
1467
1468
use 5.010;
1469
use strict qw(vars subs);
1470
use mro 'c3';
1471
1472
BEGIN {
1473
$HTML::HTML5::DOM::HTMLButtonElement::AUTHORITY = 'cpan:TOBYINK';
1474
$HTML::HTML5::DOM::HTMLButtonElement::VERSION = '0.002';
1475
};
1476
1477
our @ELEMENTS;
1478
BEGIN {
1479
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1480
qw/button/;
1481
}
1482
1483
use XML::LibXML::Augment 0
1484
-names => [@ELEMENTS],
1485
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1486
1487
__PACKAGE__->_mk_attribute_accessors(qw/autofocus disabled name type value/);
1488
__PACKAGE__->_mk_labels_method;
1489
__PACKAGE__->_mk_form_methods;
1490
}
1491
1492
{ package HTML::HTML5::DOM::HTMLCanvasElement;
1493
1494
use 5.010;
1495
use strict qw(vars subs);
1496
use mro 'c3';
1497
1498
BEGIN {
1499
$HTML::HTML5::DOM::HTMLCanvasElement::AUTHORITY = 'cpan:TOBYINK';
1500
$HTML::HTML5::DOM::HTMLCanvasElement::VERSION = '0.002';
1501
};
1502
1503
our @ELEMENTS;
1504
BEGIN {
1505
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1506
qw/canvas/;
1507
}
1508
1509
use XML::LibXML::Augment 0
1510
-names => [@ELEMENTS],
1511
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1512
1513
__PACKAGE__->_mk_attribute_accessors(qw/height width/);
1514
}
1515
1516
{ package HTML::HTML5::DOM::HTMLTableCaptionElement;
1517
1518
use 5.010;
1519
use strict qw(vars subs);
1520
use mro 'c3';
1521
1522
BEGIN {
1523
$HTML::HTML5::DOM::HTMLTableCaptionElement::AUTHORITY = 'cpan:TOBYINK';
1524
$HTML::HTML5::DOM::HTMLTableCaptionElement::VERSION = '0.002';
1525
};
1526
1527
our @ELEMENTS;
1528
BEGIN {
1529
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1530
qw/caption/;
1531
}
1532
1533
use XML::LibXML::Augment 0
1534
-names => [@ELEMENTS],
1535
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1536
}
1537
1538
{ package HTML::HTML5::DOM::HTMLTableColElement;
1539
1540
use 5.010;
1541
use strict qw(vars subs);
1542
use mro 'c3';
1543
1544
BEGIN {
1545
$HTML::HTML5::DOM::HTMLTableColElement::AUTHORITY = 'cpan:TOBYINK';
1546
$HTML::HTML5::DOM::HTMLTableColElement::VERSION = '0.002';
1547
};
1548
1549
our @ELEMENTS;
1550
BEGIN {
1551
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1552
qw/col colgroup/;
1553
}
1554
1555
use XML::LibXML::Augment 0
1556
-names => [@ELEMENTS],
1557
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1558
1559
sub span
1560
{
1561
my $self = shift;
1562
1563
if (@_)
1564
{
1565
my $set = shift;
1566
int($set) > 0
1567
? $self->setAttribute(span => int($set))
1568
: $self->removeAttribute('span')
1569
}
1570
1571
my $span = $self->getAttribute('span');
1572
int($span) > 0 ? int($span) : 1;
1573
}
1574
1575
HTML::HTML5::DOMutil::AutoDoc->add(
1576
__PACKAGE__,
1577
span => 'Accessor for the C<< span >> attribute. Must always be a positive integer.',
1578
);
1579
}
1580
1581
{ package HTML::HTML5::DOM::HTMLCommandElement;
1582
1583
use 5.010;
1584
use strict qw(vars subs);
1585
use mro 'c3';
1586
1587
BEGIN {
1588
$HTML::HTML5::DOM::HTMLCommandElement::AUTHORITY = 'cpan:TOBYINK';
1589
$HTML::HTML5::DOM::HTMLCommandElement::VERSION = '0.002';
1590
};
1591
1592
our @ELEMENTS;
1593
BEGIN {
1594
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1595
qw/command/;
1596
}
1597
1598
use XML::LibXML::Augment 0
1599
-names => [@ELEMENTS],
1600
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1601
1602
__PACKAGE__->_mk_attribute_accessors(qw/
1603
type label icon==URI disabled==boolean checked==boolean radiogroup
1604
/);
1605
}
1606
1607
{ package HTML::HTML5::DOM::HTMLDataListElement;
1608
1609
use 5.010;
1610
use strict qw(vars subs);
1611
use mro 'c3';
1612
1613
BEGIN {
1614
$HTML::HTML5::DOM::HTMLDataListElement::AUTHORITY = 'cpan:TOBYINK';
1615
$HTML::HTML5::DOM::HTMLDataListElement::VERSION = '0.002';
1616
};
1617
1618
our @ELEMENTS;
1619
BEGIN {
1620
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1621
qw/datalist/;
1622
}
1623
1624
use XML::LibXML::Augment 0
1625
-names => [@ELEMENTS],
1626
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1627
1628
sub options
1629
{
1630
my ($self) = @_;
1631
return $self->getElementsByTagName('option');
1632
}
1633
}
1634
1635
{ package HTML::HTML5::DOM::HTMLModElement;
1636
1637
use 5.010;
1638
use strict qw(vars subs);
1639
use mro 'c3';
1640
1641
BEGIN {
1642
$HTML::HTML5::DOM::HTMLModElement::AUTHORITY = 'cpan:TOBYINK';
1643
$HTML::HTML5::DOM::HTMLModElement::VERSION = '0.002';
1644
};
1645
1646
our @ELEMENTS;
1647
BEGIN {
1648
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1649
qw/del ins/;
1650
}
1651
1652
use XML::LibXML::Augment 0
1653
-names => [@ELEMENTS],
1654
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1655
1656
__PACKAGE__->_mk_attribute_accessors(qw/cite==URI dateTime=datetime=datetime/);
1657
}
1658
1659
{ package HTML::HTML5::DOM::HTMLDetailsElement;
1660
1661
use 5.010;
1662
use strict qw(vars subs);
1663
use mro 'c3';
1664
1665
BEGIN {
1666
$HTML::HTML5::DOM::HTMLDetailsElement::AUTHORITY = 'cpan:TOBYINK';
1667
$HTML::HTML5::DOM::HTMLDetailsElement::VERSION = '0.002';
1668
};
1669
1670
our @ELEMENTS;
1671
BEGIN {
1672
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1673
qw/details/;
1674
}
1675
1676
use XML::LibXML::Augment 0
1677
-names => [@ELEMENTS],
1678
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1679
1680
__PACKAGE__->_mk_attribute_accessors(qw/open==boolean/);
1681
}
1682
1683
{ package HTML::HTML5::DOM::HTMLDivElement;
1684
1685
use 5.010;
1686
use strict qw(vars subs);
1687
use mro 'c3';
1688
1689
BEGIN {
1690
$HTML::HTML5::DOM::HTMLDivElement::AUTHORITY = 'cpan:TOBYINK';
1691
$HTML::HTML5::DOM::HTMLDivElement::VERSION = '0.002';
1692
};
1693
1694
our @ELEMENTS;
1695
BEGIN {
1696
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1697
qw/div/;
1698
}
1699
1700
use XML::LibXML::Augment 0
1701
-names => [@ELEMENTS],
1702
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1703
}
1704
1705
{ package HTML::HTML5::DOM::HTMLDListElement;
1706
1707
use 5.010;
1708
use strict qw(vars subs);
1709
use mro 'c3';
1710
1711
BEGIN {
1712
$HTML::HTML5::DOM::HTMLDListElement::AUTHORITY = 'cpan:TOBYINK';
1713
$HTML::HTML5::DOM::HTMLDListElement::VERSION = '0.002';
1714
};
1715
1716
our @ELEMENTS;
1717
BEGIN {
1718
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1719
qw/dl/;
1720
}
1721
1722
use XML::LibXML::Augment 0
1723
-names => [@ELEMENTS],
1724
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1725
}
1726
1727
{ package HTML::HTML5::DOM::HTMLEmbedElement;
1728
1729
use 5.010;
1730
use strict qw(vars subs);
1731
use mro 'c3';
1732
1733
BEGIN {
1734
$HTML::HTML5::DOM::HTMLEmbedElement::AUTHORITY = 'cpan:TOBYINK';
1735
$HTML::HTML5::DOM::HTMLEmbedElement::VERSION = '0.002';
1736
};
1737
1738
our @ELEMENTS;
1739
BEGIN {
1740
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1741
qw/embed/;
1742
}
1743
1744
use XML::LibXML::Augment 0
1745
-names => [@ELEMENTS],
1746
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1747
1748
__PACKAGE__->_mk_attribute_accessors(qw/src==URI type height width/);
1749
}
1750
1751
{ package HTML::HTML5::DOM::HTMLFieldSetElement;
1752
1753
use 5.010;
1754
use strict qw(vars subs);
1755
use mro 'c3';
1756
1757
BEGIN {
1758
$HTML::HTML5::DOM::HTMLFieldSetElement::AUTHORITY = 'cpan:TOBYINK';
1759
$HTML::HTML5::DOM::HTMLFieldSetElement::VERSION = '0.002';
1760
};
1761
1762
our @ELEMENTS;
1763
BEGIN {
1764
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1765
qw/fieldset/;
1766
}
1767
1768
use XML::LibXML::Augment 0
1769
-names => [@ELEMENTS],
1770
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1771
1772
__PACKAGE__->_mk_attribute_accessors(qw/disabled==boolean name/);
1773
__PACKAGE__->_mk_form_methods([qw/form/]);
1774
1775
sub type
1776
{
1777
return 'fieldset';
1778
}
1779
1780
HTML::HTML5::DOMutil::AutoDoc->add(
1781
__PACKAGE__,
1782
'type',
1783
'Returns the string "fieldset". Kinda useless, but it is part of the HTML5 DOM.',
1784
);
1785
1786
sub elements
1787
{
1788
die "TODO";
1789
}
1790
1791
HTML::HTML5::DOMutil::AutoDoc->add(
1792
__PACKAGE__,
1793
'elements',
1794
'@@TODO - should return a list of C<< >>, C<< >>, etc elements nested inside this fieldset.',
1795
);
1796
}
1797
1798
{ package HTML::HTML5::DOM::HTMLFormElement;
1799
1800
use 5.010;
1801
use strict qw(vars subs);
1802
use mro 'c3';
1803
1804
BEGIN {
1805
$HTML::HTML5::DOM::HTMLFormElement::AUTHORITY = 'cpan:TOBYINK';
1806
$HTML::HTML5::DOM::HTMLFormElement::VERSION = '0.002';
1807
};
1808
1809
our @ELEMENTS;
1810
BEGIN {
1811
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
1812
qw/form/;
1813
}
1814
1815
use XML::LibXML::Augment 0
1816
-names => [@ELEMENTS],
1817
-isa => ['HTML::HTML5::DOM::HTMLElement'];
1818
1819
__PACKAGE__->_mk_attribute_accessors(qw/
1820
acceptCharset=accept-charset action==URI autocomplete enctype
1821
encoding method name noValidate=novalidate target
1822
/);
1823
1824
sub _get_elements
1825
{
1826
my ($self, $allowed) = @_;
1827
my $return = $self
1828
-> ownerDocument
1829
-> getElementsByTagName('*')
1830
-> grep(sub {
1831
match::simple::match($_->nodeName, $allowed)
1832
&& ($_->form == $self)
1833
})
1834
-> map(sub { XML::LibXML::Augment->rebless($_) });
1835
wantarray ?
1836
$return->get_nodelist :
1837
bless($return, 'HTML::HTML5::DOM::HTMLFormControlsCollection');
1838
}
1839
1840
sub elements
1841
{
1842
my $self = shift;
1843
@_ = ($self, [qw/button fieldset input keygen object output select textarea/]);
1844
goto \&_get_elements;
1845
}
1846
1847
HTML::HTML5::DOMutil::AutoDoc->add(
1848
__PACKAGE__,
1849
'elements',
1850
'Returns a list of form-related elements which this form owns. In list context this is a normal Perl list. In scalar context it is a HTML::HTML5::DOM::HTMLFormControlsCollection.',
1851
);
1852
1853
sub p5_submittableElements
1854
{
1855
my $self = shift;
1856
@_ = ($self, [qw/button input keygen object select textarea/]);
1857
goto \&_get_elements;
1858
}
1859
1860
HTML::HTML5::DOMutil::AutoDoc->add(
1861
__PACKAGE__,
1862
'p5_submittableElements',
1863
'Returns a list of form-related elements which this form owns that can potentially cause name=value pairs to be added to the form submission. (e.g. not C<< >>.) In list context this is a normal Perl list. In scalar context it is a HTML::HTML5::DOM::HTMLFormControlsCollection.',
1864
);
1865
1866
sub length
1867
{
1868
my $self = shift;
1869
return $self->elements->size;
1870
}
1871
1872
HTML::HTML5::DOMutil::AutoDoc->add(
1873
__PACKAGE__,
1874
'length',
1875
'The length of the C list.',
1876
);
1877
1878
sub submit
1879
{
1880
my ($self, $hashref) = @_;
1881
1882
my $method = (uc $self->method || 'GET');
1883
my $fields = $self->p5_submittableElements->p5_wwwFormUrlencoded($hashref);
1884
1885
if ($method eq 'GET')
1886
{
1887
return HTTP::Request->new(GET => $self->action.'?'.$fields)
1888
}
1889
1890
HTTP::Request->new(
1891
$method,
1892
$self->action,
1893
[ 'Content-Type' => $self->enctype || 'application/x-www-form-urlencoded' ],
1894
$fields,
1895
);
1896
}
1897
1898
HTML::HTML5::DOMutil::AutoDoc->add(
1899
__PACKAGE__,
1900
'submit',
1901
'Submits the form based on the current values of its submittable elements. May be passed an optional hashref of name=>value pairs to override those values, but this is not always enough to do what you want, as HTML allows for multiple form elements of the same name to exist in a form.',
1902
);
1903
}
1904
1905
{ package HTML::HTML5::DOM::HTMLFormControlsCollection;
1906
1907
BEGIN {
1908
$HTML::HTML5::DOM::HTMLFormControlsCollection::AUTHORITY = 'cpan:TOBYINK';
1909
$HTML::HTML5::DOM::HTMLFormControlsCollection::VERSION = '0.002';
1910
};
1911
1912
use base qw/HTML::HTML5::DOM::HTMLCollection/;
1913
use URI::Escape qw//;
1914
1915
sub namedItem
1916
{
1917
my ($self, $name) = @_;
1918
my @items = $self->grep(sub {
1919
($_->hasAttribute('id') && $_->getAttribute('id') eq $name) ||
1920
($_->hasAttribute('name') && $_->getAttribute('name') eq $name)
1921
});
1922
return $items[0] if scalar @items == 1;
1923
return wantarray ? @items : HTML::HTML5::DOM::RadioNodeList->new(@items);
1924
}
1925
1926
HTML::HTML5::DOMutil::AutoDoc->add(
1927
__PACKAGE__,
1928
'namedItem',
1929
'Given a name, returns a list of nodes of elements where the @id or @name attribute matches that name. In scalar context this can return a single element if there\'s only one match, or a HTML::HTML5::DOM::RadioNodeList if there is more than one - this is a kinda annoying feature, but it is required for DOM compliance. Best to just call it in list context.',
1930
);
1931
1932
sub p5_wwwFormUrlencoded
1933
{
1934
my ($self, $hashref) = @_;
1935
my @pairs = $self->p5_wwwFormPairs($hashref);
1936
#use Data::Dumper; print Dumper \@pairs; exit;
1937
return
1938
join '&',
1939
map {
1940
sprintf('%s=%s', map { URI::Escape::uri_escape($_) } @$_)
1941
}
1942
@pairs;
1943
}
1944
1945
HTML::HTML5::DOMutil::AutoDoc->add(
1946
__PACKAGE__,
1947
'p5_wwwFormUrlencoded',
1948
'Returns a form-encoded (C<< foo=bar&quux=xyzzy >>) string for the elements on the list.',
1949
);
1950
1951
sub p5_wwwFormPairs
1952
{
1953
my ($self, $hashref) = @_;
1954
my %remaining = my %HH = %{ $hashref || +{} };
1955
my $return = $self->map(sub {
1956
my @empty;
1957
return @empty unless $_->can('p5_wwwFormPair');
1958
my $pair = $_->p5_wwwFormPair;
1959
return @empty unless $pair;
1960
if (exists $hashref->{$pair->[0]})
1961
{
1962
delete $remaining{ $pair->[0] };
1963
$pair->[1] = $hashref->{$pair->[0]};
1964
}
1965
return $pair;
1966
});
1967
while (my @pair = each %remaining)
1968
{
1969
$return->push(\@pair);
1970
}
1971
wantarray ? @$return : (bless $return, 'XML::LibXML::NodeList');
1972
}
1973
1974
HTML::HTML5::DOMutil::AutoDoc->add(
1975
__PACKAGE__,
1976
'p5_wwwFormPairs',
1977
'Returns a list of C<< [$name => $value] >> tuples for the elements on the list.',
1978
);
1979
}
1980
1981
{ package HTML::HTML5::DOM::RadioNodeList;
1982
1983
use 5.010;
1984
use strict;
1985
use mro 'c3';
1986
use Object::AUTHORITY;
1987
1988
BEGIN {
1989
$HTML::HTML5::DOM::RadioNodeList::AUTHORITY = 'cpan:TOBYINK';
1990
$HTML::HTML5::DOM::RadioNodeList::VERSION = '0.002';
1991
};
1992
1993
use base qw/XML::LibXML::NodeList/;
1994
1995
sub value
1996
{
1997
my ($self) = @_;
1998
my @items = $self->grep(sub { $_->hasAttribute('checked') });
1999
return unless @items;
2000
return unless $items[0]->hasAttribute('value');
2001
return $items[0]->getAttribute('value');
2002
}
2003
2004
HTML::HTML5::DOMutil::AutoDoc->add(
2005
__PACKAGE__,
2006
'p5_wwwFormPairs',
2007
'Returns the "value" attribute of the first element which has a "checked" attribute.',
2008
);
2009
}
2010
2011
{ package HTML::HTML5::DOM::HTMLHeadElement;
2012
2013
use 5.010;
2014
use strict qw(vars subs);
2015
use mro 'c3';
2016
2017
BEGIN {
2018
$HTML::HTML5::DOM::HTMLHeadElement::AUTHORITY = 'cpan:TOBYINK';
2019
$HTML::HTML5::DOM::HTMLHeadElement::VERSION = '0.002';
2020
};
2021
2022
our @ELEMENTS;
2023
BEGIN {
2024
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2025
qw/head/;
2026
}
2027
2028
use XML::LibXML::Augment 0
2029
-names => [@ELEMENTS],
2030
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2031
2032
sub profile
2033
{
2034
my ($self) = @_;
2035
return
2036
map { URI->new($_) }
2037
grep { length $_ }
2038
split /\s+/,
2039
$self->getAttribute('profile');
2040
}
2041
2042
HTML::HTML5::DOMutil::AutoDoc->add(
2043
__PACKAGE__,
2044
'p5_wwwFormPairs',
2045
'Splits the "profile" attribute on whitespace, and returns it as a list of L objects.',
2046
);
2047
}
2048
2049
{ package HTML::HTML5::DOM::HTMLHeadingElement;
2050
2051
use 5.010;
2052
use strict qw(vars subs);
2053
use mro 'c3';
2054
2055
BEGIN {
2056
$HTML::HTML5::DOM::HTMLHeadingElement::AUTHORITY = 'cpan:TOBYINK';
2057
$HTML::HTML5::DOM::HTMLHeadingElement::VERSION = '0.002';
2058
};
2059
2060
our @ELEMENTS;
2061
BEGIN {
2062
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2063
qw/h1 h2 h3 h4 h5 h6/;
2064
}
2065
2066
use XML::LibXML::Augment 0
2067
-names => [@ELEMENTS],
2068
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2069
}
2070
2071
{ package HTML::HTML5::DOM::HTMLHRElement;
2072
2073
use 5.010;
2074
use strict qw(vars subs);
2075
use mro 'c3';
2076
2077
BEGIN {
2078
$HTML::HTML5::DOM::HTMLHRElement::AUTHORITY = 'cpan:TOBYINK';
2079
$HTML::HTML5::DOM::HTMLHRElement::VERSION = '0.002';
2080
};
2081
2082
our @ELEMENTS;
2083
BEGIN {
2084
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2085
qw/hr/;
2086
}
2087
2088
use XML::LibXML::Augment 0
2089
-names => [@ELEMENTS],
2090
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2091
}
2092
2093
{ package HTML::HTML5::DOM::HTMLHtmlElement;
2094
2095
use 5.010;
2096
use strict qw(vars subs);
2097
use mro 'c3';
2098
2099
BEGIN {
2100
$HTML::HTML5::DOM::HTMLHtmlElement::AUTHORITY = 'cpan:TOBYINK';
2101
$HTML::HTML5::DOM::HTMLHtmlElement::VERSION = '0.002';
2102
};
2103
2104
our @ELEMENTS;
2105
BEGIN {
2106
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2107
qw/html/;
2108
}
2109
2110
use XML::LibXML::Augment 0
2111
-names => [@ELEMENTS],
2112
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2113
2114
__PACKAGE__->_mk_attribute_accessors(qw/version/);
2115
}
2116
2117
{ package HTML::HTML5::DOM::HTMLIFrameElement;
2118
2119
use 5.010;
2120
use strict qw(vars subs);
2121
use mro 'c3';
2122
2123
BEGIN {
2124
$HTML::HTML5::DOM::HTMLIFrameElement::AUTHORITY = 'cpan:TOBYINK';
2125
$HTML::HTML5::DOM::HTMLIFrameElement::VERSION = '0.002';
2126
};
2127
2128
our @ELEMENTS;
2129
BEGIN {
2130
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2131
qw/iframe/;
2132
}
2133
2134
use XML::LibXML::Augment 0
2135
-names => [@ELEMENTS],
2136
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2137
2138
__PACKAGE__->_mk_attribute_accessors(
2139
qw/src==URI srcdoc name sandbox seamless==boolean width height/
2140
);
2141
}
2142
2143
{ package HTML::HTML5::DOM::HTMLImageElement;
2144
2145
use 5.010;
2146
use strict qw(vars subs);
2147
use mro 'c3';
2148
2149
BEGIN {
2150
$HTML::HTML5::DOM::HTMLImageElement::AUTHORITY = 'cpan:TOBYINK';
2151
$HTML::HTML5::DOM::HTMLImageElement::VERSION = '0.002';
2152
};
2153
2154
our @ELEMENTS;
2155
BEGIN {
2156
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2157
qw/img/;
2158
}
2159
2160
use XML::LibXML::Augment 0
2161
-names => [@ELEMENTS],
2162
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2163
2164
__PACKAGE__->_mk_attribute_accessors(
2165
qw/alt src==URI crossOrigin=crossorigin useMap=usemap isMap=ismap width height/
2166
);
2167
__PACKAGE__->_mk_follow_method('src');
2168
}
2169
2170
{ package HTML::HTML5::DOM::HTMLInputElement;
2171
2172
use 5.010;
2173
use strict qw(vars subs);
2174
use mro 'c3';
2175
2176
BEGIN {
2177
$HTML::HTML5::DOM::HTMLInputElement::AUTHORITY = 'cpan:TOBYINK';
2178
$HTML::HTML5::DOM::HTMLInputElement::VERSION = '0.002';
2179
};
2180
2181
our @ELEMENTS;
2182
BEGIN {
2183
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2184
qw/input/;
2185
}
2186
2187
use XML::LibXML::Augment 0
2188
-names => [@ELEMENTS],
2189
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2190
2191
__PACKAGE__->_mk_attribute_accessors(
2192
qw/accept alt max min multiple==boolean pattern placeholder
2193
required==boolean size src==URI step autocomplete type
2194
dirName=dirname autofocus==boolean checked==boolean width
2195
maxLength=maxlength height name readOnly=readonly=boolean/
2196
);
2197
__PACKAGE__->_mk_labels_method;
2198
__PACKAGE__->_mk_form_methods;
2199
2200
*indeterminate =
2201
*list =
2202
*valueAsDate =
2203
*valueAsNumber =
2204
*stepUp =
2205
*stepDown =
2206
sub { die 'TODO' };
2207
2208
sub p5_wwwFormPair
2209
{
2210
my ($self) = @_;
2211
if ($self->getAttribute('type') =~ m{^ (checkbox|radio) $}ix)
2212
{
2213
return unless $self->hasAttribute('checked');
2214
}
2215
elsif ($self->getAttribute('type') =~ m{^ (submit|reset|button|image) $}ix)
2216
{
2217
return;
2218
}
2219
2220
return [ $self->getAttribute('name'), $self->getAttribute('value') ];
2221
}
2222
2223
HTML::HTML5::DOMutil::AutoDoc->add(
2224
__PACKAGE__,
2225
'p5_wwwFormPair',
2226
'Returns the C<< [$name => $value] >> that would be used when submitting this form element.',
2227
);
2228
}
2229
2230
{ package HTML::HTML5::DOM::HTMLKeygenElement;
2231
2232
use 5.010;
2233
use strict qw(vars subs);
2234
use mro 'c3';
2235
2236
BEGIN {
2237
$HTML::HTML5::DOM::HTMLKeygenElement::AUTHORITY = 'cpan:TOBYINK';
2238
$HTML::HTML5::DOM::HTMLKeygenElement::VERSION = '0.002';
2239
};
2240
2241
our @ELEMENTS;
2242
BEGIN {
2243
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2244
qw/keygen/;
2245
}
2246
2247
use XML::LibXML::Augment 0
2248
-names => [@ELEMENTS],
2249
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2250
2251
__PACKAGE__->_mk_labels_method;
2252
__PACKAGE__->_mk_form_methods([qw/form/]);
2253
}
2254
2255
{ package HTML::HTML5::DOM::HTMLLabelElement;
2256
2257
use 5.010;
2258
use strict qw(vars subs);
2259
use mro 'c3';
2260
2261
BEGIN {
2262
$HTML::HTML5::DOM::HTMLLabelElement::AUTHORITY = 'cpan:TOBYINK';
2263
$HTML::HTML5::DOM::HTMLLabelElement::VERSION = '0.002';
2264
};
2265
2266
our @ELEMENTS;
2267
BEGIN {
2268
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2269
qw/label/;
2270
}
2271
2272
use XML::LibXML::Augment 0
2273
-names => [@ELEMENTS],
2274
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2275
2276
__PACKAGE__->_mk_form_methods([qw/form/]);
2277
2278
sub control
2279
{
2280
my ($self) = @_;
2281
2282
my @controls;
2283
if ($self->hasAttribute('for'))
2284
{
2285
my $xpath = sprintf('//[@id="%s"]', $self->getAttribute('for'));
2286
@controls = $self->ownerDocument->findnodes($xpath);
2287
}
2288
else
2289
{
2290
@controls = grep { $_->can('labels') } $self->getElementsByTagName('*');
2291
}
2292
2293
return $controls[0] if @controls;
2294
return;
2295
}
2296
2297
HTML::HTML5::DOMutil::AutoDoc->add(
2298
__PACKAGE__,
2299
'control',
2300
'Returns the control that this element acts as a label for.',
2301
);
2302
}
2303
2304
{ package HTML::HTML5::DOM::HTMLLegendElement;
2305
2306
use 5.010;
2307
use strict qw(vars subs);
2308
use mro 'c3';
2309
2310
BEGIN {
2311
$HTML::HTML5::DOM::HTMLLegendElement::AUTHORITY = 'cpan:TOBYINK';
2312
$HTML::HTML5::DOM::HTMLLegendElement::VERSION = '0.002';
2313
};
2314
2315
our @ELEMENTS;
2316
BEGIN {
2317
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2318
qw/legend/;
2319
}
2320
2321
use XML::LibXML::Augment 0
2322
-names => [@ELEMENTS],
2323
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2324
2325
__PACKAGE__->_mk_form_methods([qw/form/]);
2326
}
2327
2328
{ package HTML::HTML5::DOM::HTMLLIElement;
2329
2330
use 5.010;
2331
use strict qw(vars subs);
2332
use mro 'c3';
2333
2334
BEGIN {
2335
$HTML::HTML5::DOM::HTMLLIElement::AUTHORITY = 'cpan:TOBYINK';
2336
$HTML::HTML5::DOM::HTMLLIElement::VERSION = '0.002';
2337
};
2338
2339
our @ELEMENTS;
2340
BEGIN {
2341
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2342
qw/li/;
2343
}
2344
2345
use XML::LibXML::Augment 0
2346
-names => [@ELEMENTS],
2347
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2348
2349
sub value
2350
{
2351
die "TODO";
2352
}
2353
}
2354
2355
{ package HTML::HTML5::DOM::HTMLLinkElement;
2356
2357
use 5.010;
2358
use strict qw(vars subs);
2359
use mro 'c3';
2360
2361
BEGIN {
2362
$HTML::HTML5::DOM::HTMLLinkElement::AUTHORITY = 'cpan:TOBYINK';
2363
$HTML::HTML5::DOM::HTMLLinkElement::VERSION = '0.002';
2364
};
2365
2366
our @ELEMENTS;
2367
BEGIN {
2368
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2369
qw/link/;
2370
}
2371
2372
use XML::LibXML::Augment 0
2373
-names => [@ELEMENTS],
2374
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2375
2376
__PACKAGE__->_mk_attribute_accessors(qw/
2377
disabled==boolean href==URI rel rev media hreflang target type
2378
relList=rel=LIST revList=rev=LIST
2379
/);
2380
__PACKAGE__->_mk_url_decomposition; # technically not part of HTML5 spec
2381
__PACKAGE__->_mk_follow_method;
2382
}
2383
2384
{ package HTML::HTML5::DOM::HTMLMapElement;
2385
2386
use 5.010;
2387
use strict qw(vars subs);
2388
use mro 'c3';
2389
2390
BEGIN {
2391
$HTML::HTML5::DOM::HTMLMapElement::AUTHORITY = 'cpan:TOBYINK';
2392
$HTML::HTML5::DOM::HTMLMapElement::VERSION = '0.002';
2393
};
2394
2395
our @ELEMENTS;
2396
BEGIN {
2397
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2398
qw/map/;
2399
}
2400
2401
use XML::LibXML::Augment 0
2402
-names => [@ELEMENTS],
2403
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2404
}
2405
2406
{ package HTML::HTML5::DOM::HTMLMenuElement;
2407
2408
use 5.010;
2409
use strict qw(vars subs);
2410
use mro 'c3';
2411
2412
BEGIN {
2413
$HTML::HTML5::DOM::HTMLMenuElement::AUTHORITY = 'cpan:TOBYINK';
2414
$HTML::HTML5::DOM::HTMLMenuElement::VERSION = '0.002';
2415
};
2416
2417
our @ELEMENTS;
2418
BEGIN {
2419
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2420
qw/menu/;
2421
}
2422
2423
use XML::LibXML::Augment 0
2424
-names => [@ELEMENTS],
2425
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2426
2427
__PACKAGE__->_mk_attribute_accessors(qw/label type/);
2428
}
2429
2430
{ package HTML::HTML5::DOM::HTMLMetaElement;
2431
2432
use 5.010;
2433
use strict qw(vars subs);
2434
use mro 'c3';
2435
2436
BEGIN {
2437
$HTML::HTML5::DOM::HTMLMetaElement::AUTHORITY = 'cpan:TOBYINK';
2438
$HTML::HTML5::DOM::HTMLMetaElement::VERSION = '0.002';
2439
};
2440
2441
our @ELEMENTS;
2442
BEGIN {
2443
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2444
qw/meta/;
2445
}
2446
2447
use XML::LibXML::Augment 0
2448
-names => [@ELEMENTS],
2449
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2450
2451
__PACKAGE__->_mk_attribute_accessors(qw/name httpEquiv=http-equiv content scheme/);
2452
}
2453
2454
{ package HTML::HTML5::DOM::HTMLMeterElement;
2455
2456
use 5.010;
2457
use strict qw(vars subs);
2458
use mro 'c3';
2459
2460
BEGIN {
2461
$HTML::HTML5::DOM::HTMLMeterElement::AUTHORITY = 'cpan:TOBYINK';
2462
$HTML::HTML5::DOM::HTMLMeterElement::VERSION = '0.002';
2463
};
2464
2465
our @ELEMENTS;
2466
BEGIN {
2467
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2468
qw/meter/;
2469
}
2470
2471
use XML::LibXML::Augment 0
2472
-names => [@ELEMENTS],
2473
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2474
2475
__PACKAGE__->_mk_attribute_accessors(qw/value min max low high optimum/);
2476
__PACKAGE__->_mk_labels_method;
2477
__PACKAGE__->_mk_form_methods([qw/form/]);
2478
}
2479
2480
{ package HTML::HTML5::DOM::HTMLObjectElement;
2481
2482
use 5.010;
2483
use strict qw(vars subs);
2484
use mro 'c3';
2485
2486
BEGIN {
2487
$HTML::HTML5::DOM::HTMLObjectElement::AUTHORITY = 'cpan:TOBYINK';
2488
$HTML::HTML5::DOM::HTMLObjectElement::VERSION = '0.002';
2489
};
2490
2491
our @ELEMENTS;
2492
BEGIN {
2493
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2494
qw/object/;
2495
}
2496
2497
use XML::LibXML::Augment 0
2498
-names => [@ELEMENTS],
2499
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2500
2501
__PACKAGE__->_mk_attribute_accessors(
2502
qw/data==URI type typeMustMatch=typemustmatch name useMap=usemap width height/
2503
);
2504
__PACKAGE__->_mk_form_methods([qw/form/]);
2505
__PACKAGE__->_mk_follow_method('data');
2506
}
2507
2508
{ package HTML::HTML5::DOM::HTMLOListElement;
2509
2510
use 5.010;
2511
use strict qw(vars subs);
2512
use mro 'c3';
2513
2514
BEGIN {
2515
$HTML::HTML5::DOM::HTMLOListElement::AUTHORITY = 'cpan:TOBYINK';
2516
$HTML::HTML5::DOM::HTMLOListElement::VERSION = '0.002';
2517
};
2518
2519
our @ELEMENTS;
2520
BEGIN {
2521
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2522
qw/ol/;
2523
}
2524
2525
use XML::LibXML::Augment 0
2526
-names => [@ELEMENTS],
2527
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2528
2529
__PACKAGE__->_mk_attribute_accessors(qw/reversed==boolean start type/);
2530
}
2531
2532
{ package HTML::HTML5::DOM::HTMLOptGroupElement;
2533
2534
use 5.010;
2535
use strict qw(vars subs);
2536
use mro 'c3';
2537
2538
BEGIN {
2539
$HTML::HTML5::DOM::HTMLOptGroupElement::AUTHORITY = 'cpan:TOBYINK';
2540
$HTML::HTML5::DOM::HTMLOptGroupElement::VERSION = '0.002';
2541
};
2542
2543
our @ELEMENTS;
2544
BEGIN {
2545
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2546
qw/optgroup/;
2547
}
2548
2549
use XML::LibXML::Augment 0
2550
-names => [@ELEMENTS],
2551
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2552
2553
__PACKAGE__->_mk_attribute_accessors(qw/disabled==boolean label/);
2554
}
2555
2556
{ package HTML::HTML5::DOM::HTMLOptionElement;
2557
2558
use 5.010;
2559
use strict qw(vars subs);
2560
use mro 'c3';
2561
2562
BEGIN {
2563
$HTML::HTML5::DOM::HTMLOptionElement::AUTHORITY = 'cpan:TOBYINK';
2564
$HTML::HTML5::DOM::HTMLOptionElement::VERSION = '0.002';
2565
};
2566
2567
our @ELEMENTS;
2568
BEGIN {
2569
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2570
qw/option/;
2571
}
2572
2573
use XML::LibXML::Augment 0
2574
-names => [@ELEMENTS],
2575
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2576
}
2577
2578
{ package HTML::HTML5::DOM::HTMLOutputElement;
2579
2580
use 5.010;
2581
use strict qw(vars subs);
2582
use mro 'c3';
2583
2584
BEGIN {
2585
$HTML::HTML5::DOM::HTMLOutputElement::AUTHORITY = 'cpan:TOBYINK';
2586
$HTML::HTML5::DOM::HTMLOutputElement::VERSION = '0.002';
2587
};
2588
2589
our @ELEMENTS;
2590
BEGIN {
2591
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2592
qw/output/;
2593
}
2594
2595
use XML::LibXML::Augment 0
2596
-names => [@ELEMENTS],
2597
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2598
2599
__PACKAGE__->_mk_labels_method;
2600
__PACKAGE__->_mk_form_methods([qw/form/]);
2601
}
2602
2603
{ package HTML::HTML5::DOM::HTMLParagraphElement;
2604
2605
use 5.010;
2606
use strict qw(vars subs);
2607
use mro 'c3';
2608
2609
BEGIN {
2610
$HTML::HTML5::DOM::HTMLParagraphElement::AUTHORITY = 'cpan:TOBYINK';
2611
$HTML::HTML5::DOM::HTMLParagraphElement::VERSION = '0.002';
2612
};
2613
2614
our @ELEMENTS;
2615
BEGIN {
2616
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2617
qw/p/;
2618
}
2619
2620
use XML::LibXML::Augment 0
2621
-names => [@ELEMENTS],
2622
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2623
}
2624
2625
{ package HTML::HTML5::DOM::HTMLParamElement;
2626
2627
use 5.010;
2628
use strict qw(vars subs);
2629
use mro 'c3';
2630
2631
BEGIN {
2632
$HTML::HTML5::DOM::HTMLParamElement::AUTHORITY = 'cpan:TOBYINK';
2633
$HTML::HTML5::DOM::HTMLParamElement::VERSION = '0.002';
2634
};
2635
2636
our @ELEMENTS;
2637
BEGIN {
2638
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2639
qw/param/;
2640
}
2641
2642
use XML::LibXML::Augment 0
2643
-names => [@ELEMENTS],
2644
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2645
2646
__PACKAGE__->_mk_attribute_accessors(qw/name value/);
2647
}
2648
2649
{ package HTML::HTML5::DOM::HTMLPreElement;
2650
2651
use 5.010;
2652
use strict qw(vars subs);
2653
use mro 'c3';
2654
2655
BEGIN {
2656
$HTML::HTML5::DOM::HTMLPreElement::AUTHORITY = 'cpan:TOBYINK';
2657
$HTML::HTML5::DOM::HTMLPreElement::VERSION = '0.002';
2658
};
2659
2660
our @ELEMENTS;
2661
BEGIN {
2662
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2663
qw/pre/;
2664
}
2665
2666
use XML::LibXML::Augment 0
2667
-names => [@ELEMENTS],
2668
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2669
}
2670
2671
{ package HTML::HTML5::DOM::HTMLProgressElement;
2672
2673
use 5.010;
2674
use strict qw(vars subs);
2675
use mro 'c3';
2676
2677
BEGIN {
2678
$HTML::HTML5::DOM::HTMLProgressElement::AUTHORITY = 'cpan:TOBYINK';
2679
$HTML::HTML5::DOM::HTMLProgressElement::VERSION = '0.002';
2680
};
2681
2682
our @ELEMENTS;
2683
BEGIN {
2684
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2685
qw/progress/;
2686
}
2687
2688
use XML::LibXML::Augment 0
2689
-names => [@ELEMENTS],
2690
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2691
2692
__PACKAGE__->_mk_attribute_accessors(qw/max position value/);
2693
__PACKAGE__->_mk_labels_method;
2694
}
2695
2696
{ package HTML::HTML5::DOM::HTMLScriptElement;
2697
2698
use 5.010;
2699
use strict qw(vars subs);
2700
use mro 'c3';
2701
2702
BEGIN {
2703
$HTML::HTML5::DOM::HTMLScriptElement::AUTHORITY = 'cpan:TOBYINK';
2704
$HTML::HTML5::DOM::HTMLScriptElement::VERSION = '0.002';
2705
};
2706
2707
our @ELEMENTS;
2708
BEGIN {
2709
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2710
qw/script/;
2711
}
2712
2713
use XML::LibXML::Augment 0
2714
-names => [@ELEMENTS],
2715
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2716
2717
__PACKAGE__->_mk_attribute_accessors(
2718
qw/src==URI async==boolean defer==boolean type charset text==TEXT/
2719
);
2720
}
2721
2722
{ package HTML::HTML5::DOM::HTMLSelectElement;
2723
2724
use 5.010;
2725
use strict qw(vars subs);
2726
use mro 'c3';
2727
2728
BEGIN {
2729
$HTML::HTML5::DOM::HTMLSelectElement::AUTHORITY = 'cpan:TOBYINK';
2730
$HTML::HTML5::DOM::HTMLSelectElement::VERSION = '0.002';
2731
};
2732
2733
our @ELEMENTS;
2734
BEGIN {
2735
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2736
qw/select/;
2737
}
2738
2739
use XML::LibXML::Augment 0
2740
-names => [@ELEMENTS],
2741
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2742
2743
__PACKAGE__->_mk_labels_method;
2744
__PACKAGE__->_mk_form_methods([qw/form/]);
2745
}
2746
2747
{ package HTML::HTML5::DOM::HTMLSourceElement;
2748
2749
use 5.010;
2750
use strict qw(vars subs);
2751
use mro 'c3';
2752
2753
BEGIN {
2754
$HTML::HTML5::DOM::HTMLSourceElement::AUTHORITY = 'cpan:TOBYINK';
2755
$HTML::HTML5::DOM::HTMLSourceElement::VERSION = '0.002';
2756
};
2757
2758
our @ELEMENTS;
2759
BEGIN {
2760
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2761
qw/source/;
2762
}
2763
2764
use XML::LibXML::Augment 0
2765
-names => [@ELEMENTS],
2766
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2767
2768
__PACKAGE__->_mk_attribute_accessors(
2769
qw/src==URI type media/
2770
);
2771
__PACKAGE__->_mk_follow_method('src');
2772
}
2773
2774
{ package HTML::HTML5::DOM::HTMLSpanElement;
2775
2776
use 5.010;
2777
use strict qw(vars subs);
2778
use mro 'c3';
2779
2780
BEGIN {
2781
$HTML::HTML5::DOM::HTMLSpanElement::AUTHORITY = 'cpan:TOBYINK';
2782
$HTML::HTML5::DOM::HTMLSpanElement::VERSION = '0.002';
2783
};
2784
2785
our @ELEMENTS;
2786
BEGIN {
2787
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2788
qw/span/;
2789
}
2790
2791
use XML::LibXML::Augment 0
2792
-names => [@ELEMENTS],
2793
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2794
}
2795
2796
{ package HTML::HTML5::DOM::HTMLStyleElement;
2797
2798
use 5.010;
2799
use strict qw(vars subs);
2800
use mro 'c3';
2801
2802
BEGIN {
2803
$HTML::HTML5::DOM::HTMLStyleElement::AUTHORITY = 'cpan:TOBYINK';
2804
$HTML::HTML5::DOM::HTMLStyleElement::VERSION = '0.002';
2805
};
2806
2807
our @ELEMENTS;
2808
BEGIN {
2809
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2810
qw/style/;
2811
}
2812
2813
use XML::LibXML::Augment 0
2814
-names => [@ELEMENTS],
2815
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2816
2817
__PACKAGE__->_mk_attribute_accessors(
2818
qw/disabled==boolean scoped==boolean type media/
2819
);
2820
}
2821
2822
{ package HTML::HTML5::DOM::HTMLTableElement;
2823
2824
use 5.010;
2825
use strict qw(vars subs);
2826
use mro 'c3';
2827
2828
BEGIN {
2829
$HTML::HTML5::DOM::HTMLTableElement::AUTHORITY = 'cpan:TOBYINK';
2830
$HTML::HTML5::DOM::HTMLTableElement::VERSION = '0.002';
2831
};
2832
2833
our @ELEMENTS;
2834
BEGIN {
2835
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2836
qw/table/;
2837
}
2838
2839
use XML::LibXML::Augment 0
2840
-names => [@ELEMENTS],
2841
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2842
2843
sub caption
2844
{
2845
my $self = shift;
2846
my ($cap) = $self->getChildrenByTagName('caption');
2847
return $cap if $cap;
2848
return;
2849
}
2850
2851
sub createCaption
2852
{
2853
my $self = shift;
2854
return $self->caption || do {
2855
my $new = XML::LibXML::Element->new('caption');
2856
$new->setNamespace($self->namespaceURI, '', 1);
2857
$self->insertBefore($new, $self->childNodes->get_node(1));
2858
XML::LibXML::Augment->rebless($new);
2859
$new;
2860
};
2861
}
2862
2863
sub deleteCaption
2864
{
2865
my $self = shift;
2866
my $cap = $self->caption;
2867
$self->removeChild($cap) if $cap;
2868
return !!$cap;
2869
}
2870
2871
HTML::HTML5::DOMutil::AutoDoc->add(
2872
__PACKAGE__,
2873
caption => 'returns the C<< >> element (if any)',
2874
);
2875
2876
HTML::HTML5::DOMutil::AutoDoc->add(
2877
__PACKAGE__,
2878
createCaption => 'returns the C<< >> element, creating one if there is none',
2879
);
2880
2881
HTML::HTML5::DOMutil::AutoDoc->add(
2882
__PACKAGE__,
2883
deleteCaption => 'delete the C<< >> element (if any), and returns a boolean indicating whether anything was deleted',
2884
);
2885
2886
foreach (qw/tHead createTHead deleteTHead tFoot createTFoot deleteTFoot
2887
tBodies createTBody rows insertRow deleteRow border/)
2888
{
2889
*$_ = sub { die 'TODO' };
2890
HTML::HTML5::DOMutil::AutoDoc->add(__PACKAGE__, $_, '@@TODO - not implemented yet');
2891
}
2892
}
2893
2894
{ package HTML::HTML5::DOM::HTMLTableSectionElement;
2895
2896
use 5.010;
2897
use strict qw(vars subs);
2898
use mro 'c3';
2899
2900
BEGIN {
2901
$HTML::HTML5::DOM::HTMLTableSectionElement::AUTHORITY = 'cpan:TOBYINK';
2902
$HTML::HTML5::DOM::HTMLTableSectionElement::VERSION = '0.002';
2903
};
2904
2905
our @ELEMENTS;
2906
BEGIN {
2907
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2908
qw/tbody tfoot thead/;
2909
}
2910
2911
use XML::LibXML::Augment 0
2912
-names => [@ELEMENTS],
2913
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2914
2915
sub rows
2916
{
2917
my $self = shift;
2918
return $self->getChildrenByTagName('*')->grep(sub { $_->tagName =~ m{^(tr)$}i });
2919
}
2920
2921
HTML::HTML5::DOMutil::AutoDoc->add(__PACKAGE__,
2922
rows => 'returns a list of C<< >> child elements'
2923
);
2924
2925
sub insertRow { die "TODO" }
2926
sub deleteRow { die "TODO" }
2927
2928
HTML::HTML5::DOMutil::AutoDoc->add(__PACKAGE__, $_, '@@TODO')
2929
for qw/insertRow deleteRow/;
2930
}
2931
2932
{ package HTML::HTML5::DOM::HTMLTableCellElement;
2933
2934
use 5.010;
2935
use strict qw(vars subs);
2936
use mro 'c3';
2937
2938
BEGIN {
2939
$HTML::HTML5::DOM::HTMLTableCellElement::AUTHORITY = 'cpan:TOBYINK';
2940
$HTML::HTML5::DOM::HTMLTableCellElement::VERSION = '0.002';
2941
};
2942
2943
our @ELEMENTS;
2944
BEGIN {
2945
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2946
qw//;
2947
}
2948
2949
use XML::LibXML::Augment 0
2950
-names => [@ELEMENTS],
2951
-isa => ['HTML::HTML5::DOM::HTMLElement'];
2952
2953
__PACKAGE__->_mk_attribute_accessors(
2954
qw/rowSpan=rowspan colSpan=colspan/
2955
);
2956
2957
sub headers
2958
{
2959
die "TODO";
2960
}
2961
2962
HTML::HTML5::DOMutil::AutoDoc->add(
2963
__PACKAGE__,
2964
'headers',
2965
'@@TODO - should return a list of C<< >> elements that act as a header for this cell.',
2966
);
2967
2968
sub cellIndex
2969
{
2970
die "TODO";
2971
}
2972
2973
HTML::HTML5::DOMutil::AutoDoc->add(
2974
__PACKAGE__,
2975
'cellIndex',
2976
"\@\@TODO - should return the cell's index within its row.",
2977
);
2978
}
2979
2980
{ package HTML::HTML5::DOM::HTMLTableDataCellElement;
2981
2982
use 5.010;
2983
use strict qw(vars subs);
2984
use mro 'c3';
2985
2986
BEGIN {
2987
$HTML::HTML5::DOM::HTMLTableDataCellElement::AUTHORITY = 'cpan:TOBYINK';
2988
$HTML::HTML5::DOM::HTMLTableDataCellElement::VERSION = '0.002';
2989
};
2990
2991
our @ELEMENTS;
2992
BEGIN {
2993
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
2994
qw/td/;
2995
}
2996
2997
use XML::LibXML::Augment 0
2998
-names => [@ELEMENTS],
2999
-isa => ['HTML::HTML5::DOM::HTMLTableCellElement'];
3000
}
3001
3002
{ package HTML::HTML5::DOM::HTMLTableHeaderCellElement;
3003
3004
use 5.010;
3005
use strict qw(vars subs);
3006
use mro 'c3';
3007
3008
BEGIN {
3009
$HTML::HTML5::DOM::HTMLTableHeaderCellElement::AUTHORITY = 'cpan:TOBYINK';
3010
$HTML::HTML5::DOM::HTMLTableHeaderCellElement::VERSION = '0.002';
3011
};
3012
3013
our @ELEMENTS;
3014
BEGIN {
3015
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
3016
qw/th/;
3017
}
3018
3019
use XML::LibXML::Augment 0
3020
-names => [@ELEMENTS],
3021
-isa => ['HTML::HTML5::DOM::HTMLTableCellElement'];
3022
3023
__PACKAGE__->_mk_attribute_accessors(qw/scope/);
3024
}
3025
3026
{ package HTML::HTML5::DOM::HTMLTableRowElement;
3027
3028
use 5.010;
3029
use strict qw(vars subs);
3030
use mro 'c3';
3031
3032
BEGIN {
3033
$HTML::HTML5::DOM::HTMLTableRowElement::AUTHORITY = 'cpan:TOBYINK';
3034
$HTML::HTML5::DOM::HTMLTableRowElement::VERSION = '0.002';
3035
};
3036
3037
our @ELEMENTS;
3038
BEGIN {
3039
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
3040
qw/tr/;
3041
}
3042
3043
use XML::LibXML::Augment 0
3044
-names => [@ELEMENTS],
3045
-isa => ['HTML::HTML5::DOM::HTMLElement'];
3046
3047
sub rowIndex { die "TODO" }
3048
sub sectionRowIndex { die "TODO" }
3049
sub insertCell { die "TODO" }
3050
sub deleteCell { die "TODO" }
3051
3052
HTML::HTML5::DOMutil::AutoDoc->add(__PACKAGE__, $_, '@@TODO')
3053
for qw/sectionRowIndex rowIndex insertCell deleteCell/;
3054
3055
sub cells
3056
{
3057
my $self = shift;
3058
return $self->getChildrenByTagName('*')->grep(sub { $_->tagName =~ m{^(td|th)$}i });
3059
}
3060
3061
HTML::HTML5::DOMutil::AutoDoc->add(__PACKAGE__,
3062
cells => 'returns a list of C<< >> and C<< >> child elements'
3063
);
3064
}
3065
3066
{ package HTML::HTML5::DOM::HTMLTextAreaElement;
3067
3068
use 5.010;
3069
use strict qw(vars subs);
3070
use mro 'c3';
3071
3072
BEGIN {
3073
$HTML::HTML5::DOM::HTMLTextAreaElement::AUTHORITY = 'cpan:TOBYINK';
3074
$HTML::HTML5::DOM::HTMLTextAreaElement::VERSION = '0.002';
3075
};
3076
3077
our @ELEMENTS;
3078
BEGIN {
3079
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
3080
qw/textarea/;
3081
}
3082
3083
use XML::LibXML::Augment 0
3084
-names => [@ELEMENTS],
3085
-isa => ['HTML::HTML5::DOM::HTMLElement'];
3086
3087
__PACKAGE__->_mk_labels_method;
3088
__PACKAGE__->_mk_form_methods([qw/form/]);
3089
}
3090
3091
{ package HTML::HTML5::DOM::HTMLTimeElement;
3092
3093
use 5.010;
3094
use strict qw(vars subs);
3095
use mro 'c3';
3096
3097
BEGIN {
3098
$HTML::HTML5::DOM::HTMLTimeElement::AUTHORITY = 'cpan:TOBYINK';
3099
$HTML::HTML5::DOM::HTMLTimeElement::VERSION = '0.002';
3100
};
3101
3102
our @ELEMENTS;
3103
BEGIN {
3104
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
3105
qw/time/;
3106
}
3107
3108
use XML::LibXML::Augment 0
3109
-names => [@ELEMENTS],
3110
-isa => ['HTML::HTML5::DOM::HTMLElement'];
3111
3112
sub datetime
3113
{
3114
die "TODO";
3115
}
3116
}
3117
3118
{ package HTML::HTML5::DOM::HTMLTitleElement;
3119
3120
use 5.010;
3121
use strict qw(vars subs);
3122
use mro 'c3';
3123
3124
BEGIN {
3125
$HTML::HTML5::DOM::HTMLTitleElement::AUTHORITY = 'cpan:TOBYINK';
3126
$HTML::HTML5::DOM::HTMLTitleElement::VERSION = '0.002';
3127
};
3128
3129
our @ELEMENTS;
3130
BEGIN {
3131
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
3132
qw/title/;
3133
}
3134
3135
use XML::LibXML::Augment 0
3136
-names => [@ELEMENTS],
3137
-isa => ['HTML::HTML5::DOM::HTMLElement'];
3138
3139
__PACKAGE__->_mk_attribute_accessors(qw/text==TEXT/);
3140
}
3141
3142
{ package HTML::HTML5::DOM::HTMLTrackElement;
3143
3144
use 5.010;
3145
use strict qw(vars subs);
3146
use mro 'c3';
3147
3148
BEGIN {
3149
$HTML::HTML5::DOM::HTMLTrackElement::AUTHORITY = 'cpan:TOBYINK';
3150
$HTML::HTML5::DOM::HTMLTrackElement::VERSION = '0.002';
3151
};
3152
3153
our @ELEMENTS;
3154
BEGIN {
3155
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
3156
qw/track/;
3157
}
3158
3159
use XML::LibXML::Augment 0
3160
-names => [@ELEMENTS],
3161
-isa => ['HTML::HTML5::DOM::HTMLElement'];
3162
}
3163
3164
{ package HTML::HTML5::DOM::HTMLUListElement;
3165
3166
use 5.010;
3167
use strict qw(vars subs);
3168
use mro 'c3';
3169
3170
BEGIN {
3171
$HTML::HTML5::DOM::HTMLUListElement::AUTHORITY = 'cpan:TOBYINK';
3172
$HTML::HTML5::DOM::HTMLUListElement::VERSION = '0.002';
3173
};
3174
3175
our @ELEMENTS;
3176
BEGIN {
3177
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
3178
qw/ul/;
3179
}
3180
3181
use XML::LibXML::Augment 0
3182
-names => [@ELEMENTS],
3183
-isa => ['HTML::HTML5::DOM::HTMLElement'];
3184
}
3185
3186
{ package HTML::HTML5::DOM::HTMLVideoElement;
3187
3188
use 5.010;
3189
use strict qw(vars subs);
3190
use mro 'c3';
3191
3192
BEGIN {
3193
$HTML::HTML5::DOM::HTMLVideoElement::AUTHORITY = 'cpan:TOBYINK';
3194
$HTML::HTML5::DOM::HTMLVideoElement::VERSION = '0.002';
3195
};
3196
3197
our @ELEMENTS;
3198
BEGIN {
3199
@ELEMENTS = map { sprintf('{%s}%s', HTML::HTML5::DOM->XHTML_NS, $_) }
3200
qw/video/;
3201
}
3202
3203
use XML::LibXML::Augment 0
3204
-names => [@ELEMENTS],
3205
-isa => ['HTML::HTML5::DOM::HTMLMediaElement'];
3206
3207
__PACKAGE__->_mk_attribute_accessors(
3208
qw/poster==URI height width/
3209
);
3210
}
3211
3212
1;
3213
3214
__END__