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