add stub synopsis.t to fail if you forgot to extract the real one
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / Producer / BuiltIn.pm
CommitLineData
456a815d 1package HTML::Zoom::Producer::BuiltIn;
2
3use strict;
4use warnings FATAL => 'all';
5
d80786d0 6sub new { bless({}, $_[0]) }
7
8sub with_zconfig { shift }
9
456a815d 10sub html_from_stream {
11 my ($class, $stream) = @_;
12 my $html;
13 while (my ($evt) = $stream->next) { $html .= $class->_event_to_html($evt) }
14 return $html;
15}
16
c86c0ce2 17sub html_from_events {
18 my ($class, $events) = @_;
19 join '', map $class->_event_to_html($_), @$events;
20}
21
456a815d 22sub _event_to_html {
23 my ($self, $evt) = @_;
24 # big expression
25 if (defined $evt->{raw}) {
26 $evt->{raw}
27 } elsif ($evt->{type} eq 'OPEN') {
28 '<'
29 .$evt->{name}
30 .(defined $evt->{raw_attrs}
31 ? $evt->{raw_attrs}
32 : do {
33 my @names = @{$evt->{attr_names}};
34 @names
35 ? join(' ', '', map qq{${_}="${\$evt->{attrs}{$_}}"}, @names)
36 : ''
37 }
38 )
39 .($evt->{is_in_place_close} ? ' /' : '')
40 .'>'
41 } elsif ($evt->{type} eq 'CLOSE') {
42 '</'.$evt->{name}.'>'
43 } elsif ($evt->{type} eq 'EMPTY') {
44 ''
45 } else {
46 die "No raw value in event and no special handling for type ".$evt->{type};
47 }
48}
49
501;