| 49 |
|
|
| 50 |
my $onerror = sub { |
my $onerror = sub { |
| 51 |
my (%opt) = @_; |
my (%opt) = @_; |
| 52 |
print STDOUT "$opt{line},$opt{column},$opt{type}\n"; |
print STDOUT "$opt{line},$opt{column},$opt{type};$opt{level};$opt{value}\n"; |
| 53 |
}; |
}; |
| 54 |
|
|
| 55 |
$doc = $dom->create_document; |
$doc = $dom->create_document; |
| 81 |
$time{serialize_xml} = $time2 - $time1; |
$time{serialize_xml} = $time2 - $time1; |
| 82 |
$doc->manakai_is_html (1); |
$doc->manakai_is_html (1); |
| 83 |
} else { # test |
} else { # test |
| 84 |
|
require Whatpm::HTML::Dumper; |
| 85 |
$time1 = time; |
$time1 = time; |
| 86 |
$out = test_serialize ($el || $doc); |
$out = \Whatpm::HTML::Dumper::dumptree ($el || $doc); |
| 87 |
|
$time2 = time; |
| 88 |
|
$time{serialize_test} = $time2 - $time1; |
| 89 |
|
} |
| 90 |
|
print STDOUT Encode::encode ('utf-8', $$out); |
| 91 |
|
print STDOUT "\n"; |
| 92 |
|
} elsif (@mode == 3 and $mode[0] eq 'xml1' and |
| 93 |
|
($mode[2] eq 'html' or $mode[2] eq 'test' or $mode[2] eq 'xml')) { |
| 94 |
|
print STDOUT "Content-Type: text/plain; charset=utf-8\n\n"; |
| 95 |
|
|
| 96 |
|
require Encode; |
| 97 |
|
require Whatpm::XML::Parser; |
| 98 |
|
|
| 99 |
|
$time1 = time; |
| 100 |
|
$s = Encode::decode ('utf-8', $s); |
| 101 |
|
$time2 = time; |
| 102 |
|
$time{decode} = $time2 - $time1; |
| 103 |
|
|
| 104 |
|
print STDOUT "#errors\n"; |
| 105 |
|
|
| 106 |
|
my $onerror = sub { |
| 107 |
|
my (%opt) = @_; |
| 108 |
|
print STDOUT "$opt{line},$opt{column},$opt{type};$opt{level};$opt{value}\n"; |
| 109 |
|
}; |
| 110 |
|
|
| 111 |
|
$doc = $dom->create_document; |
| 112 |
|
$time1 = time; |
| 113 |
|
## TODO: |
| 114 |
|
#if (length $mode[1]) { |
| 115 |
|
# $el = $doc->create_element_ns |
| 116 |
|
# ('http://www.w3.org/1999/xhtml', [undef, $mode[1]]); |
| 117 |
|
# #Whatpm::HTML->set_inner_html ($el, $s, $onerror); |
| 118 |
|
#} else { |
| 119 |
|
Whatpm::XML::Parser->parse_char_string ($s => $doc, $onerror); |
| 120 |
|
#} |
| 121 |
|
$time2 = time; |
| 122 |
|
$time{parse_xml1} = $time2 - $time1; |
| 123 |
|
|
| 124 |
|
print "#document\n"; |
| 125 |
|
|
| 126 |
|
my $out; |
| 127 |
|
if ($mode[2] eq 'html') { |
| 128 |
|
$doc->manakai_is_html (1); |
| 129 |
|
$time1 = time; |
| 130 |
|
$out = \( ($el or $doc)->inner_html ); |
| 131 |
|
$time2 = time; |
| 132 |
|
$time{serialize_html} = $time2 - $time1; |
| 133 |
|
$doc->manakai_is_html (0); |
| 134 |
|
} elsif ($mode[2] eq 'xml') { |
| 135 |
|
$time1 = time; |
| 136 |
|
$out = \( ($el or $doc)->inner_html ); |
| 137 |
|
$time2 = time; |
| 138 |
|
$time{serialize_xml} = $time2 - $time1; |
| 139 |
|
} else { # test |
| 140 |
|
require Whatpm::HTML::Dumper; |
| 141 |
|
$time1 = time; |
| 142 |
|
$out = \Whatpm::HTML::Dumper::dumptree ($el || $doc); |
| 143 |
$time2 = time; |
$time2 = time; |
| 144 |
$time{serialize_test} = $time2 - $time1; |
$time{serialize_test} = $time2 - $time1; |
| 145 |
} |
} |
| 183 |
$time2 = time; |
$time2 = time; |
| 184 |
$time{serialize_xml} = $time2 - $time1; |
$time{serialize_xml} = $time2 - $time1; |
| 185 |
} else { # test |
} else { # test |
| 186 |
|
require Whatpm::HTML::Dumper; |
| 187 |
$time1 = time; |
$time1 = time; |
| 188 |
$out = test_serialize ($doc); |
$out = \Whatpm::HTML::Dumper::dumptree ($el || $doc); |
| 189 |
|
$time2 = time; |
| 190 |
|
$time{serialize_test} = $time2 - $time1; |
| 191 |
|
} |
| 192 |
|
print STDOUT Encode::encode ('utf-8', $$out); |
| 193 |
|
print STDOUT "\n"; |
| 194 |
|
} elsif (@mode == 3 and $mode[0] eq 'swml' and $mode[1] eq '' and |
| 195 |
|
($mode[2] eq 'html' or $mode[2] eq 'test' or $mode[2] eq 'xml')) { |
| 196 |
|
print STDOUT "Content-Type: text/plain; charset=utf-8\n\n"; |
| 197 |
|
|
| 198 |
|
require Encode; |
| 199 |
|
$time1 = time; |
| 200 |
|
$s = Encode::decode ('utf-8', $s); |
| 201 |
|
$time2 = time; |
| 202 |
|
$time{decode} = $time2 - $time1; |
| 203 |
|
|
| 204 |
|
require Whatpm::SWML::Parser; |
| 205 |
|
$doc = $dom->create_document; |
| 206 |
|
my $p = Whatpm::SWML::Parser->new; |
| 207 |
|
$p->parse_char_string ($s => $doc); |
| 208 |
|
|
| 209 |
|
print "#document\n"; |
| 210 |
|
|
| 211 |
|
my $out; |
| 212 |
|
if ($mode[2] eq 'html') { |
| 213 |
|
$doc->manakai_is_html (0); |
| 214 |
|
$time1 = time; |
| 215 |
|
$out = \( $doc->inner_html ); |
| 216 |
|
$time2 = time; |
| 217 |
|
$time{serialize_html} = $time2 - $time1; |
| 218 |
|
$doc->manakai_is_html (1); |
| 219 |
|
} elsif ($mode[2] eq 'xml') { |
| 220 |
|
$time1 = time; |
| 221 |
|
$out = \( $doc->inner_html ); |
| 222 |
|
$time2 = time; |
| 223 |
|
$time{serialize_xml} = $time2 - $time1; |
| 224 |
|
} else { # test |
| 225 |
|
require Whatpm::HTML::Dumper; |
| 226 |
|
$time1 = time; |
| 227 |
|
$out = \Whatpm::HTML::Dumper::dumptree ($el || $doc); |
| 228 |
$time2 = time; |
$time2 = time; |
| 229 |
$time{serialize_test} = $time2 - $time1; |
$time{serialize_test} = $time2 - $time1; |
| 230 |
} |
} |
| 260 |
$time2 = time; |
$time2 = time; |
| 261 |
$time{serialize_xml} = $time2 - $time1; |
$time{serialize_xml} = $time2 - $time1; |
| 262 |
} else { # test |
} else { # test |
| 263 |
|
require Whatpm::HTML::Dumper; |
| 264 |
$time1 = time; |
$time1 = time; |
| 265 |
$out = test_serialize ($doc); |
$out = \Whatpm::HTML::Dumper::dumptree ($el || $doc); |
| 266 |
$time2 = time; |
$time2 = time; |
| 267 |
$time{serialize_test} = $time2 - $time1; |
$time{serialize_test} = $time2 - $time1; |
| 268 |
} |
} |
| 291 |
} |
} |
| 292 |
|
|
| 293 |
print STDOUT "#log\n"; |
print STDOUT "#log\n"; |
| 294 |
for (qw/decode parse parse_xml serialize_html serialize_xml serialize_test |
for (qw/decode parse parse_xml parse_xml1 |
| 295 |
|
serialize_html serialize_xml serialize_test |
| 296 |
check/) { |
check/) { |
| 297 |
next unless defined $time{$_}; |
next unless defined $time{$_}; |
| 298 |
print STDOUT { |
print STDOUT { |
| 299 |
decode => 'bytes->chars', |
decode => 'bytes->chars', |
| 300 |
parse => 'html5(chars)->dom5', |
parse => 'html5(chars)->dom5', |
| 301 |
parse_xml => 'xml1(chars)->dom5', |
parse_xml => 'xml(chars)->dom5', |
| 302 |
|
parse_xml1 => 'xml1(chars)->dom5', |
| 303 |
serialize_html => 'dom5->html5(char)', |
serialize_html => 'dom5->html5(char)', |
| 304 |
serialize_xml => 'dom5->xml1(char)', |
serialize_xml => 'dom5->xml1(char)', |
| 305 |
serialize_test => 'dom5->test(char)', |
serialize_test => 'dom5->test(char)', |
| 312 |
|
|
| 313 |
exit; |
exit; |
| 314 |
|
|
|
sub test_serialize ($) { |
|
|
my $node = shift; |
|
|
my $r = ''; |
|
|
|
|
|
my @node = map { [$_, ''] } @{$node->child_nodes}; |
|
|
while (@node) { |
|
|
my $child = shift @node; |
|
|
my $nt = $child->[0]->node_type; |
|
|
if ($nt == $child->[0]->ELEMENT_NODE) { |
|
|
$r .= '| ' . $child->[1] . '<' . $child->[0]->tag_name . ">\x0A"; ## ISSUE: case? |
|
|
|
|
|
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value] } |
|
|
@{$child->[0]->attributes}) { |
|
|
$r .= '| ' . $child->[1] . ' ' . $attr->[0] . '="'; ## ISSUE: case? |
|
|
$r .= $attr->[1] . '"' . "\x0A"; |
|
|
} |
|
|
|
|
|
unshift @node, |
|
|
map { [$_, $child->[1] . ' '] } @{$child->[0]->child_nodes}; |
|
|
} elsif ($nt == $child->[0]->TEXT_NODE) { |
|
|
$r .= '| ' . $child->[1] . '"' . $child->[0]->data . '"' . "\x0A"; |
|
|
} elsif ($nt == $child->[0]->CDATA_SECTION_NODE) { |
|
|
$r .= '| ' . $child->[1] . '<![CDATA[' . $child->[0]->data . "]]>\x0A"; |
|
|
} elsif ($nt == $child->[0]->COMMENT_NODE) { |
|
|
$r .= '| ' . $child->[1] . '<!-- ' . $child->[0]->data . " -->\x0A"; |
|
|
} elsif ($nt == $child->[0]->DOCUMENT_TYPE_NODE) { |
|
|
$r .= '| ' . $child->[1] . '<!DOCTYPE ' . $child->[0]->name . ">\x0A"; |
|
|
} elsif ($nt == $child->[0]->PROCESSING_INSTRUCTION_NODE) { |
|
|
$r .= '| ' . $child->[1] . '<?' . $child->[0]->target . ' ' . |
|
|
$child->[0]->data . "?>\x0A"; |
|
|
} else { |
|
|
$r .= '| ' . $child->[1] . $child->[0]->node_type . "\x0A"; # error |
|
|
} |
|
|
} |
|
|
|
|
|
return \$r; |
|
|
} # test_serialize |
|
|
|
|
| 315 |
sub get_node_path ($) { |
sub get_node_path ($) { |
| 316 |
my $node = shift; |
my $node = shift; |
| 317 |
my @r; |
my @r; |
| 344 |
|
|
| 345 |
=head1 LICENSE |
=head1 LICENSE |
| 346 |
|
|
| 347 |
Copyright 2007 Wakaba <w@suika.fam.cx> |
Copyright 2007-2008 Wakaba <w@suika.fam.cx> |
| 348 |
|
|
| 349 |
This library is free software; you can redistribute it |
This library is free software; you can redistribute it |
| 350 |
and/or modify it under the same terms as Perl itself. |
and/or modify it under the same terms as Perl itself. |