few extra utility routines
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / Producer / BuiltIn.pm
CommitLineData
456a815d 1package HTML::Zoom::Producer::BuiltIn;
2
3use strict;
4use warnings FATAL => 'all';
bf5a23d0 5use base qw(HTML::Zoom::SubObject);
d80786d0 6
456a815d 7sub html_from_stream {
bf5a23d0 8 my ($self, $stream) = @_;
9 return
10 join '',
11 map $self->event_to_html($_),
12 $self->_zconfig->stream_utils->stream_to_array($stream)
456a815d 13}
14
c86c0ce2 15sub html_from_events {
bf5a23d0 16 my ($self, $events) = @_;
17 join '', map $self->event_to_html($_), @$events;
c86c0ce2 18}
19
bf5a23d0 20sub event_to_html {
456a815d 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
481;