2 use warnings FATAL => 'all';
6 eval "use HTML::Zoom; 1" ?
8 plan skip_all => "HTML::Zoom is not installed";
15 sub show_landing_html {
17 title => "Welcome to the Demo Home",
19 new_user_link => 'create_user.html',
23 sub show_landing_events {
24 as_events(\&landing, (
25 title => "Welcome to the Demo Home",
27 new_user_link => 'create_user.html',
33 \'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
36 <!-- here is a comment -->,
37 <title>, ($data{title} || 'Hello World'), </title>,
47 <p>, "Hi, I'm version: ", $data{site_version}, </p>,
48 <p>, "Here's some interesting things about me", </p>,
49 <img src="smilyface.png" alt="smiles" />,
51 <li>, <a href="/user">, "My Users", </li>,
52 <li>, <a href="/user/$data{new_user_link}">, "Create", "New User", </li>,
56 sub process_templates {
57 my ($templates, %data) = @_;
58 for my $template(@$templates) {
59 my @processed = $template->(%data);
60 $data{content} = \@processed;
62 return @{$data{content}};
66 my ($template, %data) = @_;
67 my @content = process_templates([$template, \&layout], %data);
68 return join '', HTML::Tags::to_html_string(@content);
72 my ($template, %data) = @_;
73 my @content = process_templates([$template, \&layout], %data);
74 return [_convert_to_events(@content)];
77 sub _convert_to_events {
79 my $raw = ref $_ ? $$_ : $_;
83 ( / )? ( [^/!<>\s"'=]+ )
84 ( (?:"[^"]*"|'[^']*'|[^"'<>])+? )?
86 (!-- .*? -- | ![^\-] .*? )
92 my ($whole, $is_close, $tag_name, $attrs, $comment_or_directive,
93 $in_place_close) = @info;
95 if($comment_or_directive) {
96 +{ type => 'SPECIAL', raw => $raw };
97 } elsif(!scalar(@info)) {
98 +{ type => 'TEXT', raw => $raw };
101 $tag_name =~ tr/A-Z/a-z/;
102 +{ type => 'CLOSE', name => $tag_name, raw => $raw};
104 $attrs = '' if !defined($attrs) or $attrs =~ /^ +$/;
108 is_in_place_close => $in_place_close,
109 HTML::Zoom::Parser::BuiltIn::_hacky_attribute_parser($attrs),
110 raw_attrs => $attrs||'',
117 is_in_place_close => 1,
126 ok my $html = BasicPage->show_landing_html;
127 ok my $zoom = HTML::Zoom->from_html($html);
128 ok my $events = BasicPage->show_landing_events;
130 use Data::Dump 'dump';
132 warn dump $zoom->to_events;