9fb2ad9812091ffbd524c463a6616da10a3a1900
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / ReadFH.pm
1 package HTML::Zoom::ReadFH;
2
3 use strict;
4 use warnings FATAL => 'all';
5
6 sub from_zoom {
7   my ($class, $zoom) = @_;
8   bless({ _zoom => $zoom }, $class)
9 }
10
11 sub to_zoom {
12   my $self = shift;
13   # A small defense against accidental footshots. I hope.
14   # If this turns out to merely re-aim the gun at your left nipple, please
15   # come complain with a documented use case and we'll discuss deleting it.
16   die "Already started reading - there ain't no going back now"
17     if $self->{_stream};
18   $self->{_zoom}
19 }
20
21 sub getline {
22   my $self = shift;
23   my $html;
24   my $stream = $self->{_stream} ||= $self->{_zoom}->to_stream;
25   my $producer = $self->{_producer} ||= $self->{_zoom}->zconfig->producer;
26   while (my ($evt) = $stream->next) {
27     $html .= $producer->event_to_html($evt);
28     last if $evt->{flush};
29   }
30   return $html
31 }
32
33 sub close { "The door shuts behind you with a ominous boom" }
34
35 1;