line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::Code; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
12229
|
use vars qw ($VERSION); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1120
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
$VERSION = '0.4'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new{ |
8
|
0
|
|
|
0
|
1
|
|
my $who = shift; |
9
|
0
|
|
0
|
|
|
|
my $class = ref ($who) || $who; |
10
|
0
|
|
|
|
|
|
my $this = { |
11
|
|
|
|
|
|
|
'' => shift, |
12
|
|
|
|
|
|
|
'' => [], |
13
|
|
|
|
|
|
|
'' => 1}; |
14
|
0
|
|
|
|
|
|
return bless $this, $class; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub version{ |
18
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
19
|
0
|
|
|
|
|
|
$this->{''} = shift; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub doctype{ |
23
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
24
|
0
|
|
|
|
|
|
$this->{''} = shift; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub encoding{ |
28
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
29
|
0
|
|
|
|
|
|
$this->{''} = shift; |
30
|
0
|
0
|
|
|
|
|
$this->{''} = '1.0' unless $this->{''}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub stylesheet{ |
34
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
35
|
0
|
|
|
|
|
|
$this->{''} = shift; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub comment{ |
39
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
40
|
0
|
|
|
|
|
|
my $comment = { |
41
|
|
|
|
|
|
|
'' => '!', |
42
|
|
|
|
|
|
|
'' => shift}; |
43
|
0
|
|
|
|
|
|
bless $comment; |
44
|
0
|
|
|
|
|
|
$this->add_child ($comment); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub pi{ |
48
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
49
|
0
|
|
|
|
|
|
my $pi = { |
50
|
|
|
|
|
|
|
'' => '?', |
51
|
|
|
|
|
|
|
'' => shift}; |
52
|
0
|
|
|
|
|
|
bless $pi; |
53
|
0
|
|
|
|
|
|
$this->add_child ($pi); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub name{ |
57
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
58
|
0
|
|
|
|
|
|
return $this->{''}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub escape{ |
62
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
63
|
0
|
|
|
|
|
|
my $escape = shift; |
64
|
0
|
|
|
|
|
|
$this->{''} = $escape; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub add_child{ |
68
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
69
|
0
|
|
|
|
|
|
my $children = shift; |
70
|
0
|
|
|
|
|
|
push @{$this->{''}}, $children; |
|
0
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub add_textnode{ |
74
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
75
|
0
|
|
|
|
|
|
my $text = shift; |
76
|
0
|
|
|
|
|
|
my $textnode = new XML::Code ('='); |
77
|
0
|
|
|
|
|
|
$textnode->escape ($this->{''}); |
78
|
0
|
|
|
|
|
|
$textnode->set_text ($text); |
79
|
0
|
|
|
|
|
|
push @{$this->{''}}, $textnode; |
|
0
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub add_empty{ |
83
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
84
|
0
|
|
|
|
|
|
my $name = shift; |
85
|
0
|
|
|
|
|
|
my $emptynode = new XML::Code ($name); |
86
|
0
|
|
|
|
|
|
push @{$this->{''}}, $emptynode; |
|
0
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub set_text{ |
90
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
91
|
0
|
|
|
|
|
|
my $text = shift; |
92
|
0
|
|
|
|
|
|
$this->{''} = $text; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub text{ |
96
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
97
|
0
|
|
|
|
|
|
return $this->{'text'}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub code{ |
101
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
102
|
0
|
|
0
|
|
|
|
my $tab_level = shift || 0; |
103
|
0
|
|
0
|
|
|
|
my $suppress_tab = shift || 0; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
$suppress_tab = 1 if $tab_level == -1; |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
my $tab = "\t" x ($tab_level) unless $suppress_tab; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
my $name = $this->{''}; |
110
|
0
|
|
0
|
|
|
|
my $text = $this->{''} || ''; |
111
|
0
|
|
|
|
|
|
my $escape = $this->{''}; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
my $code = ''; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $prolog; |
116
|
0
|
0
|
|
|
|
|
$prolog = " version=\"$this->{''}\"" if $this->{''}; |
117
|
0
|
0
|
|
|
|
|
$prolog .= " encoding=\"$this->{''}\"" if $this->{''}; |
118
|
0
|
0
|
|
|
|
|
$code = "\n" if $prolog; |
119
|
0
|
0
|
|
|
|
|
$code .= "{''}>\n" if $this->{''}; |
120
|
0
|
0
|
|
|
|
|
$code .= "{''}\"?>\n" |
121
|
|
|
|
|
|
|
if $this->{''}; |
122
|
|
|
|
|
|
|
|
123
|
0
|
0
|
|
|
|
|
$text = escape_text ($text) if $escape; |
124
|
|
|
|
|
|
|
|
125
|
0
|
0
|
|
|
|
|
if ($name eq '!'){ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
$code .= "$tab\n"; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
elsif ($name eq '?'){ |
130
|
0
|
|
|
|
|
|
$code .= "$tab$text?>\n"; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
elsif ($name eq '='){ |
134
|
0
|
|
|
|
|
|
$code .= $text; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
else{ |
138
|
0
|
|
|
|
|
|
my $children = $this->{''}; |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
$code .= "$tab<$name"; |
141
|
0
|
|
|
|
|
|
foreach my $attribute (sort keys %$this){ |
142
|
0
|
|
|
|
|
|
my $value = $this->{$attribute}; |
143
|
0
|
0
|
|
|
|
|
$value = escape_text ($value) if $escape; |
144
|
0
|
0
|
|
|
|
|
$code .= " $attribute=\"$value\"" unless $attribute =~ m{^<}; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
0
|
0
|
|
|
|
|
if (scalar @$children){ |
148
|
0
|
0
|
|
|
|
|
$code .= $text ? ">$text" : ">\n"; |
149
|
0
|
|
|
|
|
|
for (my $count = 0; $count != scalar @$children; $count++){ |
150
|
0
|
0
|
0
|
|
|
|
$code .= $$children[$count]->code ($tab_level != -1 ? $tab_level + 1 : -1, |
|
|
0
|
|
|
|
|
|
151
|
|
|
|
|
|
|
$count == 0 && length ($text) ? 1 : 0); |
152
|
|
|
|
|
|
|
} |
153
|
0
|
|
|
|
|
|
$code .= "$tab$name>\n"; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
else{ |
156
|
0
|
0
|
|
|
|
|
$code .= $text ? ">$text$name>\n" : "/>\n"; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
return $code; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub escape_text{ |
164
|
0
|
|
|
0
|
0
|
|
my $text = shift; |
165
|
0
|
|
|
|
|
|
$text =~ s{\&}{\&}gm; |
166
|
0
|
|
|
|
|
|
$text =~ s{<}{\<}gm; |
167
|
0
|
|
|
|
|
|
$text =~ s{>}{\>}gm; |
168
|
0
|
|
|
|
|
|
return $text; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
return 1; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
__END__ |