Tiny.pm

filter: Statementstmt 100% 232 / 232 Branchbran 99.2% 135 / 136 Conditioncond 93.7% 60 / 64 MC/DCmcdc 72.9% 27 / 37 Subroutinesub 100% 76 / 76 Podpod 97.5% 40 / 41 totaltotal 97.2% 570 / 586 SCAR 45.6
CC
96
Cov
99%
_text
17.0
val
12.0
_siblings
10.0
CRAP 96.0
« Tiny/_CSS.pm ↑ Summary Tiny/_HTML.pm »
1 package DOM::Tiny;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 use overload
7 4 ▶ '@{}' => sub { shift->child_nodes },
Subroutine __ANON__: called CC=1 SCAR=0.0
8 76 ▶ '%{}' => sub { shift->attr },
Subroutine __ANON__: called CC=1 SCAR=0.0
9 103 ▶ bool => sub {1},
Subroutine __ANON__: called CC=1 SCAR=0.0
10 105 ▶ '""' => sub { shift->to_string },
Subroutine __ANON__: called CC=1 SCAR=0.0
11 1 ▶ fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use DOM::Tiny::_Collection;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use DOM::Tiny::_CSS;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use DOM::Tiny::_HTML;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Scalar::Util qw(blessed weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 our $VERSION = '0.003';
20  
21 sub new {
22 1884 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
23 1884 ▶ my $self = bless \DOM::Tiny::_HTML->new, ref $class || $class;
Condition66%2/3
ref $class || $class
l!l&&r!l&&!r
17591250
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table66%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
24 1884 ▶ return @_ ? $self->parse(@_) : $self;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 111 1773 1884
25 }
26  
27 1 ▶sub TO_JSON { shift->_delegate('render') }
Subroutine TO_JSON: called CC=1 SCAR=0.0
Pod undocumented
28  
29 27 ▶sub all_text { shift->_all_text(1, @_) }
Subroutine all_text: called CC=1 SCAR=0.0
Pod documented
30  
31 9 ▶sub ancestors { _select($_[0]->_collect($_[0]->_ancestors), $_[1]) }
Subroutine ancestors: called CC=1 SCAR=0.0
Pod documented
32  
33 7 ▶sub append { shift->_add(1, @_) }
Subroutine append: called CC=1 SCAR=0.0
Pod documented
34 9 ▶sub append_content { shift->_content(1, 0, @_) }
Subroutine append_content: called CC=1 SCAR=0.0
Pod documented
35  
36 sub at {
37 453 ▶ my $self = shift;
Subroutine at: called CC=2 SCAR=6.9
Pod documented
38 453 ▶ return undef unless my $result = $self->_css->select_one(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless my $result = $self->_css->select_one(@_) 35 418 453
39 418 return $self->_build($result, $self->xml);
40 }
41  
42 sub attr {
43 149 ▶ my $self = shift;
Subroutine attr: called CC=6 SCAR=17.9
Pod documented
44  
45 # Hash
46 149 my $tree = $self->tree;
47 149 ▶ my $attrs = $tree->[0] ne 'tag' ? {} : $tree->[2];
Branch: 1 branch
BranchTrueFalseTotal
$tree->[0] ne 'tag' ? : 6 143 149
48 149 ▶ return $attrs unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 109 40 149
49  
50 # Get
51 40 ▶ return $attrs->{$_[0]} unless @_ > 1 || ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 1 or ref $_[0] 36 4 40
Condition100%3/3
@_ > 1 or ref $_[0]
l!l&&r!l&&!r
3136
MC/DC100%2/2
@_ > 1 or ref $_[0]
@_ > 1 ref $_[0]
Truth table100%3/3
A or B
A= @_ > 1B= ref $_[0]
ABresult
1X1
011
000
52  
53 # Set
54 4 ▶ my $values = ref $_[0] ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1 3 4
55 4 @$attrs{keys %$values} = values %$values;
56  
57 4 return $self;
58 }
59  
60 58 ▶sub child_nodes { $_[0]->_collect(_nodes($_[0]->tree)) }
Subroutine child_nodes: called CC=1 SCAR=0.0
Pod documented
61  
62 13 ▶sub children { _select($_[0]->_collect(_nodes($_[0]->tree, 1)), $_[1]) }
Subroutine children: called CC=1 SCAR=0.0
Pod documented
63  
64 sub content {
65 53 ▶ my $self = shift;
Subroutine content: called CC=5 SCAR=16.1
Pod documented
66  
67 53 my $type = $self->type;
68 53 ▶ if ($type eq 'root' || $type eq 'tag') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "root" or $type eq "tag") 22 31 53
Condition100%3/3
$type eq "root" or $type eq "tag"
l!l&&r!l&&!r
61631
MC/DC100%2/2
$type eq "root" or $type eq "tag"
$type eq "root" $type eq "tag"
Truth table100%3/3
A or B
A= $type eq "root"B= $type eq "tag"
ABresult
1X1
011
000
69 22 ▶ return $self->_content(0, 1, @_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 15 7 22
70 7 my $html = DOM::Tiny::_HTML->new(xml => $self->xml);
71 7 return join '', map { $html->tree($_)->render } _nodes($self->tree);
72 }
73  
74 31 ▶ return $self->tree->[1] unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 28 3 31
75 3 $self->tree->[1] = shift;
76 3 return $self;
77 }
78  
79 13 ▶sub descendant_nodes { $_[0]->_collect(_all(_nodes($_[0]->tree))) }
Subroutine descendant_nodes: called CC=1 SCAR=0.0
Pod documented
80  
81 389 ▶sub find { $_[0]->_collect(@{$_[0]->_css->select($_[1])}) }
Subroutine find: called CC=1 SCAR=0.0
Pod documented
82  
83 8 ▶sub following { _select($_[0]->_collect(@{$_[0]->_siblings(1)->[1]}), $_[1]) }
Subroutine following: called CC=1 SCAR=0.0
Pod documented
84 7 ▶sub following_nodes { $_[0]->_collect(@{$_[0]->_siblings->[1]}) }
Subroutine following_nodes: called CC=1 SCAR=0.0
Pod documented
85  
86 29 ▶sub matches { shift->_css->matches(@_) }
Subroutine matches: called CC=1 SCAR=0.0
Pod documented
87  
88 sub namespace {
89 18 ▶ my $self = shift;
Subroutine namespace: called CC=8 SCAR=20.8
Pod documented
90  
91 18 ▶ return undef if (my $tree = $self->tree)->[0] ne 'tag';
Branch: 1 branch
BranchTrueFalseTotal
if +(my $tree = $self->tree)->[0] ne "tag" 2 16 18
92  
93 # Extract namespace prefix and search parents
94 16 ▶ my $ns = $tree->[1] =~ /^(.*?):/ ? "xmlns:$1" : undef;
Branch: 1 branch
BranchTrueFalseTotal
$tree->[1] =~ /^(.*?):/ ? : 5 11 16
95 16 for my $node ($tree, $self->_ancestors) {
96  
97 # Namespace for prefix
98 35 my $attrs = $node->[2];
99 35 ▶ if ($ns) { $_ eq $ns and return $attrs->{$_} for keys %$attrs }
Branch: 3 branches
BranchTrueFalseTotal
if ($ns) { } 13 22 35
elsif (defined $attrs->{'xmlns'}) { } 10 12 22
$_ eq $ns and return $attrs->{$_} 5 3 8
100  
101 # Namespace attribute
102 10 elsif (defined $attrs->{xmlns}) { return $attrs->{xmlns} }
103 }
104  
105 1 return undef;
106 }
107  
108 13 ▶sub next { $_[0]->_maybe($_[0]->_siblings(1, 0)->[1]) }
Subroutine next: called CC=1 SCAR=0.0
Pod documented
109 5 ▶sub next_node { $_[0]->_maybe($_[0]->_siblings(0, 0)->[1]) }
Subroutine next_node: called CC=1 SCAR=0.0
Pod documented
110  
111 sub parent {
112 101 ▶ my $self = shift;
Subroutine parent: called CC=2 SCAR=6.9
Pod documented
113 101 ▶ return undef if $self->tree->[0] eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
if $self->tree->[0] eq "root" 6 95 101
114 95 return $self->_build($self->_parent, $self->xml);
115 }
116  
117 133 ▶sub parse { shift->_delegate(parse => @_) }
Subroutine parse: called CC=1 SCAR=0.0
Pod documented
118  
119 5 ▶sub preceding { _select($_[0]->_collect(@{$_[0]->_siblings(1)->[0]}), $_[1]) }
Subroutine preceding: called CC=1 SCAR=0.0
Pod documented
120 7 ▶sub preceding_nodes { $_[0]->_collect(@{$_[0]->_siblings->[0]}) }
Subroutine preceding_nodes: called CC=1 SCAR=0.0
Pod documented
121  
122 8 ▶sub prepend { shift->_add(0, @_) }
Subroutine prepend: called CC=1 SCAR=0.0
Pod documented
123 4 ▶sub prepend_content { shift->_content(0, 0, @_) }
Subroutine prepend_content: called CC=1 SCAR=0.0
Pod documented
124  
125 7 ▶sub previous { $_[0]->_maybe($_[0]->_siblings(1, -1)->[0]) }
Subroutine previous: called CC=1 SCAR=0.0
Pod documented
126 5 ▶sub previous_node { $_[0]->_maybe($_[0]->_siblings(0, -1)->[0]) }
Subroutine previous_node: called CC=1 SCAR=0.0
Pod documented
127  
128 6 ▶sub remove { shift->replace('') }
Subroutine remove: called CC=1 SCAR=0.0
Pod documented
129  
130 sub replace {
131 22 ▶ my ($self, $new) = @_;
Subroutine replace: called CC=2 SCAR=6.9
Pod documented
132 22 ▶ return $self->parse($new) if (my $tree = $self->tree)->[0] eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
if +(my $tree = $self->tree)->[0] eq "root" 8 14 22
133 14 return $self->_replace($self->_parent, $tree, _nodes($self->_parse($new)));
134 }
135  
136 sub root {
137 11 ▶ my $self = shift;
Subroutine root: called CC=2 SCAR=6.9
Pod documented
138 11 ▶ return $self unless my $tree = $self->_ancestors(1);
Branch: 1 branch
BranchTrueFalseTotal
unless my $tree = $self->_ancestors(1) 3 8 11
139 8 return $self->_build($tree, $self->xml);
140 }
141  
142 sub strip {
143 9 ▶ my $self = shift;
Subroutine strip: called CC=2 SCAR=6.9
Pod documented
144 9 ▶ return $self if (my $tree = $self->tree)->[0] ne 'tag';
Branch: 1 branch
BranchTrueFalseTotal
if +(my $tree = $self->tree)->[0] ne "tag" 2 7 9
145 7 return $self->_replace($tree->[3], $tree, _nodes($tree));
146 }
147  
148 sub tag {
149 85 ▶ my ($self, $tag) = @_;
Subroutine tag: called CC=3 SCAR=11.0
Pod documented
150 85 ▶ return undef if (my $tree = $self->tree)->[0] ne 'tag';
Branch: 1 branch
BranchTrueFalseTotal
if +(my $tree = $self->tree)->[0] ne "tag" 2 83 85
151 83 ▶ return $tree->[1] unless $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless $tag 82 1 83
152 1 $tree->[1] = $tag;
153 1 return $self;
154 }
155  
156 1 ▶sub tap { DOM::Tiny::_Collection::tap(@_) }
Subroutine tap: called CC=1 SCAR=0.0
Pod documented
157  
158 630 ▶sub text { shift->_all_text(0, @_) }
Subroutine text: called CC=1 SCAR=0.0
Pod documented
159  
160 112 ▶sub to_string { shift->_delegate('render') }
Subroutine to_string: called CC=1 SCAR=0.0
Pod documented
161  
162 5687 ▶sub tree { shift->_delegate(tree => @_) }
Subroutine tree: called CC=1 SCAR=0.0
Pod documented
163  
164 878 ▶sub type { shift->tree->[0] }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
165  
166 sub val {
167 25 ▶ my $self = shift;
Subroutine val: called CC=12 SCAR=24.8
Pod documented
168  
169 # "option"
170 25 ▶ return defined($self->{value}) ? $self->{value} : $self->text
Branch: 2 branches
BranchTrueFalseTotal
if (my $tag = $self->tag) eq "option" 9 16 25
defined $self->{'value'} ? : 2 7 9
171 if (my $tag = $self->tag) eq 'option';
172  
173 # "input" ("type=checkbox" and "type=radio")
174 16 ▶ my $type = $self->{type} || '';
Condition100%2/2
$self->{'type'} || ''
l!l
88
MC/DC100%1/1
$self->{'type'} || ''
$self->{'type'}
Truth table100%2/2
A
A= $self->{'type'}
Aresult
11
00
175 16 ▶ return defined $self->{value} ? $self->{value} : 'on'
Branch: 2 branches
BranchTrueFalseTotal
if $tag eq "input" and $type eq "radio" || $type eq "checkbox" 5 11 16
defined $self->{'value'} ? : 3 2 5
Condition100%6/6
$tag eq "input" and $type eq "radio" || $type eq "checkbox"
!ll&&!rl&&r
763
$type eq "radio" or $type eq "checkbox"
l!l&&r!l&&!r
234
MC/DC66%2/3
$tag eq "input" and $type eq "radio" || $type eq "checkbox"
$tag eq "input" $type eq "radio" $type eq "checkbox"
Truth table75%3/4
A and B or C
A= $tag eq "input"B= $type eq "radio"C= $type eq "checkbox"
ABCresult
0XX0
1000
11X1
1011
176 if $tag eq 'input' && ($type eq 'radio' || $type eq 'checkbox');
177  
178 # "textarea", "input" or "button"
179 11 ▶ return $tag eq 'textarea' ? $self->text : $self->{value} if $tag ne 'select';
Branch: 2 branches
BranchTrueFalseTotal
if $tag ne "select" 7 4 11
$tag eq 'textarea' ? : 1 6 7
180  
181 # "select"
182 4 my $v = $self->find('option:checked')->map('val');
183 4 ▶ return exists $self->{multiple} ? $v->size ? $v->to_array : undef : $v->last;
Branch: 2 branches
BranchTrueFalseTotal
exists $self->{'multiple'} ? : 2 2 4
$v->size ? : 1 1 2
184 }
185  
186 7 ▶sub wrap { shift->_wrap(0, @_) }
Subroutine wrap: called CC=1 SCAR=0.0
Pod documented
187 5 ▶sub wrap_content { shift->_wrap(1, @_) }
Subroutine wrap_content: called CC=1 SCAR=0.0
Pod documented
188  
189 2907 ▶sub xml { shift->_delegate(xml => @_) }
Subroutine xml: called CC=1 SCAR=0.0
Pod documented
190  
191 sub _add {
192 15 ▶ my ($self, $offset, $new) = @_;
Subroutine _add: called CC=2 SCAR=6.9
193  
194 15 ▶ return $self if (my $tree = $self->tree)->[0] eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
if +(my $tree = $self->tree)->[0] eq "root" 4 11 15
195  
196 11 my $parent = $self->_parent;
197 11 splice @$parent, _offset($parent, $tree) + $offset, 0,
198 _link($parent, _nodes($self->_parse($new)));
199  
200 11 return $self;
201 }
202  
203 sub _all {
204 21 ▶ map { $_->[0] eq 'tag' ? ($_, _all(_nodes($_))) : ($_) } @_;
Subroutine _all: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_->[0] eq 'tag' ? : 8 52 60
205 }
206  
207 sub _all_text {
208 657 ▶ my ($self, $recurse, $trim) = @_;
Subroutine _all_text: called CC=5 SCAR=16.1
209  
210 # Detect "pre" tag
211 657 my $tree = $self->tree;
212 657 ▶ $trim = 1 unless defined $trim;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $trim 647 10 657
213 657 ▶ map { $_->[1] eq 'pre' and $trim = 0 } $self->_ancestors, $tree
Branch: 2 branches
BranchTrueFalseTotal
if $trim and $tree->[0] ne "root" 641 16 657
$_->[1] eq "pre" and $trim = 0 5 1456 1461
Condition100%3/3
$trim and $tree->[0] ne "root"
!ll&&!rl&&r
106641
MC/DC100%2/2
$trim and $tree->[0] ne "root"
$trim $tree->[0] ne "root"
Truth table100%3/3
A and B
A= $trimB= $tree->[0] ne "root"
ABresult
0X0
100
111
214 if $trim && $tree->[0] ne 'root';
215  
216 657 return _text([_nodes($tree)], $recurse, $trim);
217 }
218  
219 sub _ancestors {
220 677 ▶ my ($self, $root) = @_;
Subroutine _ancestors: called CC=5 SCAR=16.1
221  
222 677 ▶ return () unless my $tree = $self->_parent;
Branch: 1 branch
BranchTrueFalseTotal
unless my $tree = $self->_parent 3 674 677
223 674 my @ancestors;
224 674 ▶ do { push @ancestors, $tree }
Branch: 1 branch
BranchTrueFalseTotal
$tree->[0] eq "tag" and $tree = $tree->[3] and do { do { push @ancestors, $tree } } 872 674 1546
Condition66%2/3
$tree->[0] eq "tag" and $tree = $tree->[3]
!ll&&!rl&&r
6740872
MC/DC50%1/2
$tree->[0] eq "tag" and $tree = $tree->[3]
$tree->[0] eq "tag" $tree = $tree->[3]
Truth table66%2/3
A and B
A= $tree->[0] eq "tag"B= $tree = $tree->[3]
ABresult
0X0
100
111
225 while ($tree->[0] eq 'tag') && ($tree = $tree->[3]);
226 674 ▶ return $root ? $ancestors[-1] : @ancestors[0 .. $#ancestors - 1];
Branch: 1 branch
BranchTrueFalseTotal
$root ? : 8 666 674
227 }
228  
229 1759 ▶sub _build { shift->new->tree(shift)->xml(shift) }
Subroutine _build: called CC=1 SCAR=0.0
230  
231 sub _collect {
232 509 ▶ my $self = shift;
Subroutine _collect: called CC=1 SCAR=0.0
233 509 my $xml = $self->xml;
234 509 return DOM::Tiny::_Collection->new(map { $self->_build($_, $xml) } @_);
235 }
236  
237 sub _content {
238 28 ▶ my ($self, $start, $offset, $new) = @_;
Subroutine _content: called CC=6 SCAR=17.9
239  
240 28 my $tree = $self->tree;
241 28 ▶ unless ($tree->[0] eq 'root' || $tree->[0] eq 'tag') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tree->[0] eq "root" or $tree->[0] eq "tag") 2 26 28
Condition100%3/3
$tree->[0] eq "root" or $tree->[0] eq "tag"
l!l&&r!l&&!r
7192
MC/DC100%2/2
$tree->[0] eq "root" or $tree->[0] eq "tag"
$tree->[0] eq "root" $tree->[0] eq "tag"
Truth table100%3/3
A or B
A= $tree->[0] eq "root"B= $tree->[0] eq "tag"
ABresult
1X1
011
000
242 2 my $old = $self->content;
243 2 ▶ return $self->content($start ? $old . $new : $new . $old);
Branch: 1 branch
BranchTrueFalseTotal
$start ? : 1 1 2
244 }
245  
246 26 ▶ $start = $start ? ($#$tree + 1) : _start($tree);
Branch: 1 branch
BranchTrueFalseTotal
$start ? : 8 18 26
247 26 ▶ $offset = $offset ? $#$tree : 0;
Branch: 1 branch
BranchTrueFalseTotal
$offset ? : 15 11 26
248 26 splice @$tree, $start, $offset, _link($tree, _nodes($self->_parse($new)));
249  
250 26 return $self;
251 }
252  
253 871 ▶sub _css { DOM::Tiny::_CSS->new(tree => shift->tree) }
Subroutine _css: called CC=1 SCAR=0.0
254  
255 sub _delegate {
256 8840 ▶ my ($self, $method) = (shift, shift);
Subroutine _delegate: called CC=2 SCAR=6.9
257 8840 ▶ return $$self->$method unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 5183 3657 8840
258 3657 $$self->$method(@_);
259 3657 return $self;
260 }
261  
262 sub _link {
263 74 ▶ my ($parent, @children) = @_;
Subroutine _link: called CC=3 SCAR=11.0
264  
265 # Link parent to children
266 74 for my $node (@children) {
267 79 ▶ my $offset = $node->[0] eq 'tag' ? 3 : 2;
Branch: 1 branch
BranchTrueFalseTotal
$node->[0] eq 'tag' ? : 38 41 79
268 79 $node->[$offset] = $parent;
269 79 weaken $node->[$offset];
270 }
271  
272 74 return @children;
273 }
274  
275 30 ▶sub _maybe { $_[1] ? $_[0]->_build($_[1], $_[0]->xml) : undef }
Subroutine _maybe: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 20 10 30
276  
277 sub _nodes {
278 1029 ▶ return () unless my $tree = shift;
Subroutine _nodes: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
unless my $tree = shift() 0 1029 1029
279 1029 my @nodes = @$tree[_start($tree) .. $#$tree];
280 1029 ▶ return shift() ? grep { $_->[0] eq 'tag' } @nodes : @nodes;
Branch: 1 branch
BranchTrueFalseTotal
shift() ? : 33 996 1029
281 }
282  
283 sub _offset {
284 37 ▶ my ($parent, $child) = @_;
Subroutine _offset: called CC=3 SCAR=11.0
285 37 my $i = _start($parent);
286 37 ▶ $_ eq $child ? last : $i++ for @$parent[$i .. $#$parent];
Branch: 1 branch
BranchTrueFalseTotal
$_ eq $child ? : 37 25 62
287 37 return $i;
288 }
289  
290 802 ▶sub _parent { $_[0]->tree->[$_[0]->type eq 'tag' ? 3 : 2] }
Subroutine _parent: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->type eq 'tag' ? : 759 43 802
291  
292 61 ▶sub _parse { DOM::Tiny::_HTML->new(xml => shift->xml)->parse(shift)->tree }
Subroutine _parse: called CC=1 SCAR=0.0
293  
294 sub _replace {
295 26 ▶ my ($self, $parent, $child, @nodes) = @_;
Subroutine _replace: called CC=1 SCAR=0.0
296 26 splice @$parent, _offset($parent, $child), 1, _link($parent, @nodes);
297 26 return $self->parent;
298 }
299  
300 sub _select {
301 35 ▶ my ($collection, $selector) = @_;
Subroutine _select: called CC=2 SCAR=6.9
302 35 ▶ return $collection unless $selector;
Branch: 1 branch
BranchTrueFalseTotal
unless $selector 20 15 35
303 15 return $collection->new(grep { $_->matches($selector) } @$collection);
304 }
305  
306 sub _siblings {
307 57 ▶ my ($self, $tags, $i) = @_;
Subroutine _siblings: called CC=10 SCAR=23.0
308  
309 57 ▶ return [] unless my $parent = $self->parent;
Branch: 1 branch
BranchTrueFalseTotal
unless my $parent = $self->parent 6 51 57
310  
311 51 my $tree = $self->tree;
312 51 my (@before, @after, $match);
313 51 for my $node (_nodes($parent->tree)) {
314 284 ▶ ++$match and next if !$match && $node eq $tree;
Branch: 1 branch
BranchTrueFalseTotal
if not $match and $node eq $tree 51 233 284
Condition85%6/7
!$match && $node eq $tree && (++$match && (next))
!ll
23351
not $match and $node eq $tree
!ll&&!rl&&r
1508351
++$match and next
!ll
051
MC/DC0%0/3
!$match && $node eq $tree && (++$match && (next))
not $match $node eq $tree ++$match
Truth table50%2/4
not(A) and B && C
A= not $matchB= $node eq $treeC= ++$match
ABCresult
0XX0
10X0
1100
1111
315 233 ▶ next if $tags && $node->[0] ne 'tag';
Branch: 1 branch
BranchTrueFalseTotal
if $tags and $node->[0] ne "tag" 118 115 233
Condition100%3/3
$tags and $node->[0] ne "tag"
!ll&&!rl&&r
4966118
MC/DC100%2/2
$tags and $node->[0] ne "tag"
$tags $node->[0] ne "tag"
Truth table100%3/3
A and B
A= $tagsB= $node->[0] ne "tag"
ABresult
0X0
100
111
316 115 ▶ $match ? push @after, $node : push @before, $node;
Branch: 1 branch
BranchTrueFalseTotal
$match ? : 71 44 115
317 }
318  
319 51 ▶ return defined $i ? [$before[$i], $after[$i]] : [\@before, \@after];
Branch: 1 branch
BranchTrueFalseTotal
defined $i ? : 28 23 51
320 }
321  
322 sub _squish {
323 675 ▶ my $str = shift;
Subroutine _squish: called CC=1 SCAR=0.0
324 675 $str =~ s/^\s+//;
325 675 $str =~ s/\s+$//;
326 675 $str =~ s/\s+/ /g;
327 675 return $str;
328 }
329  
330 1087 ▶sub _start { $_[0][0] eq 'root' ? 1 : 4 }
Subroutine _start: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0][0] eq 'root' ? : 160 927 1087
331  
332 sub _text {
333 790 ▶ my ($nodes, $recurse, $trim) = @_;
Subroutine _text: called CC=17 SCAR=28.3
334  
335 # Merge successive text nodes
336 790 my $i = 0;
337 790 ▶ while (my $next = $nodes->[$i + 1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $next = $$nodes[$i + 1]) 167 790 957
338 167 ▶ ++$i and next unless $nodes->[$i][0] eq 'text' && $next->[0] eq 'text';
Branch: 1 branch
BranchTrueFalseTotal
unless $nodes->[$i][0] eq "text" and $next->[0] eq "text" 152 15 167
Condition85%6/7
$nodes->[$i][0] eq 'text' && $next->[0] eq 'text' || ++$i && (next)
l!l
15152
$nodes->[$i][0] eq "text" and $next->[0] eq "text"
!ll&&!rl&&r
718115
++$i and next
!ll
0152
MC/DC0%0/3
$nodes->[$i][0] eq 'text' && $next->[0] eq 'text' || ++$i && (next)
$nodes->[$i][0] eq "text" $next->[0] eq "text" ++$i
Truth table20%1/5
A and B || C
A= $nodes->[$i][0] eq "text"B= $next->[0] eq "text"C= ++$i
ABCresult
11X1
0X11
1011
0X00
1000
339 15 splice @$nodes, $i, 2, ['text', $nodes->[$i][1] . $next->[1]];
340 }
341  
342 790 my $text = '';
343 790 for my $node (@$nodes) {
344 932 my $type = $node->[0];
345  
346 # Text
347 932 my $chunk = '';
348 932 ▶ if ($type eq 'text') { $chunk = $trim ? _squish $node->[1] : $node->[1] }
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'text') { } 703 229 932
elsif ($type eq 'cdata' or $type eq 'raw') { } 33 196 229
elsif ($type eq 'tag' and $recurse) { } 133 65 198
$trim ? : 675 28 703
349  
350 # CDATA or raw text
351 33 ▶ elsif ($type eq 'cdata' || $type eq 'raw') { $chunk = $node->[1] }
Condition100%3/3
$type eq "cdata" or $type eq "raw"
l!l&&r!l&&!r
1122196
MC/DC100%2/2
$type eq "cdata" or $type eq "raw"
$type eq "cdata" $type eq "raw"
Truth table100%3/3
A or B
A= $type eq "cdata"B= $type eq "raw"
ABresult
1X1
011
000
352  
353 # Nested tag
354 ▶ elsif ($type eq 'tag' && $recurse) {
Condition100%3/3
$type eq "tag" and $recurse
!ll&&!rl&&r
261133
MC/DC100%2/2
$type eq "tag" and $recurse
$type eq "tag" $recurse
Truth table100%3/3
A and B
A= $type eq "tag"B= $recurse
ABresult
0X0
100
111
355 1 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
356 133 ▶ $chunk = _text([_nodes($node)], 1, $node->[1] eq 'pre' ? 0 : $trim);
Branch: 1 branch
BranchTrueFalseTotal
$node->[1] eq 'pre' ? : 4 129 133
357 }
358  
359 # Add leading whitespace if punctuation allows it
360 932 ▶ $chunk = " $chunk" if $text =~ /\S\z/ && $chunk =~ /^[^.!?,;:\s]+/;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\S\z/ and $chunk =~ /^[^.!?,;:\s]+/ 23 909 932
Condition100%3/3
$text =~ /\S\z/ and $chunk =~ /^[^.!?,;:\s]+/
!ll&&!rl&&r
8129723
MC/DC100%2/2
$text =~ /\S\z/ and $chunk =~ /^[^.!?,;:\s]+/
$text =~ /\S\z/ $chunk =~ /^[^.!?,;:\s]+/
Truth table100%3/3
A and B
A= $text =~ /\S\z/B= $chunk =~ /^[^.!?,;:\s]+/
ABresult
0X0
100
111
361  
362 # Trim whitespace blocks
363 932 ▶ $text .= $chunk if $chunk =~ /\S+/ || !$trim;
Branch: 1 branch
BranchTrueFalseTotal
if $chunk =~ /\S+/ or not $trim 819 113 932
Condition100%3/3
$chunk =~ /\S+/ or not $trim
l!l&&r!l&&!r
80514113
MC/DC100%2/2
$chunk =~ /\S+/ or not $trim
$chunk =~ /\S+/ not $trim
Truth table100%3/3
A or not(B)
A= $chunk =~ /\S+/B= not $trim
ABresult
1X1
011
000
364 }
365  
366 790 return $text;
367 }
368  
369 sub _wrap {
370 12 ▶ my ($self, $content, $new) = @_;
Subroutine _wrap: called CC=9 SCAR=22.0
371  
372 12 ▶ return $self if (my $tree = $self->tree)->[0] eq 'root' && !$content;
Branch: 1 branch
BranchTrueFalseTotal
if +(my $tree = $self->tree)->[0] eq "root" and not $content 1 11 12
Condition100%3/3
+(my $tree = $self->tree)->[0] eq "root" and not $content
!ll&&!rl&&r
1011
MC/DC100%2/2
+(my $tree = $self->tree)->[0] eq "root" and not $content
+(my $tree = $self->tree)->[0] eq "root" not $content
Truth table100%3/3
A and not(B)
A= +(my $tree = $self->tree)->[0] eq "root"B= not $content
ABresult
0X0
100
111
373 11 ▶ return $self if $tree->[0] ne 'root' && $tree->[0] ne 'tag' && $content;
Branch: 1 branch
BranchTrueFalseTotal
if $tree->[0] ne "root" and $tree->[0] ne "tag" and $content 1 10 11
Condition100%6/6
$tree->[0] ne "root" and $tree->[0] ne "tag" and $content
!ll&&!rl&&r
821
$tree->[0] ne "root" and $tree->[0] ne "tag"
!ll&&!rl&&r
173
MC/DC100%3/3
$tree->[0] ne "root" and $tree->[0] ne "tag" and $content
$tree->[0] ne "root" $tree->[0] ne "tag" $content
Truth table100%4/4
A and B and C
A= $tree->[0] ne "root"B= $tree->[0] ne "tag"C= $content
ABCresult
0XX0
10X0
1100
1111
374  
375 # Find innermost tag
376 10 my $current;
377 10 my $first = $new = $self->_parse($new);
378 10 ▶ $current = $first while $first = (_nodes($first, 1))[0];
Branch: 1 branch
BranchTrueFalseTotal
$first = (_nodes($first, 1))[0] and do { $current = $first } 10 10 20
379 10 ▶ return $self unless $current;
Branch: 1 branch
BranchTrueFalseTotal
unless $current 2 8 10
380  
381 # Wrap content
382 8 ▶ if ($content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content) 3 5 8
383 3 push @$current, _link($current, _nodes($tree));
384 3 splice @$tree, _start($tree), $#$tree, _link($tree, _nodes($new));
385 3 return $self;
386 }
387  
388 # Wrap element
389 5 $self->_replace($self->_parent, $tree, _nodes($new));
390 5 push @$current, _link($current, $tree);
391 5 return $self;
392 }
393  
394 1 1;
395  
396 =encoding utf8
397  
398 =head1 NAME
399  
400 DOM::Tiny - Minimalistic HTML/XML DOM parser with CSS selectors
401  
402 =head1 SYNOPSIS
403  
404 use DOM::Tiny;
405  
406 # Parse
407 my $dom = DOM::Tiny->new('<div><p id="a">Test</p><p id="b">123</p></div>');
408  
409 # Find
410 say $dom->at('#b')->text;
411 say $dom->find('p')->map('text')->join("\n");
412 say $dom->find('[id]')->map(attr => 'id')->join("\n");
413  
414 # Iterate
415 $dom->find('p[id]')->reverse->each(sub { say $_->{id} });
416  
417 # Loop
418 for my $e ($dom->find('p[id]')->each) {
419 say $e->{id}, ':', $e->text;
420 }
421  
422 # Modify
423 $dom->find('div p')->last->append('<p id="c">456</p>');
424 $dom->find(':not(p)')->map('strip');
425  
426 # Render
427 say "$dom";
428  
429 =head1 DESCRIPTION
430  
431 L<DOM::Tiny> is a minimalistic and relaxed pure-perl HTML/XML DOM parser based
432 on L<Mojo::DOM>. It supports the L<HTML Living Standard|https://html.spec.whatwg.org/>
433 and L<Extensible Markup Language (XML) 1.0|http://www.w3.org/TR/xml/>, and
434 matching based on L<CSS3 selectors|http://www.w3.org/TR/selectors/>. It will
435 even try to interpret broken HTML and XML, so you should not use it for
436 validation.
437  
438 =head1 NODES AND ELEMENTS
439  
440 When we parse an HTML/XML fragment, it gets turned into a tree of nodes.
441  
442 <!DOCTYPE html>
443 <html>
444 <head><title>Hello</title></head>
445 <body>World!</body>
446 </html>
447  
448 There are currently eight different kinds of nodes, C<cdata>, C<comment>,
449 C<doctype>, C<pi>, C<raw>, C<root>, C<tag> and C<text>. Elements are nodes of
450 the type C<tag>.
451  
452 root
453 |- doctype (html)
454 +- tag (html)
455 |- tag (head)
456 | +- tag (title)
457 | +- raw (Hello)
458 +- tag (body)
459 +- text (World!)
460  
461 While all node types are represented as L<DOM::Tiny> objects, some methods like
462 L</"attr"> and L</"namespace"> only apply to elements.
463  
464 =head1 CASE-SENSITIVITY
465  
466 L<DOM::Tiny> defaults to HTML semantics, that means all tags and attribute
467 names are lowercased and selectors need to be lowercase as well.
468  
469 # HTML semantics
470 my $dom = DOM::Tiny->new('<P ID="greeting">Hi!</P>');
471 say $dom->at('p[id]')->text;
472  
473 If an XML declaration is found, the parser will automatically switch into XML
474 mode and everything becomes case-sensitive.
475  
476 # XML semantics
477 my $dom = DOM::Tiny->new('<?xml version="1.0"?><P ID="greeting">Hi!</P>');
478 say $dom->at('P[ID]')->text;
479  
480 XML detection can also be disabled with the L</"xml"> method.
481  
482 # Force XML semantics
483 my $dom = DOM::Tiny->new->xml(1)->parse('<P ID="greeting">Hi!</P>');
484 say $dom->at('P[ID]')->text;
485  
486 # Force HTML semantics
487 my $dom = DOM::Tiny->new->xml(0)->parse('<P ID="greeting">Hi!</P>');
488 say $dom->at('p[id]')->text;
489  
490 =head1 SELECTORS
491  
492 L<DOM::Tiny> uses a CSS selector engine based on L<Mojo::DOM::CSS>. All CSS
493 selectors that make sense for a standalone parser are supported.
494  
495 =over
496  
497 =item Z<>*
498  
499 Any element.
500  
501 my $all = $dom->find('*');
502  
503 =item E
504  
505 An element of type C<E>.
506  
507 my $title = $dom->at('title');
508  
509 =item E[foo]
510  
511 An C<E> element with a C<foo> attribute.
512  
513 my $links = $dom->find('a[href]');
514  
515 =item E[foo="bar"]
516  
517 An C<E> element whose C<foo> attribute value is exactly equal to C<bar>.
518  
519 my $case_sensitive = $dom->find('input[type="hidden"]');
520 my $case_sensitive = $dom->find('input[type=hidden]');
521  
522 =item E[foo="bar" i]
523  
524 An C<E> element whose C<foo> attribute value is exactly equal to any
525 (ASCII-range) case-permutation of C<bar>. Note that this selector is
526 EXPERIMENTAL and might change without warning!
527  
528 my $case_insensitive = $dom->find('input[type="hidden" i]');
529 my $case_insensitive = $dom->find('input[type=hidden i]');
530 my $case_insensitive = $dom->find('input[class~="foo" i]');
531  
532 This selector is part of
533 L<Selectors Level 4|http://dev.w3.org/csswg/selectors-4>, which is still a work
534 in progress.
535  
536 =item E[foo~="bar"]
537  
538 An C<E> element whose C<foo> attribute value is a list of whitespace-separated
539 values, one of which is exactly equal to C<bar>.
540  
541 my $foo = $dom->find('input[class~="foo"]');
542 my $foo = $dom->find('input[class~=foo]');
543  
544 =item E[foo^="bar"]
545  
546 An C<E> element whose C<foo> attribute value begins exactly with the string
547 C<bar>.
548  
549 my $begins_with = $dom->find('input[name^="f"]');
550 my $begins_with = $dom->find('input[name^=f]');
551  
552 =item E[foo$="bar"]
553  
554 An C<E> element whose C<foo> attribute value ends exactly with the string
555 C<bar>.
556  
557 my $ends_with = $dom->find('input[name$="o"]');
558 my $ends_with = $dom->find('input[name$=o]');
559  
560 =item E[foo*="bar"]
561  
562 An C<E> element whose C<foo> attribute value contains the substring C<bar>.
563  
564 my $contains = $dom->find('input[name*="fo"]');
565 my $contains = $dom->find('input[name*=fo]');
566  
567 =item E:root
568  
569 An C<E> element, root of the document.
570  
571 my $root = $dom->at(':root');
572  
573 =item E:nth-child(n)
574  
575 An C<E> element, the C<n-th> child of its parent.
576  
577 my $third = $dom->find('div:nth-child(3)');
578 my $odd = $dom->find('div:nth-child(odd)');
579 my $even = $dom->find('div:nth-child(even)');
580 my $top3 = $dom->find('div:nth-child(-n+3)');
581  
582 =item E:nth-last-child(n)
583  
584 An C<E> element, the C<n-th> child of its parent, counting from the last one.
585  
586 my $third = $dom->find('div:nth-last-child(3)');
587 my $odd = $dom->find('div:nth-last-child(odd)');
588 my $even = $dom->find('div:nth-last-child(even)');
589 my $bottom3 = $dom->find('div:nth-last-child(-n+3)');
590  
591 =item E:nth-of-type(n)
592  
593 An C<E> element, the C<n-th> sibling of its type.
594  
595 my $third = $dom->find('div:nth-of-type(3)');
596 my $odd = $dom->find('div:nth-of-type(odd)');
597 my $even = $dom->find('div:nth-of-type(even)');
598 my $top3 = $dom->find('div:nth-of-type(-n+3)');
599  
600 =item E:nth-last-of-type(n)
601  
602 An C<E> element, the C<n-th> sibling of its type, counting from the last one.
603  
604 my $third = $dom->find('div:nth-last-of-type(3)');
605 my $odd = $dom->find('div:nth-last-of-type(odd)');
606 my $even = $dom->find('div:nth-last-of-type(even)');
607 my $bottom3 = $dom->find('div:nth-last-of-type(-n+3)');
608  
609 =item E:first-child
610  
611 An C<E> element, first child of its parent.
612  
613 my $first = $dom->find('div p:first-child');
614  
615 =item E:last-child
616  
617 An C<E> element, last child of its parent.
618  
619 my $last = $dom->find('div p:last-child');
620  
621 =item E:first-of-type
622  
623 An C<E> element, first sibling of its type.
624  
625 my $first = $dom->find('div p:first-of-type');
626  
627 =item E:last-of-type
628  
629 An C<E> element, last sibling of its type.
630  
631 my $last = $dom->find('div p:last-of-type');
632  
633 =item E:only-child
634  
635 An C<E> element, only child of its parent.
636  
637 my $lonely = $dom->find('div p:only-child');
638  
639 =item E:only-of-type
640  
641 An C<E> element, only sibling of its type.
642  
643 my $lonely = $dom->find('div p:only-of-type');
644  
645 =item E:empty
646  
647 An C<E> element that has no children (including text nodes).
648  
649 my $empty = $dom->find(':empty');
650  
651 =item E:checked
652  
653 A user interface element C<E> which is checked (for instance a radio-button or
654 checkbox).
655  
656 my $input = $dom->find(':checked');
657  
658 =item E.warning
659  
660 An C<E> element whose class is "warning".
661  
662 my $warning = $dom->find('div.warning');
663  
664 =item E#myid
665  
666 An C<E> element with C<ID> equal to "myid".
667  
668 my $foo = $dom->at('div#foo');
669  
670 =item E:not(s)
671  
672 An C<E> element that does not match simple selector C<s>.
673  
674 my $others = $dom->find('div p:not(:first-child)');
675  
676 =item E F
677  
678 An C<F> element descendant of an C<E> element.
679  
680 my $headlines = $dom->find('div h1');
681  
682 =item E E<gt> F
683  
684 An C<F> element child of an C<E> element.
685  
686 my $headlines = $dom->find('html > body > div > h1');
687  
688 =item E + F
689  
690 An C<F> element immediately preceded by an C<E> element.
691  
692 my $second = $dom->find('h1 + h2');
693  
694 =item E ~ F
695  
696 An C<F> element preceded by an C<E> element.
697  
698 my $second = $dom->find('h1 ~ h2');
699  
700 =item E, F, G
701  
702 Elements of type C<E>, C<F> and C<G>.
703  
704 my $headlines = $dom->find('h1, h2, h3');
705  
706 =item E[foo=bar][bar=baz]
707  
708 An C<E> element whose attributes match all following attribute selectors.
709  
710 my $links = $dom->find('a[foo^=b][foo$=ar]');
711  
712 =back
713  
714 =head1 OPERATORS
715  
716 L<DOM::Tiny> overloads the following operators.
717  
718 =head2 array
719  
720 my @nodes = @$dom;
721  
722 Alias for L</"child_nodes">.
723  
724 # "<!-- Test -->"
725 $dom->parse('<!-- Test --><b>123</b>')->[0];
726  
727 =head2 bool
728  
729 my $bool = !!$dom;
730  
731 Always true.
732  
733 =head2 hash
734  
735 my %attrs = %$dom;
736  
737 Alias for L</"attr">.
738  
739 # "test"
740 $dom->parse('<div id="test">Test</div>')->at('div')->{id};
741  
742 =head2 stringify
743  
744 my $str = "$dom";
745  
746 Alias for L</"to_string">.
747  
748 =head1 METHODS
749  
750 L<DOM::Tiny> implements the following methods.
751  
752 =head2 new
753  
754 my $dom = DOM::Tiny->new;
755 my $dom = DOM::Tiny->new('<foo bar="baz">I ♥ DOM::Tiny!</foo>');
756  
757 Construct a new scalar-based L<DOM::Tiny> object and L</"parse"> HTML/XML
758 fragment if necessary.
759  
760 =head2 all_text
761  
762 my $trimmed = $dom->all_text;
763 my $untrimmed = $dom->all_text(0);
764  
765 Extract text content from all descendant nodes of this element, smart
766 whitespace trimming is enabled by default.
767  
768 # "foo bar baz"
769 $dom->parse("<div>foo\n<p>bar</p>baz\n</div>")->at('div')->all_text;
770  
771 # "foo\nbarbaz\n"
772 $dom->parse("<div>foo\n<p>bar</p>baz\n</div>")->at('div')->all_text(0);
773  
774 =head2 ancestors
775  
776 my $collection = $dom->ancestors;
777 my $collection = $dom->ancestors('div ~ p');
778  
779 Find all ancestor elements of this node matching the CSS selector and return a
780 L<collection|/"COLLECTION METHODS"> containing these elements as L<DOM::Tiny>
781 objects. All selectors listed in L</"SELECTORS"> are supported.
782  
783 # List tag names of ancestor elements
784 say $dom->ancestors->map('tag')->join("\n");
785  
786 =head2 append
787  
788 $dom = $dom->append('<p>I ♥ DOM::Tiny!</p>');
789  
790 Append HTML/XML fragment to this node (for all node types other than C<root>).
791  
792 # "<div><h1>Test</h1><h2>123</h2></div>"
793 $dom->parse('<div><h1>Test</h1></div>')
794 ->at('h1')->append('<h2>123</h2>')->root;
795  
796 # "<p>Test 123</p>"
797 $dom->parse('<p>Test</p>')->at('p')
798 ->child_nodes->first->append(' 123')->root;
799  
800 =head2 append_content
801  
802 $dom = $dom->append_content('<p>I ♥ DOM::Tiny!</p>');
803  
804 Append HTML/XML fragment (for C<root> and C<tag> nodes) or raw content to this
805 node's content.
806  
807 # "<div><h1>Test123</h1></div>"
808 $dom->parse('<div><h1>Test</h1></div>')
809 ->at('h1')->append_content('123')->root;
810  
811 # "<!-- Test 123 --><br>"
812 $dom->parse('<!-- Test --><br>')
813 ->child_nodes->first->append_content('123 ')->root;
814  
815 # "<p>Test<i>123</i></p>"
816 $dom->parse('<p>Test</p>')->at('p')->append_content('<i>123</i>')->root;
817  
818 =head2 at
819  
820 my $result = $dom->at('div ~ p');
821  
822 Find first descendant element of this element matching the CSS selector and
823 return it as a L<DOM::Tiny> object, or C<undef> if none could be found. All
824 selectors listed in L</"SELECTORS"> are supported.
825  
826 # Find first element with "svg" namespace definition
827 my $namespace = $dom->at('[xmlns\:svg]')->{'xmlns:svg'};
828  
829 =head2 attr
830  
831 my $hash = $dom->attr;
832 my $foo = $dom->attr('foo');
833 $dom = $dom->attr({foo => 'bar'});
834 $dom = $dom->attr(foo => 'bar');
835  
836 This element's attributes.
837  
838 # Remove an attribute
839 delete $dom->attr->{id};
840  
841 # Attribute without value
842 $dom->attr(selected => undef);
843  
844 # List id attributes
845 say $dom->find('*')->map(attr => 'id')->compact->join("\n");
846  
847 =head2 child_nodes
848  
849 my $collection = $dom->child_nodes;
850  
851 Return a L<collection|/"COLLECTION METHODS"> containing all child nodes of this
852 element as L<DOM::Tiny> objects.
853  
854 # "<p><b>123</b></p>"
855 $dom->parse('<p>Test<b>123</b></p>')->at('p')->child_nodes->first->remove;
856  
857 # "<!DOCTYPE html>"
858 $dom->parse('<!DOCTYPE html><b>123</b>')->child_nodes->first;
859  
860 # " Test "
861 $dom->parse('<b>123</b><!-- Test -->')->child_nodes->last->content;
862  
863 =head2 children
864  
865 my $collection = $dom->children;
866 my $collection = $dom->children('div ~ p');
867  
868 Find all child elements of this element matching the CSS selector and return a
869 L<collection|/"COLLECTION METHODS"> containing these elements as L<DOM::Tiny>
870 objects. All selectors listed in L</"SELECTORS"> are supported.
871  
872 # Show tag name of random child element
873 say $dom->children->shuffle->first->tag;
874  
875 =head2 content
876  
877 my $str = $dom->content;
878 $dom = $dom->content('<p>I ♥ DOM::Tiny!</p>');
879  
880 Return this node's content or replace it with HTML/XML fragment (for C<root>
881 and C<tag> nodes) or raw content.
882  
883 # "<b>Test</b>"
884 $dom->parse('<div><b>Test</b></div>')->at('div')->content;
885  
886 # "<div><h1>123</h1></div>"
887 $dom->parse('<div><h1>Test</h1></div>')->at('h1')->content('123')->root;
888  
889 # "<p><i>123</i></p>"
890 $dom->parse('<p>Test</p>')->at('p')->content('<i>123</i>')->root;
891  
892 # "<div><h1></h1></div>"
893 $dom->parse('<div><h1>Test</h1></div>')->at('h1')->content('')->root;
894  
895 # " Test "
896 $dom->parse('<!-- Test --><br>')->child_nodes->first->content;
897  
898 # "<div><!-- 123 -->456</div>"
899 $dom->parse('<div><!-- Test -->456</div>')
900 ->at('div')->child_nodes->first->content(' 123 ')->root;
901  
902 =head2 descendant_nodes
903  
904 my $collection = $dom->descendant_nodes;
905  
906 Return a L<collection|/"COLLECTION METHODS"> containing all descendant nodes of
907 this element as L<DOM::Tiny> objects.
908  
909 # "<p><b>123</b></p>"
910 $dom->parse('<p><!-- Test --><b>123<!-- 456 --></b></p>')
911 ->descendant_nodes->grep(sub { $_->type eq 'comment' })
912 ->map('remove')->first;
913  
914 # "<p><b>test</b>test</p>"
915 $dom->parse('<p><b>123</b>456</p>')
916 ->at('p')->descendant_nodes->grep(sub { $_->type eq 'text' })
917 ->map(content => 'test')->first->root;
918  
919 =head2 find
920  
921 my $collection = $dom->find('div ~ p');
922  
923 Find all descendant elements of this element matching the CSS selector and
924 return a L<collection|/"COLLECTION METHODS"> containing these elements as
925 L<DOM::Tiny> objects. All selectors listed in L</"SELECTORS"> are supported.
926  
927 # Find a specific element and extract information
928 my $id = $dom->find('div')->[23]{id};
929  
930 # Extract information from multiple elements
931 my @headers = $dom->find('h1, h2, h3')->map('text')->each;
932  
933 # Count all the different tags
934 my $hash = $dom->find('*')->reduce(sub { $a->{$b->tag}++; $a }, {});
935  
936 # Find elements with a class that contains dots
937 my @divs = $dom->find('div.foo\.bar')->each;
938  
939 =head2 following
940  
941 my $collection = $dom->following;
942 my $collection = $dom->following('div ~ p');
943  
944 Find all sibling elements after this node matching the CSS selector and return
945 a L<collection|/"COLLECTION METHODS"> containing these elements as L<DOM::Tiny>
946 objects. All selectors listen in L</"SELECTORS"> are supported.
947  
948 # List tags of sibling elements after this node
949 say $dom->following->map('tag')->join("\n");
950  
951 =head2 following_nodes
952  
953 my $collection = $dom->following_nodes;
954  
955 Return a L<collection|/"COLLECTION METHODS"> containing all sibling nodes after
956 this node as L<DOM::Tiny> objects.
957  
958 # "C"
959 $dom->parse('<p>A</p><!-- B -->C')->at('p')->following_nodes->last->content;
960  
961 =head2 matches
962  
963 my $bool = $dom->matches('div ~ p');
964  
965 Check if this element matches the CSS selector. All selectors listed in
966 L</"SELECTORS"> are supported.
967  
968 # True
969 $dom->parse('<p class="a">A</p>')->at('p')->matches('.a');
970 $dom->parse('<p class="a">A</p>')->at('p')->matches('p[class]');
971  
972 # False
973 $dom->parse('<p class="a">A</p>')->at('p')->matches('.b');
974 $dom->parse('<p class="a">A</p>')->at('p')->matches('p[id]');
975  
976 =head2 namespace
977  
978 my $namespace = $dom->namespace;
979  
980 Find this element's namespace, or return C<undef> if none could be found.
981  
982 # Find namespace for an element with namespace prefix
983 my $namespace = $dom->at('svg > svg\:circle')->namespace;
984  
985 # Find namespace for an element that may or may not have a namespace prefix
986 my $namespace = $dom->at('svg > circle')->namespace;
987  
988 =head2 next
989  
990 my $sibling = $dom->next;
991  
992 Return L<DOM::Tiny> object for next sibling element, or C<undef> if there are
993 no more siblings.
994  
995 # "<h2>123</h2>"
996 $dom->parse('<div><h1>Test</h1><h2>123</h2></div>')->at('h1')->next;
997  
998 =head2 next_node
999  
1000 my $sibling = $dom->next_node;
1001  
1002 Return L<DOM::Tiny> object for next sibling node, or C<undef> if there are no
1003 more siblings.
1004  
1005 # "456"
1006 $dom->parse('<p><b>123</b><!-- Test -->456</p>')
1007 ->at('b')->next_node->next_node;
1008  
1009 # " Test "
1010 $dom->parse('<p><b>123</b><!-- Test -->456</p>')
1011 ->at('b')->next_node->content;
1012  
1013 =head2 parent
1014  
1015 my $parent = $dom->parent;
1016  
1017 Return L<DOM::Tiny> object for parent of this node, or C<undef> if this node
1018 has no parent.
1019  
1020 # "<b><i>Test</i></b>"
1021 $dom->parse('<p><b><i>Test</i></b></p>')->at('i')->parent;
1022  
1023 =head2 parse
1024  
1025 $dom = $dom->parse('<foo bar="baz">I ♥ DOM::Tiny!</foo>');
1026  
1027 Parse HTML/XML fragment.
1028  
1029 # Parse XML
1030 my $dom = DOM::Tiny->new->xml(1)->parse('<foo>I ♥ DOM::Tiny!</foo>');
1031  
1032 =head2 preceding
1033  
1034 my $collection = $dom->preceding;
1035 my $collection = $dom->preceding('div ~ p');
1036  
1037 Find all sibling elements before this node matching the CSS selector and return
1038 a L<collection|/"COLLECTION METHODS"> containing these elements as L<DOM::Tiny>
1039 objects. All selectors listed in L</"SELECTORS"> are supported.
1040  
1041 # List tags of sibling elements before this node
1042 say $dom->preceding->map('tag')->join("\n");
1043  
1044 =head2 preceding_nodes
1045  
1046 my $collection = $dom->preceding_nodes;
1047  
1048 Return a L<collection|/"COLLECTION METHODS"> containing all sibling nodes
1049 before this node as L<DOM::Tiny> objects.
1050  
1051 # "A"
1052 $dom->parse('A<!-- B --><p>C</p>')->at('p')->preceding_nodes->first->content;
1053  
1054 =head2 prepend
1055  
1056 $dom = $dom->prepend('<p>I ♥ DOM::Tiny!</p>');
1057  
1058 Prepend HTML/XML fragment to this node (for all node types other than C<root>).
1059  
1060 # "<div><h1>Test</h1><h2>123</h2></div>"
1061 $dom->parse('<div><h2>123</h2></div>')
1062 ->at('h2')->prepend('<h1>Test</h1>')->root;
1063  
1064 # "<p>Test 123</p>"
1065 $dom->parse('<p>123</p>')
1066 ->at('p')->child_nodes->first->prepend('Test ')->root;
1067  
1068 =head2 prepend_content
1069  
1070 $dom = $dom->prepend_content('<p>I ♥ DOM::Tiny!</p>');
1071  
1072 Prepend HTML/XML fragment (for C<root> and C<tag> nodes) or raw content to this
1073 node's content.
1074  
1075 # "<div><h2>Test123</h2></div>"
1076 $dom->parse('<div><h2>123</h2></div>')
1077 ->at('h2')->prepend_content('Test')->root;
1078  
1079 # "<!-- Test 123 --><br>"
1080 $dom->parse('<!-- 123 --><br>')
1081 ->child_nodes->first->prepend_content(' Test')->root;
1082  
1083 # "<p><i>123</i>Test</p>"
1084 $dom->parse('<p>Test</p>')->at('p')->prepend_content('<i>123</i>')->root;
1085  
1086 =head2 previous
1087  
1088 my $sibling = $dom->previous;
1089  
1090 Return L<DOM::Tiny> object for previous sibling element, or C<undef> if there
1091 are no more siblings.
1092  
1093 # "<h1>Test</h1>"
1094 $dom->parse('<div><h1>Test</h1><h2>123</h2></div>')->at('h2')->previous;
1095  
1096 =head2 previous_node
1097  
1098 my $sibling = $dom->previous_node;
1099  
1100 Return L<DOM::Tiny> object for previous sibling node, or C<undef> if there are
1101 no more siblings.
1102  
1103 # "123"
1104 $dom->parse('<p>123<!-- Test --><b>456</b></p>')
1105 ->at('b')->previous_node->previous_node;
1106  
1107 # " Test "
1108 $dom->parse('<p>123<!-- Test --><b>456</b></p>')
1109 ->at('b')->previous_node->content;
1110  
1111 =head2 remove
1112  
1113 my $parent = $dom->remove;
1114  
1115 Remove this node and return L</"root"> (for C<root> nodes) or L</"parent">.
1116  
1117 # "<div></div>"
1118 $dom->parse('<div><h1>Test</h1></div>')->at('h1')->remove;
1119  
1120 # "<p><b>456</b></p>"
1121 $dom->parse('<p>123<b>456</b></p>')
1122 ->at('p')->child_nodes->first->remove->root;
1123  
1124 =head2 replace
1125  
1126 my $parent = $dom->replace('<div>I ♥ DOM::Tiny!</div>');
1127  
1128 Replace this node with HTML/XML fragment and return L</"root"> (for C<root>
1129 nodes) or L</"parent">.
1130  
1131 # "<div><h2>123</h2></div>"
1132 $dom->parse('<div><h1>Test</h1></div>')->at('h1')->replace('<h2>123</h2>');
1133  
1134 # "<p><b>123</b></p>"
1135 $dom->parse('<p>Test</p>')
1136 ->at('p')->child_nodes->[0]->replace('<b>123</b>')->root;
1137  
1138 =head2 root
1139  
1140 my $root = $dom->root;
1141  
1142 Return L<DOM::Tiny> object for C<root> node.
1143  
1144 =head2 strip
1145  
1146 my $parent = $dom->strip;
1147  
1148 Remove this element while preserving its content and return L</"parent">.
1149  
1150 # "<div>Test</div>"
1151 $dom->parse('<div><h1>Test</h1></div>')->at('h1')->strip;
1152  
1153 =head2 tag
1154  
1155 my $tag = $dom->tag;
1156 $dom = $dom->tag('div');
1157  
1158 This element's tag name.
1159  
1160 # List tag names of child elements
1161 say $dom->children->map('tag')->join("\n");
1162  
1163 =head2 tap
1164  
1165 $dom = $dom->tap(sub {...});
1166  
1167 Equivalent to L<Mojo::Base/"tap">.
1168  
1169 =head2 text
1170  
1171 my $trimmed = $dom->text;
1172 my $untrimmed = $dom->text(0);
1173  
1174 Extract text content from this element only (not including child elements),
1175 smart whitespace trimming is enabled by default.
1176  
1177 # "foo baz"
1178 $dom->parse("<div>foo\n<p>bar</p>baz\n</div>")->at('div')->text;
1179  
1180 # "foo\nbaz\n"
1181 $dom->parse("<div>foo\n<p>bar</p>baz\n</div>")->at('div')->text(0);
1182  
1183 =head2 to_string
1184  
1185 my $str = $dom->to_string;
1186  
1187 Render this node and its content to HTML/XML.
1188  
1189 # "<b>Test</b>"
1190 $dom->parse('<div><b>Test</b></div>')->at('div b')->to_string;
1191  
1192 =head2 tree
1193  
1194 my $tree = $dom->tree;
1195 $dom = $dom->tree(['root']);
1196  
1197 Document Object Model. Note that this structure should only be used very
1198 carefully since it is very dynamic.
1199  
1200 =head2 type
1201  
1202 my $type = $dom->type;
1203  
1204 This node's type, usually C<cdata>, C<comment>, C<doctype>, C<pi>, C<raw>,
1205 C<root>, C<tag> or C<text>.
1206  
1207 # "cdata"
1208 $dom->parse('<![CDATA[Test]]>')->child_nodes->first->type;
1209  
1210 # "comment"
1211 $dom->parse('<!-- Test -->')->child_nodes->first->type;
1212  
1213 # "doctype"
1214 $dom->parse('<!DOCTYPE html>')->child_nodes->first->type;
1215  
1216 # "pi"
1217 $dom->parse('<?xml version="1.0"?>')->child_nodes->first->type;
1218  
1219 # "raw"
1220 $dom->parse('<title>Test</title>')->at('title')->child_nodes->first->type;
1221  
1222 # "root"
1223 $dom->parse('<p>Test</p>')->type;
1224  
1225 # "tag"
1226 $dom->parse('<p>Test</p>')->at('p')->type;
1227  
1228 # "text"
1229 $dom->parse('<p>Test</p>')->at('p')->child_nodes->first->type;
1230  
1231 =head2 val
1232  
1233 my $value = $dom->val;
1234  
1235 Extract value from form element (such as C<button>, C<input>, C<option>,
1236 C<select> and C<textarea>), or return C<undef> if this element has no value. In
1237 the case of C<select> with C<multiple> attribute, find C<option> elements with
1238 C<selected> attribute and return an array reference with all values, or
1239 C<undef> if none could be found.
1240  
1241 # "a"
1242 $dom->parse('<input name=test value=a>')->at('input')->val;
1243  
1244 # "b"
1245 $dom->parse('<textarea>b</textarea>')->at('textarea')->val;
1246  
1247 # "c"
1248 $dom->parse('<option value="c">Test</option>')->at('option')->val;
1249  
1250 # "d"
1251 $dom->parse('<select><option selected>d</option></select>')
1252 ->at('select')->val;
1253  
1254 # "e"
1255 $dom->parse('<select multiple><option selected>e</option></select>')
1256 ->at('select')->val->[0];
1257  
1258 # "on"
1259 $dom->parse('<input name=test type=checkbox>')->at('input')->val;
1260  
1261 =head2 wrap
1262  
1263 $dom = $dom->wrap('<div></div>');
1264  
1265 Wrap HTML/XML fragment around this node (for all node types other than C<root>),
1266 placing it as the last child of the first innermost element.
1267  
1268 # "<p>123<b>Test</b></p>"
1269 $dom->parse('<b>Test</b>')->at('b')->wrap('<p>123</p>')->root;
1270  
1271 # "<div><p><b>Test</b></p>123</div>"
1272 $dom->parse('<b>Test</b>')->at('b')->wrap('<div><p></p>123</div>')->root;
1273  
1274 # "<p><b>Test</b></p><p>123</p>"
1275 $dom->parse('<b>Test</b>')->at('b')->wrap('<p></p><p>123</p>')->root;
1276  
1277 # "<p><b>Test</b></p>"
1278 $dom->parse('<p>Test</p>')->at('p')->child_nodes->first->wrap('<b>')->root;
1279  
1280 =head2 wrap_content
1281  
1282 $dom = $dom->wrap_content('<div></div>');
1283  
1284 Wrap HTML/XML fragment around this node's content (for C<root> and C<tag>
1285 nodes), placing it as the last children of the first innermost element.
1286  
1287 # "<p><b>123Test</b></p>"
1288 $dom->parse('<p>Test<p>')->at('p')->wrap_content('<b>123</b>')->root;
1289  
1290 # "<p><b>Test</b></p><p>123</p>"
1291 $dom->parse('<b>Test</b>')->wrap_content('<p></p><p>123</p>');
1292  
1293 =head2 xml
1294  
1295 my $bool = $dom->xml;
1296 $dom = $dom->xml($bool);
1297  
1298 Disable HTML semantics in parser and activate case-sensitivity, defaults to
1299 auto detection based on XML declarations.
1300  
1301 =head1 COLLECTION METHODS
1302  
1303 Some L<DOM::Tiny> methods return an array-based collection object based on
1304 L<Mojo::Collection>, which can either be accessed directly as an array
1305 reference, or with the following methods.
1306  
1307 # Chain methods
1308 $collection->map(sub { ucfirst })->shuffle->each(sub {
1309 my ($word, $num) = @_;
1310 say "$num: $word";
1311 });
1312  
1313 # Access array directly to manipulate collection
1314 $collection->[23] += 100;
1315 say for @$collection;
1316  
1317 =head2 compact
1318  
1319 my $new = $collection->compact;
1320  
1321 Create a new collection with all elements that are defined and not an empty
1322 string.
1323  
1324 # $collection contains (0, 1, undef, 2, '', 3)
1325 $collection->compact->join(', '); # "0, 1, 2, 3"
1326  
1327 =head2 each
1328  
1329 my @elements = $collection->each;
1330 $collection = $collection->each(sub {...});
1331  
1332 Evaluate callback for each element in collection or return all elements as a
1333 list if none has been provided. The element will be the first argument passed
1334 to the callback and is also available as C<$_>.
1335  
1336 # Make a numbered list
1337 $collection->each(sub {
1338 my ($e, $num) = @_;
1339 say "$num: $e";
1340 });
1341  
1342 =head2 first
1343  
1344 my $first = $collection->first;
1345 my $first = $collection->first(qr/foo/);
1346 my $first = $collection->first(sub {...});
1347 my $first = $collection->first($method);
1348 my $first = $collection->first($method, @args);
1349  
1350 Evaluate regular expression/callback for, or call method on, each element in
1351 collection and return the first one that matched the regular expression, or for
1352 which the callback/method returned true. The element will be the first argument
1353 passed to the callback and is also available as C<$_>.
1354  
1355 # Longer version
1356 my $first = $collection->first(sub { $_->$method(@args) });
1357  
1358 # Find first value that contains the word "tiny"
1359 my $interesting = $collection->first(qr/tiny/i);
1360  
1361 # Find first value that is greater than 5
1362 my $greater = $collection->first(sub { $_ > 5 });
1363  
1364 =head2 flatten
1365  
1366 my $new = $collection->flatten;
1367  
1368 Flatten nested collections/arrays recursively and create a new collection with
1369 all elements.
1370  
1371 # $collection contains (1, [2, [3, 4], 5, [6]], 7)
1372 $collection->flatten->join(', '); # "1, 2, 3, 4, 5, 6, 7"
1373  
1374 =head2 grep
1375  
1376 my $new = $collection->grep(qr/foo/);
1377 my $new = $collection->grep(sub {...});
1378 my $new = $collection->grep($method);
1379 my $new = $collection->grep($method, @args);
1380  
1381 Evaluate regular expression/callback for, or call method on, each element in
1382 collection and create a new collection with all elements that matched the
1383 regular expression, or for which the callback/method returned true. The element
1384 will be the first argument passed to the callback and is also available as
1385 C<$_>.
1386  
1387 # Longer version
1388 my $new = $collection->grep(sub { $_->$method(@args) });
1389  
1390 # Find all values that contain the word "tiny"
1391 my $interesting = $collection->grep(qr/tiny/i);
1392  
1393 # Find all values that are greater than 5
1394 my $greater = $collection->grep(sub { $_ > 5 });
1395  
1396 =head2 join
1397  
1398 my $stream = $collection->join;
1399 my $stream = $collection->join("\n");
1400  
1401 Turn collection into string.
1402  
1403 # Join all values with commas
1404 $collection->join(', ');
1405  
1406 =head2 last
1407  
1408 my $last = $collection->last;
1409  
1410 Return the last element in collection.
1411  
1412 =head2 map
1413  
1414 my $new = $collection->map(sub {...});
1415 my $new = $collection->map($method);
1416 my $new = $collection->map($method, @args);
1417  
1418 Evaluate callback for, or call method on, each element in collection and create
1419 a new collection from the results. The element will be the first argument
1420 passed to the callback and is also available as C<$_>.
1421  
1422 # Longer version
1423 my $new = $collection->map(sub { $_->$method(@args) });
1424  
1425 # Append the word "tiny" to all values
1426 my $domified = $collection->map(sub { $_ . 'tiny' });
1427  
1428 =head2 reduce
1429  
1430 my $result = $collection->reduce(sub {...});
1431 my $result = $collection->reduce(sub {...}, $initial);
1432  
1433 Reduce elements in collection with callback, the first element will be used as
1434 initial value if none has been provided.
1435  
1436 # Calculate the sum of all values
1437 my $sum = $collection->reduce(sub { $a + $b });
1438  
1439 # Count how often each value occurs in collection
1440 my $hash = $collection->reduce(sub { $a->{$b}++; $a }, {});
1441  
1442 =head2 reverse
1443  
1444 my $new = $collection->reverse;
1445  
1446 Create a new collection with all elements in reverse order.
1447  
1448 =head2 slice
1449  
1450 my $new = $collection->slice(4 .. 7);
1451  
1452 Create a new collection with all selected elements.
1453  
1454 # $collection contains ('A', 'B', 'C', 'D', 'E')
1455 $collection->slice(1, 2, 4)->join(' '); # "B C E"
1456  
1457 =head2 shuffle
1458  
1459 my $new = $collection->shuffle;
1460  
1461 Create a new collection with all elements in random order.
1462  
1463 =head2 size
1464  
1465 my $size = $collection->size;
1466  
1467 Number of elements in collection.
1468  
1469 =head2 sort
1470  
1471 my $new = $collection->sort;
1472 my $new = $collection->sort(sub {...});
1473  
1474 Sort elements based on return value of callback and create a new collection
1475 from the results.
1476  
1477 # Sort values case-insensitive
1478 my $case_insensitive = $collection->sort(sub { uc($a) cmp uc($b) });
1479  
1480 =head2 tap
1481  
1482 $collection = $collection->tap(sub {...});
1483  
1484 Equivalent to L<Mojo::Base/"tap">.
1485  
1486 =head2 to_array
1487  
1488 my $array = $collection->to_array;
1489  
1490 Turn collection into array reference.
1491  
1492 =head2 uniq
1493  
1494 my $new = $collection->uniq;
1495 my $new = $collection->uniq(sub {...});
1496 my $new = $collection->uniq($method);
1497 my $new = $collection->uniq($method, @args);
1498  
1499 Create a new collection without duplicate elements, using the string
1500 representation of either the elements or the return value of the
1501 callback/method.
1502  
1503 # Longer version
1504 my $new = $collection->uniq(sub { $_->$method(@args) });
1505  
1506 # $collection contains ('foo', 'bar', 'bar', 'baz')
1507 $collection->uniq->join(' '); # "foo bar baz"
1508  
1509 # $collection contains ([1, 2], [2, 1], [3, 2])
1510 $collection->uniq(sub{ $_->[1] })->to_array; # "[[1, 2], [2, 1]]"
1511  
1512 =head1 BUGS
1513  
1514 Report any issues on the public bugtracker.
1515  
1516 =head1 AUTHOR
1517  
1518 Dan Book <dbook@cpan.org>
1519  
1520 Code and tests adapted from L<Mojo::DOM>, a lightweight DOM parser by the L<Mojolicious> team.
1521  
1522 =head1 CONTRIBUTORS
1523  
1524 =over
1525  
1526 =item Matt S Trout (mst)
1527  
1528 =back
1529  
1530 =head1 COPYRIGHT AND LICENSE
1531  
1532 Copyright (c) 2008-2015 Sebastian Riedel.
1533  
1534 Copyright (c) 2015 L</"AUTHOR"> and L</"CONTRIBUTORS"> for adaptation to standalone format.
1535  
1536 This is free software, licensed under:
1537  
1538 The Artistic License 2.0 (GPL Compatible)
1539  
1540 =head1 SEE ALSO
1541  
1542 L<Mojo::DOM>, L<HTML::TreeBuilder>, L<XML::LibXML>, L<XML::Twig>, L<XML::Smart>
1543  
1544 =for Pod::Coverage TO_JSON
1545  
1546 =cut
« Tiny/_CSS.pm ↑ Summary Tiny/_HTML.pm »