line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2004-2005 Timothy Appnel |
2
|
|
|
|
|
|
|
# http://www.timaoutloud.org/ |
3
|
|
|
|
|
|
|
# This code is released under the Artistic License. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# XML::Parser::Style::Elemental - A flexible and extensible object |
6
|
|
|
|
|
|
|
# tree style for XML::Parser. DEPRECATED. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package XML::Parser::Style::Elemental; |
10
|
1
|
|
|
1
|
|
2620
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
124
|
|
11
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
462
|
|
|
1
|
|
|
|
|
1163
|
|
14
|
|
|
|
|
|
|
$VERSION = '0.72'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub Init { |
17
|
0
|
|
|
0
|
0
|
|
my $xp = shift; |
18
|
0
|
|
0
|
|
|
|
$xp->{Elemental} ||= {}; |
19
|
0
|
|
|
|
|
|
my $e = $xp->{Elemental}; |
20
|
0
|
0
|
0
|
|
|
|
if ($xp->{Pkg} eq 'main' || !defined $xp->{Pkg}) { |
21
|
0
|
|
0
|
|
|
|
$e->{Document} ||= 'XML::Elemental::Document'; |
22
|
0
|
|
0
|
|
|
|
$e->{Element} ||= 'XML::Elemental::Element'; |
23
|
0
|
|
0
|
|
|
|
$e->{Characters} ||= 'XML::Elemental::Characters'; |
24
|
|
|
|
|
|
|
} |
25
|
0
|
|
|
|
|
|
map { eval "use $e->{$_}" } qw( Document Element Characters); |
|
0
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
$xp->{__doc} = $e->{Document}->new; |
27
|
0
|
|
|
|
|
|
push(@{$xp->{__stack}}, $xp->{__doc}); |
|
0
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub Start { |
31
|
0
|
|
|
0
|
0
|
|
my $xp = shift; |
32
|
0
|
|
|
|
|
|
my $tag = shift; |
33
|
0
|
|
|
|
|
|
my $node = $xp->{Elemental}->{Element}->new(); |
34
|
0
|
|
|
|
|
|
$node->name(ns_qualify($xp, $tag)); |
35
|
0
|
|
|
|
|
|
$node->parent($xp->{__stack}->[-1]); |
36
|
0
|
0
|
|
|
|
|
if (@_) { |
37
|
0
|
|
|
|
|
|
$node->attributes({}); |
38
|
0
|
|
|
|
|
|
while (@_) { |
39
|
0
|
|
|
|
|
|
my ($key, $value) = (shift @_, shift @_); |
40
|
0
|
|
|
|
|
|
$node->attributes->{ns_qualify($xp, $key, $tag)} = $value; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
0
|
0
|
|
|
|
|
$node->parent->contents([]) unless $node->parent->contents; |
44
|
0
|
|
|
|
|
|
push(@{$node->parent->contents}, $node); |
|
0
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
push(@{$xp->{__stack}}, $node); |
|
0
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub Char { |
49
|
0
|
|
|
0
|
0
|
|
my ($xp, $data) = @_; |
50
|
0
|
|
|
|
|
|
my $parent = $xp->{__stack}->[-1]; |
51
|
0
|
0
|
|
|
|
|
$parent->contents([]) unless $parent->contents; |
52
|
0
|
|
|
|
|
|
my $contents = $parent->contents(); |
53
|
0
|
|
|
|
|
|
my $class = $xp->{Elemental}->{Characters}; |
54
|
0
|
0
|
0
|
|
|
|
unless ($contents && ref($contents->[-1]) eq $class) { |
55
|
0
|
0
|
0
|
|
|
|
return if ($xp->{Elemental}->{No_Whitespace} && $data !~ /\S/); |
56
|
0
|
|
|
|
|
|
my $node = $class->new(); |
57
|
0
|
|
|
|
|
|
$node->parent($parent); |
58
|
0
|
|
|
|
|
|
$node->data($data); |
59
|
0
|
|
|
|
|
|
push(@{$contents}, $node); |
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
0
|
|
0
|
|
|
|
my $d = $contents->[-1]->data() || ''; |
63
|
0
|
0
|
0
|
|
|
|
return if ($xp->{Elemental}->{No_Whitespace} && $d !~ /\S/); |
64
|
0
|
|
|
|
|
|
$contents->[-1]->data("$d$data"); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
0
|
0
|
|
sub End { pop(@{$_[0]->{__stack}}) } |
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub Final { |
71
|
0
|
|
|
0
|
0
|
|
delete $_[0]->{__stack}; |
72
|
0
|
|
|
|
|
|
$_[0]->{__doc}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub ns_qualify { |
76
|
0
|
0
|
|
0
|
0
|
|
return $_[1] unless $_[0]->{Namespaces}; |
77
|
0
|
|
0
|
|
|
|
my $ns = $_[0]->namespace($_[1]) || $_[0]->namespace($_[2]); |
78
|
0
|
0
|
|
|
|
|
return $_[1] unless $ns; |
79
|
0
|
0
|
|
|
|
|
$ns =~ m!(/|#)$! ? "$ns$_[1]" : "$ns/$_[1]"; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |