few extra utility routines
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / ReadFH.pm
CommitLineData
bf5a23d0 1package HTML::Zoom::ReadFH;
2
3use strict;
4use warnings FATAL => 'all';
5
6sub from_zoom {
7 my ($class, $zoom) = @_;
8 bless({ _zoom => $zoom }, $class)
9}
10
11sub 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
21sub 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
33sub close { "The door shuts behind you with a ominous boom" }
34
351;