4 use warnings FATAL => 'all';
7 use HTML::Zoom::EventFilter;
8 use HTML::Zoom::SelectorParser;
9 use HTML::Zoom::ActionBuilder;
10 use HTML::Zoom::Parser::BuiltIn;
14 my $class = ref($proto) || $proto;
19 my ($self, %clone) = @_;
20 bless({ %$self, %clone }, ref($self));
25 $new->{source_html} = shift;
32 $new->{source_html} = do { local $/; <$fh> || die "from_fh: $!" };
39 while (my @spec = splice(@_, 0, 2)) {
42 HTML::Zoom::EventFilter->build_selector_pair(@spec)
46 _selector_handler => HTML::Zoom::EventFilter->selector_handler($pairs)
51 my ($self, $out) = @_;
53 _emitter => HTML::Zoom::EventFilter->standard_emitter($out)
59 my $s_h = $self->{_selector_handler};
60 $s_h->set_next($self->{_emitter});
61 HTML::Zoom::Parser::BuiltIn::_hacky_tag_parser(
62 $self->{source_html}, sub { $s_h->call(@_) }
69 HTML::Zoom - Lightweight CSS selector based HTML templating
78 <title>Hello people</title>
81 <h1 id="greeting">Placeholder</h1>
84 <p>Name: <span class="name">Bob</span></p>
85 <p>Age: <span class="age">23</span></p>
87 <hr class="between" />
93 HTML::Zoom->from_string($html)
95 'title, #greeting' => 'Hello world & dog!',
103 { '.name' => 'Epitaph',
104 '.age' => '<redacted>'
106 'span:odd p' => { -add_class => 'alt' },
109 ->stream_to(\*STDOUT)
116 <title>Hello world & dog!</title>
119 <h1 id="greeting">Hello world & dog!</h1>
122 <p>Name: <span class="name">Matt</span></p>
123 <p>Age: <span class="age">26</span></p>
125 <hr class="between" />
127 <p class="alt">Name: <span class="name">Mark</span></p>
128 <p class="alt">Age: <span class="age">0x29</span></p>
130 <hr class="between" />
132 <p>Name: <span class="name">Epitaph</span></p>
133 <p>Age: <span class="age"><redacted></span></p>
143 <title>default title</title>
146 <img src="/logo.jpg" />
152 http://docs.jquery.com/Selectors