Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / Data / Stream / Bulk / Cat.pm
CommitLineData
3fea05b9 1#!/usr/bin/perl
2
3package Data::Stream::Bulk::Cat;
4use Moose;
5
6use namespace::clean -except => 'meta';
7
8with qw(Data::Stream::Bulk) => { excludes => 'list_cat' };
9
10has streams => (
11 isa => "ArrayRef[Data::Stream::Bulk]",
12 is => "ro",
13 required => 1,
14);
15
16sub is_done {
17 my $self = shift;
18 @{ $self->streams } == 0;
19}
20
21sub next {
22 my $self = shift;
23
24 my $s = $self->streams;
25
26 return unless @$s;
27
28 my $next;
29
30 until ( $next = @$s && $s->[0]->next ) {
31 shift @$s;
32 return unless @$s;
33 }
34
35 return $next;
36}
37
38sub list_cat {
39 my ( $self, @rest ) = @_;
40 my ( $head, @tail ) = ( @{ $self->streams }, @rest );
41 return () unless $head;
42 return $head->list_cat(@tail);
43}
44
45__PACKAGE__->meta->make_immutable;
46
47__PACKAGE__
48
49__END__
50
51=pod
52
53=head1 NAME
54
55Data::Stream::Bulk::Cat - Concatenated streams
56
57=head1 SYNOPSIS
58
59 use Data::Stream::Bulk::Cat;
60
61 Data::Stream::Bulk::Cat->new(
62 streams => [ $s1, $s2, $s3 ],
63 );
64
65=head1 DESCRIPTION
66
67This stream is a concatenation of several other streams.
68
69=head1 METHODS
70
71=over 4
72
73=item is_done
74
75Returns true if the list of streams is empty.
76
77=item next
78
79Returns the next block from the next ready stream.
80
81=item list_cat
82
83Breaks down the internal list of streams, and delegates C<list_cat> to the
84first one.
85
86Has the effect of inlining the nested streams into the total concatenation,
87allowing L<Data::Stream::Bulk::Array/list_cat> to work better.
88
89=back
90
91=cut
92
93