blib/lib/XML/Excel.pm

filter: Statementstmt 76.2% 135 / 177 Branchbran 55.3% 52 / 94 Conditioncond 52.3% 22 / 42 MC/DCmcdc 24.0% 6 / 25 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 5 totaltotal 63.5% 225 / 354 CC 69 SCAR 29.5
CC
69
Cov
67%
__ANON__
30.0
print_xml
25.6
declare_doctype
21.5
CRAP 19.2
↑ Summary
1 package XML::Excel;
2
3 1 ▶use Spreadsheet::ParseExcel;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 #use strict;
7 1 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 1 require 5.004;
10 1 require Exporter;
11 #require DynaLoader;
12 1 require AutoLoader;
13
14 1 @ISA = qw(Exporter);# DynaLoader);
15
16 1 @EXPORT = qw(
17
18 );
19 1 $VERSION = '0.01';
20
21 #bootstrap XML::Excel $VERSION;
22
23 1 my $ParseExcel_obj; #Declared for global usage
24 my $_error; #Error container
25
26
27 sub new($;$)
28 4 ▶{
Subroutine new: called CC=3 SCAR=11.3
Pod undocumented
29
30 4 my $class = shift;
31 4 ▶ my $attr = shift || {};
Condition100%2/2
shift() || {}
l!l
13
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
32
33 4 my $self = { 'error_out' => 0,
34 'column_headings' => 0,
35 'column_data' => 0,
36 'ParseExcel' => 0,
37 %$attr
38 };
39
40 4 bless $self, $class;
41
42 4 ▶ if ($attr->{ParseExcel}) ### if custom Spreadsheet::ParseExcel object is provided use it
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{'ParseExcel'}) { } 0 4 4
43 {
44 0 $ParseExcel_obj = $attr->{ParseExcel};
45 0 $attr->{ParseExcel} = undef;
46 } else { ### else create our own Spreadsheet::ParseExcel object with it's defaults
47 4 $ParseExcel_obj = Spreadsheet::ParseExcel->new();
48 }
49
50 4 return $self;
51
52 }
53
54 sub parse_doc
55 3 ▶{
Subroutine parse_doc: called CC=19 SCAR=30.4
Pod undocumented
56 3 my $class = shift;
57 3 ▶ my $file_name = shift || croak "Usage: parse_doc(file_name, [\%attr])";
Condition50%1/2
shift() || croak('Usage: parse_doc(file_name, [%attr])')
l!l
30
MC/DC0%0/1
shift() || croak('Usage: parse_doc(file_name, [%attr])')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
58 3 my $attr = shift; # %attr (headings, sub_char)
59
60 3 ▶ my $workbook = $ParseExcel_obj->Parse($file_name) or die "Error: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
my $workbook = $ParseExcel_obj->Parse($file_name) or die "Error: $!\n" 3 0 3
61 3 my $worksheet = $workbook->{Worksheet}[0];
62
63 3 ▶ $_error = "Problems parsing the file: $file_name " unless defined($workbook);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $workbook 0 3 3
64
65 3 ▶ croak "$_error" if ($class->{'error_out'} == 1 && $@);
Branch: 1 branch
BranchTrueFalseTotal
if $class->{"error_out"} == 1 and $@ 0 3 3
Condition33%1/3
$class->{"error_out"} == 1 and $@
!ll&&!rl&&r
300
MC/DC0%0/2
$class->{"error_out"} == 1 and $@
$class->{"error_out"} == 1 $@
Truth table33%1/3
A and B
A= $class->{"error_out"} == 1B= $@
ABresult
0X0
100
111
66
67 3 my @col_headings;
68
69 3 ▶ $attr->{headings} = 0 unless (exists($attr->{headings})); ### default headings to 0
Branch: 1 branch
BranchTrueFalseTotal
unless exists $attr->{"headings"} 1 2 3
70
71 3 ▶ if ($attr->{headings} == 0) ### No headings to be used from file
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{"headings"} == 0) 1 2 3
72 {
73 1 ▶ if ($class->{column_headings})
Branch: 1 branch
BranchTrueFalseTotal
if ($class->{"column_headings"}) 1 0 1
74 {
75 1 @col_headings = @{$class->{column_headings}}; ### if column_heading are provided
76 } ### by user, use them
77
78 }
79 #my $line; ### declare $line outside of scope to be use later
80
81 3 ▶ if ($attr->{headings} != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{"headings"} != 0) 2 1 3
82 {
83 2 ▶ my $cols_returned = $get_header->($worksheet, \@col_headings, defined($attr->{sub_char})? $attr->{sub_char}:undef );
Branch: 1 branch
BranchTrueFalseTotal
defined $attr->{'sub_char'} ? : 1 1 2
84 2 ▶ $_error = "There were no columns returned for headers, please check your excel file" if (!$cols_returned);
Branch: 1 branch
BranchTrueFalseTotal
unless $cols_returned 0 2 2
85 2 ▶ croak "$_error" if ($class->{'error_out'} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $class->{"error_out"} == 1 0 2 2
86
87 2 ▶ return 0 if (!$cols_returned);
Branch: 1 branch
BranchTrueFalseTotal
unless $cols_returned 0 2 2
88 }
89
90 3 my @arr_cols_data; ### declare @arr_cols_data to be used for stacking data
91
92
93 #######
94
95 3 my ($cell, $row_count, $cell_count);
96
97 3 ▶ for($row_count = $attr->{headings}; defined $worksheet->{MaxRow} && $row_count <= $worksheet->{MaxRow}; $row_count++)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $worksheet->{"MaxRow"} and $row_count <= $worksheet->{"MaxRow"}) 25 3 28
Condition66%2/3
defined $worksheet->{"MaxRow"} and $row_count <= $worksheet->{"MaxRow"}
!ll&&!rl&&r
0325
MC/DC50%1/2
defined $worksheet->{"MaxRow"} and $row_count <= $worksheet->{"MaxRow"}
defined $worksheet->{"MaxRow"} $row_count <= $worksheet->{"MaxRow"}
Truth table66%2/3
A and B
A= defined $worksheet->{"MaxRow"}B= $row_count <= $worksheet->{"MaxRow"}
ABresult
0X0
100
111
98 {
99 25 my @cols_data;
100 25 ▶ for(my $cell_count = $worksheet->{MinCol}; defined $worksheet->{MaxCol} && $cell_count <= $worksheet->{MaxCol} ; $cell_count++)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $worksheet->{"MaxCol"} and $cell_count <= $worksheet->{"MaxCol"}) 275 25 300
Condition66%2/3
defined $worksheet->{"MaxCol"} and $cell_count <= $worksheet->{"MaxCol"}
!ll&&!rl&&r
025275
MC/DC50%1/2
defined $worksheet->{"MaxCol"} and $cell_count <= $worksheet->{"MaxCol"}
defined $worksheet->{"MaxCol"} $cell_count <= $worksheet->{"MaxCol"}
Truth table66%2/3
A and B
A= defined $worksheet->{"MaxCol"}B= $cell_count <= $worksheet->{"MaxCol"}
ABresult
0X0
100
111
101 {
102 275 $cell = $worksheet->{Cells}[$row_count][$cell_count];
103 275 ▶ defined($cell) ? push(@cols_data, $cell->Value) : push(@cols_data, undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $cell ? : 257 18 275
104 }
105 25 $escape_char->(\@cols_data);
106 25 push(@arr_cols_data, \@cols_data);
107 }
108
109 3 $class->{'column_headings'} = \@col_headings; ### assign reference of @col_headings (xml headers) to object
110 3 $class->{'column_data'} = \@arr_cols_data; ### assign reference of @arr_cols_data (xml data) to object
111
112 3 return 1;
113 }
114
115 sub print_xml
116 4 ▶{
Subroutine print_xml: called CC=18 SCAR=32.4
Pod undocumented
117 4 my $class = shift;
118 4 ▶ my $file_out = shift || 0;
Condition50%1/2
shift() || 0
l!l
40
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
119 4 ▶ my $args = shift || {}; # %attr (file_tag, parent_tag, format)
Condition100%2/2
shift() || {}
l!l
13
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
120
121 4 ▶ $args->{file_tag} = "records" unless $args->{file_tag}; #default {parent_tag} to record if not supplied
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"file_tag"} 3 1 4
122 4 ▶ $args->{parent_tag} = "record" unless $args->{parent_tag};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"parent_tag"} 4 0 4
123 4 ▶ $args->{format} = "\t" unless $args->{format}; #default {format} to tab if not supplied
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"format"} 3 1 4
124
125 4 $class->{'document_element'} = $args->{file_tag}; ### Used later for declare_doctype() method
126
127 4 ▶ if ($class->{'column_data'} == 0 || ($class->{'column_headings'} == 0 && $class->{'headings'}))
Branch: 1 branch
BranchTrueFalseTotal
if ($class->{"column_data"} == 0 or $class->{"column_headings"} == 0 and $class->{"headings"}) 0 4 4
Condition33%2/6
$class->{"column_data"} == 0 or $class->{"column_headings"} == 0 and $class->{"headings"}
l!l&&r!l&&!r
004
$class->{"column_headings"} == 0 and $class->{"headings"}
!ll&&!rl&&r
400
MC/DC0%0/3
$class->{"column_data"} == 0 or $class->{"column_headings"} == 0 and $class->{"headings"}
$class->{"column_data"} == 0 $class->{"column_headings"} == 0 $class->{"headings"}
Truth table25%1/4
A or B and C
A= $class->{"column_data"} == 0B= $class->{"column_headings"} == 0C= $class->{"headings"}
ABCresult
1XX1
0111
00X0
0100
128 {
129 0 croak "There is no data to print, make sure that you parsed the document before printing";
130 }
131
132 ###Open file $file_out for output or output to STDOUT
133 4 ▶ if ($file_out)
Branch: 1 branch
BranchTrueFalseTotal
if ($file_out) { } 4 0 4
134 {
135 4 open FILE_OUT, ">$file_out";
136 } else {
137 0 *FILE_OUT = *STDOUT;
138 }
139
140 4 ▶ print FILE_OUT $class->{'declare_xml'}."\n" if $class->{'declare_xml'};
Branch: 1 branch
BranchTrueFalseTotal
if $class->{"declare_xml"} 1 3 4
141 ###This will replace the non-interpolated $class->{'document_element'} inside the $class->{'declare_doctype'} to get the real value
142 ###Should be replace with something more practical in the future...
143 4 ▶ $class->{'declare_doctype'} =~ s/\$class\-\>\{\'document_element\'\}/$class->{'document_element'}/ if $class->{'declare_doctype'};
Branch: 1 branch
BranchTrueFalseTotal
if $class->{"declare_doctype"} 1 3 4
144
145 4 ▶ print FILE_OUT $class->{'declare_doctype'}."\n" if $class->{'declare_doctype'};
Branch: 1 branch
BranchTrueFalseTotal
if $class->{"declare_doctype"} 1 3 4
146 4 print FILE_OUT "<$args->{file_tag}>", "\n"; ### print initial document tag
147
148 ### declare the $tag for <$tag> and $loop_num for headers and data index tracking
149 4 my $tag;
150 my $loop_num;
151
152 4 ▶ if ($#{$class->{'column_headings'}} > 0) ### if column headings are provided
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$$class{'column_headings'};} > 0) { } 4 0 4
153 {
154
155 4 foreach $loop_num (0..$#{$class->{'column_data'}})
156 {
157 25 print FILE_OUT $args->{format}, "<$args->{parent_tag}>", "\n";
158 25 foreach $tag (0..$#{$class->{'column_headings'}})
159 {
160 275 print FILE_OUT $args->{format}, $args->{format}, "<$class->{'column_headings'}[$tag]>$class->{'column_data'}[$loop_num][$tag]</$class->{'column_headings'}[$tag]>\n";
161 }
162 25 print FILE_OUT $args->{format}, "</$args->{parent_tag}>", "\n";
163 }
164
165 } else { ### if column headings are not provided we default to <tr$loop_num>
166
167 0 foreach $loop_num (0..$#{$class->{'column_data'}})
168 {
169 0 print FILE_OUT $args->{format}, "<$args->{parent_tag}>", "\n";
170 0 foreach $tag (0..$#{$class->{'column_data'}->[$loop_num]})
171 {
172 0 print FILE_OUT $args->{format}, $args->{format}, "<tr$loop_num>$class->{'column_data'}[$loop_num][$tag]</tr$loop_num>\n";
173 }
174 0 print FILE_OUT $args->{format}, "</$args->{parent_tag}>", "\n";
175 }
176 }
177
178 4 print FILE_OUT "</$args->{file_tag}>", "\n"; ### print the final document tag
179
180 4 close FILE_OUT;
181
182 }
183
184 sub declare_xml
185 1 ▶{
Subroutine declare_xml: called CC=9 SCAR=30.6
Pod undocumented
186
187 1 my $class = shift;
188 1 ▶ my $attr = shift || {};
Condition50%1/2
shift() || {}
l!l
10
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
189
190 ### Attributes: version, encoding, standalone
191
192 1 ▶ if (exists $attr->{'version'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr->{'version'}) { } 1 0 1
193 {
194 1 $class->{'declare_xml'} = "<?xml version=\"$attr->{'version'}\""
195 }
196 else
197 {
198 0 $csvxml_error = "The version attribute must be specified for declare_xml()\n
199 Usage: declare_xml\({version=>1.0, [encoding=>..., standalone=>yes/no]}\)";
200 0 ▶ croak "$csvxml_error" if ($class->{'error_out'} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $class->{"error_out"} == 1 0 0 0
201 }
202
203 1 ▶ $class->{'declare_xml'} .= " encoding=\"$attr->{'encoding'}\"" if exists $attr->{'encoding'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr->{"encoding"} 1 0 1
204 1 ▶ if (exists $attr->{'standalone'} && ($attr->{'standalone'} =~ /[yes|no]/))
Branch: 2 branches
BranchTrueFalseTotal
if (exists $attr->{'standalone'} and $attr->{'standalone'} =~ /[yes|no]/) { } 1 0 1
elsif (not $attr->{'standalone'} =~ /[yes|no]/) { } 0 0 0
Condition33%1/3
exists $attr->{"standalone"} and $attr->{"standalone"} =~ /[yes|no]/
!ll&&!rl&&r
001
MC/DC0%0/2
exists $attr->{"standalone"} and $attr->{"standalone"} =~ /[yes|no]/
exists $attr->{"standalone"} $attr->{"standalone"} =~ /[yes|no]/
Truth table33%1/3
A and B
A= exists $attr->{"standalone"}B= $attr->{"standalone"} =~ /[yes|no]/
ABresult
0X0
100
111
205 {
206 1 $class->{'declare_xml'} .= " standalone=\"$attr->{'standalone'}\"";
207 }
208 elsif (!($attr->{'standalone'} =~ /[yes|no]/))
209 {
210 0 $csvxml_error = "The standalone attribute must be yes|no for declare_xml()\n
211 Usage: declare_xml\({version=>1.0, [encoding=>..., standalone=>yes/no]}\)";
212 0 ▶ croak "$csvxml_error" if ($class->{'error_out'} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $class->{"error_out"} == 1 0 0 0
213 }
214
215 1 $class->{'declare_xml'} .= "?>";
216
217 1 return $class->{'declare_xml'};
218
219 }
220
221 sub declare_doctype
222 1 ▶{
Subroutine declare_doctype: called CC=10 SCAR=30.7
Pod undocumented
223
224 1 my $class = shift;
225 1 ▶ my $attr = shift || {};
Condition50%1/2
shift() || {}
l!l
10
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
226
227 ### Attributes: source, location1, location2, subset
228
229 1 $class->{'declare_doctype'} = '<!DOCTYPE $class->{\'document_element\'}';
230 1 ▶ if ($attr->{source} eq "SYSTEM" || $attr->{source} eq "PUBLIC")
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{'source'} eq 'SYSTEM' or $attr->{'source'} eq 'PUBLIC') { } 1 0 1
Condition33%1/3
$attr->{"source"} eq "SYSTEM" or $attr->{"source"} eq "PUBLIC"
l!l&&r!l&&!r
010
MC/DC0%0/2
$attr->{"source"} eq "SYSTEM" or $attr->{"source"} eq "PUBLIC"
$attr->{"source"} eq "SYSTEM" $attr->{"source"} eq "PUBLIC"
Truth table33%1/3
A or B
A= $attr->{"source"} eq "SYSTEM"B= $attr->{"source"} eq "PUBLIC"
ABresult
1X1
011
000
231 {
232 1 $class->{'declare_doctype'} .= " $attr->{'source'}";
233 }
234 else
235 {
236 0 $csvxml_error = "The source attribute is not set correctly";
237 0 ▶ croak "$csvxml_error" if ($class->{'error_out'} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $class->{"error_out"} == 1 0 0 0
238 }
239
240 1 ▶ if (exists $attr->{location1} && !(exists $attr->{subset}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr->{'location1'} and not exists $attr->{'subset'}) { } 1 0 1
Condition33%1/3
exists $attr->{"location1"} and not exists $attr->{"subset"}
!ll&&!rl&&r
001
MC/DC0%0/2
exists $attr->{"location1"} and not exists $attr->{"subset"}
exists $attr->{"location1"} not exists $attr->{"subset"}
Truth table33%1/3
A and not(B)
A= exists $attr->{"location1"}B= not exists $attr->{"subset"}
ABresult
0X0
100
111
241 {
242 1 $class->{'declare_doctype'} .= " \"$attr->{'location1'}\"";
243 }
244 else
245 {
246 0 $csvxml_error = "$attr->{'source'} location1 must be specified";
247 0 ▶ croak "$csvxml_error" if ($class->{'error_out'} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $class->{"error_out"} == 1 0 0 0
248 }
249
250 1 ▶ $class->{'declare_doctype'} .= " \"$attr->{'location2'}\"" if exists $attr->{'location2'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr->{"location2"} 1 0 1
251 1 ▶ $class->{'declare_doctype'} .= " [$attr->{'subset'}]" if exists $attr->{'subset'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr->{"subset"} 0 1 1
252
253
254 1 $class->{'declare_doctype'} .= ">";
255
256 1 return $class->{'declare_doctype'};
257
258 }
259
260 $get_header = sub()
261 2 ▶{
Subroutine __ANON__: called CC=8 SCAR=21.1
262 2 my $worksheet = shift;
263 2 my $ref_col = shift;
264 2 my $sub_char = shift;
265
266 2 my ($cell, $row_count, $cell_count);
267
268 2 ▶ for(my $row_count = 0; defined $worksheet->{MaxRow} && $row_count < 1; $row_count++)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $worksheet->{"MaxRow"} and $row_count < 1) 2 2 4
Condition66%2/3
defined $worksheet->{"MaxRow"} and $row_count < 1
!ll&&!rl&&r
022
MC/DC50%1/2
defined $worksheet->{"MaxRow"} and $row_count < 1
defined $worksheet->{"MaxRow"} $row_count < 1
Truth table66%2/3
A and B
A= defined $worksheet->{"MaxRow"}B= $row_count < 1
ABresult
0X0
100
111
269 {
270 2 ▶ for(my $cell_count = $worksheet->{MinCol}; defined $worksheet->{MaxCol} && $cell_count <= $worksheet->{MaxCol} ; $cell_count++)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $worksheet->{"MaxCol"} and $cell_count <= $worksheet->{"MaxCol"}) 22 2 24
Condition66%2/3
defined $worksheet->{"MaxCol"} and $cell_count <= $worksheet->{"MaxCol"}
!ll&&!rl&&r
0222
MC/DC50%1/2
defined $worksheet->{"MaxCol"} and $cell_count <= $worksheet->{"MaxCol"}
defined $worksheet->{"MaxCol"} $cell_count <= $worksheet->{"MaxCol"}
Truth table66%2/3
A and B
A= defined $worksheet->{"MaxCol"}B= $cell_count <= $worksheet->{"MaxCol"}
ABresult
0X0
100
111
271 {
272 22 $cell = $worksheet->{Cells}[$row_count][$cell_count];
273 22 ▶ defined($cell) ? push(@$ref_col, $cell->Value) : push(@$ref_col, undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $cell ? : 22 0 22
274 }
275 }
276
277
278 2 ▶ if (defined($sub_char))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sub_char) 1 1 2
279 {
280 1 map {s/^([^a-zA-Z|_|:]|((x|X)(m|M)(l|L)))/$sub_char/g;} @$ref_col; #convert all beginning \n or \t or \s to '_'
281 1 map {s/[^a-zA-Z|^-|^.|^0-9|^:]/$sub_char/g;} @$ref_col;
282 }
283
284 #print __LINE__.": $ref_col->[0]\n";
285
286 0 ▶ if ($ref_col) {return $#$ref_col;}else{return 0;}
Branch: 1 branch
BranchTrueFalseTotal
if ($ref_col) { } 2 0 2
287 1 };
288
289 $escape_char = sub() ### Escape char per XML 1.0 specifications
290 25 ▶{ ### Needs to be optimized for faster processing
Subroutine __ANON__: called CC=4 SCAR=17.9
291
292 25 my $arg = shift;
293 25 ▶ if (ref($arg) eq 'ARRAY')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 25 0 25
elsif (ref $arg eq 'SCALAR') { } 0 0 0
294 {
295 25 my $arr_index;
296 25 foreach $arr_index (0..$#{$arg})
297 {
298 275 @{$arg}[$arr_index] =~ s/\&/\&amp\;/g;
299 275 @{$arg}[$arr_index] =~ s/\</\&lt\;/g;
300 275 @{$arg}[$arr_index] =~ s/\>/\&gt\;/g;
301 275 @{$arg}[$arr_index] =~ s/\'/\&apos\;/g;
302 275 @{$arg}[$arr_index] =~ s/\"/\&quot\;/g;
303 0 @{$arg}[$arr_index] =~ s/([\x80-\xFF])/$XmlUtf8Encode->(ord($1))/ge;
304 }
305 }
306 elsif (ref($arg) eq 'SCALAR')
307 {
308 0 ${$arg} =~ s/\&/\&amp\;/g;
309 0 ${$arg} =~ s/\</\&lt\;/g;
310 0 ${$arg} =~ s/\>/\&gt\;/g;
311 0 ${$arg} =~ s/\'/\&apos\;/g;
312 0 ${$arg} =~ s/\"/\&quot\;/g;
313 0 ${$arg} =~ s/([\x80-\xFF])/$XmlUtf8Encode->(ord($1))/ge;
314 }
315 else
316 {
317 0 croak "Usage: $escape_char->(\@cols_data) or $escape_char->(\$foo)\n";
318 }
319
320 1 };
321
322 0 ▶$XmlUtf8Encode = sub() {
Subroutine __ANON__: not called CC=5 SCAR=34.0
323
324 0 my $n = shift;
325 0 ▶ if ($n < 0x80) {
Branch: 4 branches
BranchTrueFalseTotal
if ($n < 128) { } 0 0 0
elsif ($n < 2048) { } 0 0 0
elsif ($n < 65536) { } 0 0 0
elsif ($n < 1114112) { } 0 0 0
326 0 return chr ($n);
327 } elsif ($n < 0x800) {
328 0 return pack ("CC", (($n >> 6) | 0xc0), (($n & 0x3f) | 0x80));
329 } elsif ($n < 0x10000) {
330 0 return pack ("CCC", (($n >> 12) | 0xe0), ((($n >> 6) & 0x3f) | 0x80),
331 (($n & 0x3f) | 0x80));
332 } elsif ($n < 0x110000) {
333 0 return pack ("CCCC", (($n >> 18) | 0xf0), ((($n >> 12) & 0x3f) | 0x80),
334 ((($n >> 6) & 0x3f) | 0x80), (($n & 0x3f) | 0x80));
335 }
336 0 return $n;
337 1 };
338
339
340 # Preloaded methods go here.
341
342 # Autoload methods go after =cut, and are processed by the autosplit program.
343
344 1 1;
345 __END__
↑ Summary