line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Async::Stream::Iterator; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
46
|
use 5.010; |
|
3
|
|
|
|
|
11
|
|
4
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
62
|
|
5
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
69
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
23
|
use Carp; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
652
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Iterator for Async stream |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Version 0.03 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Creating and managing item for Async::Stream |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use Async::Stream::Iterator; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $iterator = Async::Stream::Iterator->new($stream); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 new($stream) |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Constructor creates instance of class. |
35
|
|
|
|
|
|
|
Class method gets 1 arguments stream from which will be created iterator. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $iterator = Async::Stream::Iterator->new($stream); |
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
sub new { |
40
|
58
|
|
|
58
|
1
|
1148
|
my ($class, $stream) = @_; |
41
|
|
|
|
|
|
|
|
42
|
58
|
100
|
|
|
|
230
|
if (!$stream->isa('Async::Stream')) { |
43
|
1
|
|
|
|
|
233
|
croak "First argument can be only instance of Async::Stream or instance of derived class"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
57
|
|
|
|
|
175
|
my $item = $stream->head; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return bless sub { |
49
|
233
|
|
|
233
|
|
350
|
my $return_cb = shift; |
50
|
233
|
50
|
|
|
|
521
|
return $return_cb->() if (!defined $item); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$item->next(sub { |
53
|
233
|
100
|
|
|
|
492
|
if (defined $_[0]) { |
54
|
178
|
|
|
|
|
309
|
$item = shift; |
55
|
178
|
|
|
|
|
437
|
$return_cb->($item->val) |
56
|
|
|
|
|
|
|
} else { |
57
|
55
|
|
|
|
|
134
|
$return_cb->() |
58
|
|
|
|
|
|
|
} |
59
|
233
|
|
|
|
|
975
|
}); |
60
|
57
|
|
|
|
|
287
|
}, $class; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 next($returning_cb) |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Method gets returning callback and call that when iterator ready to return next value. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$iterator->(sub { |
68
|
|
|
|
|
|
|
my $item_value = shift; |
69
|
|
|
|
|
|
|
}); |
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub next { |
73
|
234
|
|
|
234
|
1
|
1065
|
my $self = shift; |
74
|
234
|
|
|
|
|
347
|
my $return_cb = shift; |
75
|
|
|
|
|
|
|
|
76
|
234
|
100
|
|
|
|
614
|
if (ref $return_cb ne 'CODE') { |
77
|
1
|
|
|
|
|
135
|
croak "First argument can be only subroutine reference" |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
233
|
|
|
|
|
695
|
$self->($return_cb); |
81
|
|
|
|
|
|
|
|
82
|
233
|
|
|
|
|
784
|
return; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 AUTHOR |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Kirill Sysoev, C<< >> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 BUGS |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Please report any bugs or feature requests to L. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SUPPORT |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
perldoc Async::Stream::Item |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Copyright 2017 Kirill Sysoev. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
105
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
106
|
|
|
|
|
|
|
copy of the full license at: |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
L |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; # End of Async::Stream::Item |