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