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 | |
13 | sub _event_to_html { |
14 | my ($self, $evt) = @_; |
15 | # big expression |
16 | if (defined $evt->{raw}) { |
17 | $evt->{raw} |
18 | } elsif ($evt->{type} eq 'OPEN') { |
19 | '<' |
20 | .$evt->{name} |
21 | .(defined $evt->{raw_attrs} |
22 | ? $evt->{raw_attrs} |
23 | : do { |
24 | my @names = @{$evt->{attr_names}}; |
25 | @names |
26 | ? join(' ', '', map qq{${_}="${\$evt->{attrs}{$_}}"}, @names) |
27 | : '' |
28 | } |
29 | ) |
30 | .($evt->{is_in_place_close} ? ' /' : '') |
31 | .'>' |
32 | } elsif ($evt->{type} eq 'CLOSE') { |
33 | '</'.$evt->{name}.'>' |
34 | } elsif ($evt->{type} eq 'EMPTY') { |
35 | '' |
36 | } else { |
37 | die "No raw value in event and no special handling for type ".$evt->{type}; |
38 | } |
39 | } |
40 | |
41 | 1; |