clean up error
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / Producer / BuiltIn.pm
1 package HTML::Zoom::Producer::BuiltIn;
2
3 use strictures 1;
4 use base qw(HTML::Zoom::SubObject);
5
6 sub html_from_stream {
7   my ($self, $stream) = @_;
8   return
9     join '',
10       map $self->event_to_html($_),
11         $self->_zconfig->stream_utils->stream_to_array($stream)
12 }
13
14 sub html_from_events {
15   my ($self, $events) = @_;
16   join '', map $self->event_to_html($_), @$events;
17 }
18
19 sub event_to_html {
20   my ($self, $evt) = @_;
21   # big expression
22   if (defined $evt->{raw}) {
23     $evt->{raw}
24   } elsif ($evt->{type} eq 'OPEN') {
25     '<'
26     .$evt->{name}
27     .(defined $evt->{raw_attrs}
28         ? $evt->{raw_attrs}
29         : do {
30             my @names = @{$evt->{attr_names}};
31             @names
32               ? join(' ', '', map qq{${_}="${\$evt->{attrs}{$_}}"}, @names)
33               : ''
34           }
35      )
36     .($evt->{is_in_place_close} ? ' /' : '')
37     .'>'
38   } elsif ($evt->{type} eq 'CLOSE') {
39     '</'.$evt->{name}.'>'
40   } elsif ($evt->{type} eq 'EMPTY') {
41     ''
42   } else {
43     die "No raw value in event and no special handling for type ".$evt->{type};
44   }
45 }
46
47 1;