introduce ZConfig system, first cut at HTML::Zoom itself
[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
6 sub new { bless({}, $_[0]) }
7
8 sub with_zconfig { shift }
9
10 sub html_from_stream {
11   my ($class, $stream) = @_;
12   my $html;
13   while (my ($evt) = $stream->next) { $html .= $class->_event_to_html($evt) }
14   return $html;
15 }
16
17 sub html_from_events {
18   my ($class, $events) = @_;
19   join '', map $class->_event_to_html($_), @$events;
20 }
21
22 sub _event_to_html {
23   my ($self, $evt) = @_;
24   # big expression
25   if (defined $evt->{raw}) {
26     $evt->{raw}
27   } elsif ($evt->{type} eq 'OPEN') {
28     '<'
29     .$evt->{name}
30     .(defined $evt->{raw_attrs}
31         ? $evt->{raw_attrs}
32         : do {
33             my @names = @{$evt->{attr_names}};
34             @names
35               ? join(' ', '', map qq{${_}="${\$evt->{attrs}{$_}}"}, @names)
36               : ''
37           }
38      )
39     .($evt->{is_in_place_close} ? ' /' : '')
40     .'>'
41   } elsif ($evt->{type} eq 'CLOSE') {
42     '</'.$evt->{name}.'>'
43   } elsif ($evt->{type} eq 'EMPTY') {
44     ''
45   } else {
46     die "No raw value in event and no special handling for type ".$evt->{type};
47   }
48 }
49
50 1;