| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PPM::XML::Element; |
|
2
|
2
|
|
|
2
|
|
7
|
use vars qw( $VERSION ); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
90
|
|
|
3
|
|
|
|
|
|
|
$VERSION = '0.01_01'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
# PPM::XML::Element |
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
# Base class for XML Elements. Provides the ability to output the XML document |
|
9
|
|
|
|
|
|
|
# once it's been parsed using the XML::Parser module. |
|
10
|
|
|
|
|
|
|
# |
|
11
|
|
|
|
|
|
|
############################################################################### |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
############################################################################### |
|
14
|
|
|
|
|
|
|
# Required inclusions. |
|
15
|
|
|
|
|
|
|
############################################################################### |
|
16
|
2
|
|
|
2
|
|
1117
|
use HTML::Entities; # Needed for escaping char entities |
|
|
2
|
|
|
|
|
23769
|
|
|
|
2
|
|
|
|
|
1254
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
############################################################################### |
|
19
|
|
|
|
|
|
|
# Allow for creation via 'new'. |
|
20
|
|
|
|
|
|
|
############################################################################### |
|
21
|
|
|
|
|
|
|
sub new |
|
22
|
|
|
|
|
|
|
{ |
|
23
|
0
|
|
|
0
|
0
|
|
my ($class, %args) = @_; |
|
24
|
0
|
|
|
|
|
|
bless \%args, $class; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
############################################################################### |
|
28
|
|
|
|
|
|
|
# Subroutine: output |
|
29
|
|
|
|
|
|
|
############################################################################### |
|
30
|
|
|
|
|
|
|
# Outputs the entire XML document on the currently selected filehandle. |
|
31
|
|
|
|
|
|
|
############################################################################### |
|
32
|
|
|
|
|
|
|
sub output |
|
33
|
|
|
|
|
|
|
{ |
|
34
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
35
|
0
|
|
|
|
|
|
print $self->as_text(); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
############################################################################### |
|
39
|
|
|
|
|
|
|
# Subroutine: content |
|
40
|
|
|
|
|
|
|
############################################################################### |
|
41
|
|
|
|
|
|
|
# Returns a string containing all of the content of this element. |
|
42
|
|
|
|
|
|
|
############################################################################### |
|
43
|
|
|
|
|
|
|
sub content |
|
44
|
|
|
|
|
|
|
{ |
|
45
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
46
|
0
|
|
|
|
|
|
my $kids = $self->{'Kids'}; |
|
47
|
0
|
0
|
0
|
|
|
|
return unless (defined $kids and ref($kids) eq 'ARRAY'); |
|
48
|
0
|
|
|
|
|
|
my @kids = @{ $kids }; |
|
|
0
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $text; |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if (@kids > 0) |
|
52
|
|
|
|
|
|
|
{ |
|
53
|
0
|
|
|
|
|
|
foreach (@kids) |
|
54
|
|
|
|
|
|
|
{ |
|
55
|
|
|
|
|
|
|
# Allow for outputting of char data |
|
56
|
0
|
0
|
|
|
|
|
if ((ref $_) =~ /::Characters$/o) |
|
57
|
0
|
|
|
|
|
|
{ $text .= encode_entities( $_->{'Text'} ); } |
|
58
|
|
|
|
|
|
|
else |
|
59
|
0
|
|
|
|
|
|
{ $text .= $_->as_text(); } |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return $text; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
############################################################################### |
|
67
|
|
|
|
|
|
|
# Subroutine: add_child ($elemref) |
|
68
|
|
|
|
|
|
|
############################################################################### |
|
69
|
|
|
|
|
|
|
# Adds a new child element to ourselves. |
|
70
|
|
|
|
|
|
|
############################################################################### |
|
71
|
|
|
|
|
|
|
sub add_child (\$) |
|
72
|
|
|
|
|
|
|
{ |
|
73
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
74
|
0
|
|
|
|
|
|
my $elemref = shift; |
|
75
|
0
|
|
|
|
|
|
push( @{$self->{'Kids'}}, $elemref ); |
|
|
0
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
############################################################################### |
|
79
|
|
|
|
|
|
|
# Subroutine: remove_child ($elemref) |
|
80
|
|
|
|
|
|
|
############################################################################### |
|
81
|
|
|
|
|
|
|
# Removes a child element from ourselves. Returns non-zero if it was able to |
|
82
|
|
|
|
|
|
|
# remove the child element, and zero if it was unable to do so. |
|
83
|
|
|
|
|
|
|
############################################################################### |
|
84
|
|
|
|
|
|
|
sub remove_child |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
87
|
0
|
|
|
|
|
|
my $elemref = shift; |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
foreach my $idx (0 .. @{$self->{'Kids'}}) |
|
|
0
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
{ |
|
91
|
0
|
0
|
|
|
|
|
if ($self->{'Kids'}[$idx] == $elemref) |
|
92
|
|
|
|
|
|
|
{ |
|
93
|
0
|
|
|
|
|
|
splice( @{$self->{'Kids'}}, $idx, 1 ); |
|
|
0
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return 1; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return 0; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
############################################################################### |
|
102
|
|
|
|
|
|
|
# Subroutine: add_text ($text) |
|
103
|
|
|
|
|
|
|
############################################################################### |
|
104
|
|
|
|
|
|
|
# Adds character data to the given element. Returns undef if unable to add the |
|
105
|
|
|
|
|
|
|
# text to this element, and returns a reference to the character data element |
|
106
|
|
|
|
|
|
|
# if successful. |
|
107
|
|
|
|
|
|
|
############################################################################### |
|
108
|
|
|
|
|
|
|
sub add_text |
|
109
|
|
|
|
|
|
|
{ |
|
110
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
111
|
0
|
|
|
|
|
|
my $text = shift; |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
|
|
|
return if (!defined $text); |
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $type = ref $self; # Do package name magic |
|
116
|
0
|
|
|
|
|
|
$type =~ s/::[^:]+?$/::Characters/o; |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
my $elem = new $type; |
|
119
|
0
|
|
|
|
|
|
$elem->{'Text'} = $text; |
|
120
|
0
|
|
|
|
|
|
$self->add_child( $elem ); |
|
121
|
0
|
|
|
|
|
|
return $elem; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
############################################################################### |
|
125
|
|
|
|
|
|
|
# Subroutine: as_text |
|
126
|
|
|
|
|
|
|
############################################################################### |
|
127
|
|
|
|
|
|
|
# Returns a string containing the entire XML document. |
|
128
|
|
|
|
|
|
|
############################################################################### |
|
129
|
|
|
|
|
|
|
sub as_text |
|
130
|
|
|
|
|
|
|
{ |
|
131
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
132
|
0
|
|
|
|
|
|
my $text; |
|
133
|
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
my $type = ref $self; |
|
135
|
0
|
|
|
|
|
|
$type =~ s/.*:://; |
|
136
|
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
$text = "\n<" . $type; |
|
138
|
0
|
|
|
|
|
|
foreach (sort keys %{$self}) |
|
|
0
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
{ |
|
140
|
0
|
0
|
|
|
|
|
if ($_ !~ /Text|Kids/) { |
|
141
|
0
|
0
|
|
|
|
|
if (defined $self->{$_} ) { |
|
142
|
0
|
|
|
|
|
|
$text .= " $_=\"" . $self->{$_} . '"'; } |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my $cont = $self->content(); |
|
147
|
0
|
0
|
|
|
|
|
if (defined $cont) |
|
148
|
0
|
|
|
|
|
|
{ $text .= '>' . $cont . '' . $type . '>'; } |
|
149
|
|
|
|
|
|
|
else |
|
150
|
0
|
|
|
|
|
|
{ $text .= ' />'; } |
|
151
|
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
$text =~ s/\n\n/\n/g; |
|
153
|
0
|
|
|
|
|
|
return $text; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
__END__ |