factor some code-based stream types out into classes
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / CodeStream.pm
CommitLineData
456a815d 1package HTML::Zoom::CodeStream;
2
3use strict;
4use warnings FATAL => 'all';
5f74b883 5use base qw(HTML::Zoom::StreamBase);
456a815d 6
7sub from_array {
8 my ($class, @array) = @_;
9 $class->new({ code => sub {
10 return unless @array;
11 return shift @array;
12 }});
13}
14
15sub new {
16 my ($class, $args) = @_;
d80786d0 17 bless({ _code => $args->{code}, _zconfig => $args->{zconfig} }, $class);
456a815d 18}
19
20sub next {
8f962884 21 my ($self) = @_;
22
23 # peeked entry so return that
24
25 if (exists $self->{_peeked}) {
26 return (delete $self->{_peeked});
27 }
28
29 $self->{_code}->();
456a815d 30}
31
321;
33