13 |
|
|
14 |
## TODO: _charset_ |
## TODO: _charset_ |
15 |
|
|
16 |
my $mode = $http->meta_variable ('PATH_INFO'); |
my @mode = split m#/#, scalar $http->meta_variable ('PATH_INFO'), -1; |
17 |
|
shift @mode if @mode and $mode[0] == ''; |
18 |
## TODO: decode unreserved characters |
## TODO: decode unreserved characters |
19 |
|
|
20 |
my $s = $http->parameter ('s'); |
my $s = $http->parameter ('s'); |
28 |
my $time2; |
my $time2; |
29 |
|
|
30 |
require Message::DOM::DOMImplementation; |
require Message::DOM::DOMImplementation; |
31 |
my $dom = Message::DOM::DOMImplementation->____new; |
my $dom = Message::DOM::DOMImplementation->new; |
32 |
$| = 1; |
# $| = 1; |
33 |
my $doc; |
my $doc; |
34 |
|
my $el; |
35 |
|
|
36 |
if ($mode eq '/html/html' or $mode eq '/html/test') { |
if (@mode == 3 and $mode[0] eq 'html' and |
37 |
|
($mode[2] eq 'html' or $mode[2] eq 'test')) { |
38 |
print STDOUT "Content-Type: text/plain; charset=utf-8\n\n"; |
print STDOUT "Content-Type: text/plain; charset=utf-8\n\n"; |
39 |
|
|
40 |
require Encode; |
require Encode; |
53 |
print STDOUT "$opt{line},$opt{column},$opt{type}\n"; |
print STDOUT "$opt{line},$opt{column},$opt{type}\n"; |
54 |
}; |
}; |
55 |
|
|
56 |
|
$doc = $dom->create_document; |
57 |
|
$doc->manakai_is_html (1); |
58 |
$time1 = time; |
$time1 = time; |
59 |
$doc = Whatpm::HTML->parse_string ($s => $dom->create_document, $onerror); |
if (length $mode[1]) { |
60 |
|
$el = $doc->create_element_ns |
61 |
|
('http://www.w3.org/1999/xhtml', [undef, $mode[1]]); |
62 |
|
Whatpm::HTML->set_inner_html ($el, $s, $onerror); |
63 |
|
} else { |
64 |
|
Whatpm::HTML->parse_string ($s => $doc, $onerror); |
65 |
|
} |
66 |
$time2 = time; |
$time2 = time; |
67 |
$time{parse} = $time2 - $time1; |
$time{parse} = $time2 - $time1; |
68 |
|
|
69 |
print "#document\n"; |
print "#document\n"; |
70 |
|
|
71 |
my $out; |
my $out; |
72 |
$time1 = time; |
if ($mode[2] eq 'html') { |
73 |
if ($mode eq '/html/html') { |
$time1 = time; |
74 |
$out = Whatpm::HTML->get_inner_html ($doc); |
$out = \( ($el or $doc)->inner_html ); |
75 |
|
$time2 = time; |
76 |
|
$time{serialize_html} = $time2 - $time1; |
77 |
} else { # test |
} else { # test |
78 |
$out = test_serialize ($doc); |
$time1 = time; |
79 |
|
$out = test_serialize ($el || $doc); |
80 |
|
$time2 = time; |
81 |
|
$time{serialize_test} = $time2 - $time1; |
82 |
} |
} |
|
$time2 = time; |
|
|
$time{serialize} = $time2 - $time1; |
|
83 |
print STDOUT Encode::encode ('utf-8', $$out); |
print STDOUT Encode::encode ('utf-8', $$out); |
84 |
print STDOUT "\n"; |
print STDOUT "\n"; |
85 |
} elsif ($mode eq '/xhtml/html' or $mode eq '/xhtml/test') { |
} elsif (@mode == 3 and $mode[0] eq 'xhtml' and |
86 |
|
($mode[2] eq 'html' or $mode[2] eq 'test')) { |
87 |
print STDOUT "Content-Type: text/plain; charset=utf-8\n\n"; |
print STDOUT "Content-Type: text/plain; charset=utf-8\n\n"; |
88 |
|
|
89 |
require Message::DOM::XMLParserTemp; |
require Message::DOM::XMLParserTemp; |
92 |
my $onerror = sub { |
my $onerror = sub { |
93 |
my $err = shift; |
my $err = shift; |
94 |
print STDOUT $err->location->line_number, ","; |
print STDOUT $err->location->line_number, ","; |
95 |
print STDOUT $err->location->column_number, " "; |
print STDOUT $err->location->column_number, ","; |
96 |
print STDOUT $err->text, "\n"; |
print STDOUT $err->text, "\n"; |
97 |
return 1; |
return 1; |
98 |
}; |
}; |
107 |
print "#document\n"; |
print "#document\n"; |
108 |
|
|
109 |
my $out; |
my $out; |
110 |
if ($mode eq '/xhtml/html') { |
if ($mode[2] eq 'html') { |
111 |
## TODO: Use XHTML serializer |
$time1 = time; |
112 |
#$out = Whatpm::HTML->get_inner_html ($doc); |
$out = \( $doc->inner_html ); ## TODO: $el case |
113 |
|
$time2 = time; |
114 |
|
$time{serialize_xml} = $time2 - $time1; |
115 |
|
} else { # test |
116 |
|
$time1 = time; |
117 |
|
$out = test_serialize ($doc); |
118 |
|
$time2 = time; |
119 |
|
$time{serialize_test} = $time2 - $time1; |
120 |
|
} |
121 |
|
print STDOUT Encode::encode ('utf-8', $$out); |
122 |
|
print STDOUT "\n"; |
123 |
|
} elsif (@mode == 3 and $mode[0] eq 'h2h' and $mode[1] eq '' and |
124 |
|
($mode[2] eq 'html' or $mode[2] eq 'test')) { |
125 |
|
print STDOUT "Content-Type: text/plain; charset=utf-8\n\n"; |
126 |
|
|
127 |
|
require Encode; |
128 |
|
$time1 = time; |
129 |
|
$s = Encode::decode ('utf-8', $s); |
130 |
|
$time2 = time; |
131 |
|
$time{decode} = $time2 - $time1; |
132 |
|
|
133 |
|
require Whatpm::H2H; |
134 |
|
$doc = $dom->create_document; |
135 |
|
Whatpm::H2H->parse_string ($s => $doc); |
136 |
|
|
137 |
|
print "#document\n"; |
138 |
|
|
139 |
|
my $out; |
140 |
|
if ($mode[2] eq 'html') { |
141 |
|
$time1 = time; |
142 |
|
$out = \( $doc->inner_html ); |
143 |
|
$time2 = time; |
144 |
|
$time{serialize_xml} = $time2 - $time1; |
145 |
} else { # test |
} else { # test |
146 |
$time1 = time; |
$time1 = time; |
147 |
$out = test_serialize ($doc); |
$out = test_serialize ($doc); |
157 |
|
|
158 |
if ($http->parameter ('dom5')) { |
if ($http->parameter ('dom5')) { |
159 |
require Whatpm::ContentChecker; |
require Whatpm::ContentChecker; |
160 |
print STDOUT "#domerrors\n"; |
my $onerror = sub { |
|
$time1 = time; |
|
|
Whatpm::ContentChecker->check_document ($doc, sub { |
|
161 |
my %opt = @_; |
my %opt = @_; |
162 |
print STDOUT get_node_path ($opt{node}) . ';' . $opt{type} . "\n"; |
print STDOUT get_node_path ($opt{node}) . ';' . $opt{type} . "\n"; |
163 |
}); |
}; |
164 |
|
print STDOUT "#domerrors\n"; |
165 |
|
$time1 = time; |
166 |
|
if ($el) { |
167 |
|
Whatpm::ContentChecker->check_element ($el, $onerror); |
168 |
|
} else { |
169 |
|
Whatpm::ContentChecker->check_document ($doc, $onerror); |
170 |
|
} |
171 |
$time2 = time; |
$time2 = time; |
172 |
$time{check} = $time2 - $time1; |
$time{check} = $time2 - $time1; |
173 |
} |
} |
180 |
decode => 'bytes->chars', |
decode => 'bytes->chars', |
181 |
parse => 'html5(chars)->dom5', |
parse => 'html5(chars)->dom5', |
182 |
parse_xml => 'xml1(chars)->dom5', |
parse_xml => 'xml1(chars)->dom5', |
183 |
serialize_html => 'dom5->html5', |
serialize_html => 'dom5->html5(char)', |
184 |
serialize_xml => 'dom5->xml', |
serialize_xml => 'dom5->xml1(char)', |
185 |
serialize_test => 'dom5->test', |
serialize_test => 'dom5->test(char)', |
186 |
check => 'dom5 check', |
check => 'dom5 check', |
187 |
}->{$_}; |
}->{$_}; |
188 |
print STDOUT "\t", $time{$_}, "s\n"; |
print STDOUT "\t", $time{$_}, "s\n"; |