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'); |
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 |
$time1 = time; |
$time1 = time; |
58 |
$doc = Whatpm::HTML->parse_string ($s => $dom->create_document, $onerror); |
if (length $mode[1]) { |
59 |
|
$el = $doc->create_element_ns |
60 |
|
('http://www.w3.org/1999/xhtml', [undef, $mode[1]]); |
61 |
|
Whatpm::HTML->set_inner_html ($el, $s, $onerror); |
62 |
|
} else { |
63 |
|
Whatpm::HTML->parse_string ($s => $doc, $onerror); |
64 |
|
} |
65 |
$time2 = time; |
$time2 = time; |
66 |
$time{parse} = $time2 - $time1; |
$time{parse} = $time2 - $time1; |
67 |
|
|
68 |
print "#document\n"; |
print "#document\n"; |
69 |
|
|
70 |
my $out; |
my $out; |
71 |
$time1 = time; |
if ($mode[2] eq 'html') { |
72 |
if ($mode eq '/html/html') { |
$time1 = time; |
73 |
$out = Whatpm::HTML->get_inner_html ($doc); |
$out = Whatpm::HTML->get_inner_html ($el || $doc); |
74 |
|
$time2 = time; |
75 |
|
$time{serialize_html} = $time2 - $time1; |
76 |
} else { # test |
} else { # test |
77 |
$out = test_serialize ($doc); |
$time1 = time; |
78 |
|
$out = test_serialize ($el || $doc); |
79 |
|
$time2 = time; |
80 |
|
$time{serialize_test} = $time2 - $time1; |
81 |
} |
} |
|
$time2 = time; |
|
|
$time{serialize} = $time2 - $time1; |
|
82 |
print STDOUT Encode::encode ('utf-8', $$out); |
print STDOUT Encode::encode ('utf-8', $$out); |
83 |
print STDOUT "\n"; |
print STDOUT "\n"; |
84 |
} elsif ($mode eq '/xhtml/html' or $mode eq '/xhtml/test') { |
} elsif (@mode == 3 and $mode[0] eq 'xhtml' and |
85 |
|
($mode[2] eq 'html' or $mode[2] eq 'test')) { |
86 |
print STDOUT "Content-Type: text/plain; charset=utf-8\n\n"; |
print STDOUT "Content-Type: text/plain; charset=utf-8\n\n"; |
87 |
|
|
88 |
require Message::DOM::XMLParserTemp; |
require Message::DOM::XMLParserTemp; |
91 |
my $onerror = sub { |
my $onerror = sub { |
92 |
my $err = shift; |
my $err = shift; |
93 |
print STDOUT $err->location->line_number, ","; |
print STDOUT $err->location->line_number, ","; |
94 |
print STDOUT $err->location->column_number, " "; |
print STDOUT $err->location->column_number, ","; |
95 |
print STDOUT $err->text, "\n"; |
print STDOUT $err->text, "\n"; |
96 |
return 1; |
return 1; |
97 |
}; |
}; |
106 |
print "#document\n"; |
print "#document\n"; |
107 |
|
|
108 |
my $out; |
my $out; |
109 |
if ($mode eq '/xhtml/html') { |
if ($mode[2] eq 'html') { |
110 |
## TODO: Use XHTML serializer |
## TODO: Use XHTML serializer |
111 |
#$out = Whatpm::HTML->get_inner_html ($doc); |
#$out = Whatpm::HTML->get_inner_html ($doc); |
112 |
} else { # test |
} else { # test |
124 |
|
|
125 |
if ($http->parameter ('dom5')) { |
if ($http->parameter ('dom5')) { |
126 |
require Whatpm::ContentChecker; |
require Whatpm::ContentChecker; |
127 |
print STDOUT "#domerrors\n"; |
my $onerror = sub { |
|
$time1 = time; |
|
|
Whatpm::ContentChecker->check_document ($doc, sub { |
|
128 |
my %opt = @_; |
my %opt = @_; |
129 |
print STDOUT get_node_path ($opt{node}) . ';' . $opt{type} . "\n"; |
print STDOUT get_node_path ($opt{node}) . ';' . $opt{type} . "\n"; |
130 |
}); |
}; |
131 |
|
print STDOUT "#domerrors\n"; |
132 |
|
$time1 = time; |
133 |
|
if ($el) { |
134 |
|
Whatpm::ContentChecker->check_element ($el, $onerror); |
135 |
|
} else { |
136 |
|
Whatpm::ContentChecker->check_document ($doc, $onerror); |
137 |
|
} |
138 |
$time2 = time; |
$time2 = time; |
139 |
$time{check} = $time2 - $time1; |
$time{check} = $time2 - $time1; |
140 |
} |
} |
147 |
decode => 'bytes->chars', |
decode => 'bytes->chars', |
148 |
parse => 'html5(chars)->dom5', |
parse => 'html5(chars)->dom5', |
149 |
parse_xml => 'xml1(chars)->dom5', |
parse_xml => 'xml1(chars)->dom5', |
150 |
serialize_html => 'dom5->html5', |
serialize_html => 'dom5->html5(char)', |
151 |
serialize_xml => 'dom5->xml', |
serialize_xml => 'dom5->xml1(char)', |
152 |
serialize_test => 'dom5->test', |
serialize_test => 'dom5->test(char)', |
153 |
check => 'dom5 check', |
check => 'dom5 check', |
154 |
}->{$_}; |
}->{$_}; |
155 |
print STDOUT "\t", $time{$_}, "s\n"; |
print STDOUT "\t", $time{$_}, "s\n"; |