1 package HTML::Zoom::Parser::BuiltIn;
4 use base qw(HTML::Zoom::SubObject);
7 my ($self, $text) = @_;
9 _hacky_tag_parser($text => sub { push @events, $_[0] });
14 my ($self, $text) = @_;
15 return $self->_zconfig->stream_utils
16 ->stream_from_array(@{$self->html_to_events($text)});
21 # Well, ok. Be afraid. A little. But this is lexing HTML with a regexp,
22 # not really parsing (since the structure nesting isn't handled here) so
23 # it's relatively not dangerous.
25 # Certainly it's not really any more or any less heinous than anything else
26 # I could do in a handful of lines of pure perl.
28 sub _hacky_tag_parser {
29 my ($text, $handler) = @_;
34 ( / )? ( [^/!<>\s"'=]+ )
35 ( (?:"[^"]*"|'[^']*'|[^/"'<>])+? )?
37 (!-- .*? -- | ![^\-] .*? )
43 my ($whole, $is_close, $tag_name, $attributes, $is_special,
44 $in_place_close, $content)
45 = ($1, $2, $3, $4, $5, $6, $7, $8);
47 $handler->({ type => 'SPECIAL', raw => $whole });
49 $tag_name =~ tr/A-Z/a-z/;
51 $handler->({ type => 'CLOSE', name => $tag_name, raw => $whole });
53 $attributes = '' if !defined($attributes) or $attributes =~ /^ +$/;
57 is_in_place_close => $in_place_close,
58 _hacky_attribute_parser($attributes),
59 raw_attrs => $attributes||'',
62 if ($in_place_close) {
64 type => 'CLOSE', name => $tag_name, raw => '',
65 is_in_place_close => 1
70 if (length $content) {
71 $handler->({ type => 'TEXT', raw => $content });
76 sub _hacky_attribute_parser {
78 my (%attrs, @attr_names);
81 ([^\s\=\"\']+)(\s*=\s*(?:(")(.*?)"|(')(.*?)'|([^'"\s=]+)['"]*))?
86 my $val = ( $3 ? $4 : ( $5 ? $6 : $7 ));
89 $attrs{$lckey} = _simple_unescape($val);
91 $attrs{$lckey} = $lckey;
93 push(@attr_names, $lckey);
95 (attrs => \%attrs, attr_names => \@attr_names);
98 sub _simple_unescape {
100 $str =~ s/"/"/g;
110 $str =~ s/"/"/g;
116 sub html_escape { _simple_escape($_[1]) }
118 sub html_unescape { _simple_unescape($_[1]) }