Commit | Line | Data |
456a815d |
1 | package HTML::Zoom::Producer::BuiltIn; |
2 | |
1cf03540 |
3 | use strictures 1; |
bf5a23d0 |
4 | use base qw(HTML::Zoom::SubObject); |
d80786d0 |
5 | |
456a815d |
6 | sub html_from_stream { |
bf5a23d0 |
7 | my ($self, $stream) = @_; |
8 | return |
9 | join '', |
10 | map $self->event_to_html($_), |
11 | $self->_zconfig->stream_utils->stream_to_array($stream) |
456a815d |
12 | } |
13 | |
c86c0ce2 |
14 | sub html_from_events { |
bf5a23d0 |
15 | my ($self, $events) = @_; |
16 | join '', map $self->event_to_html($_), @$events; |
c86c0ce2 |
17 | } |
18 | |
bf5a23d0 |
19 | sub event_to_html { |
456a815d |
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; |