line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ryu; |
2
|
|
|
|
|
|
|
# ABSTRACT: stream and data flow handling for async code |
3
|
34
|
|
|
34
|
|
2453352
|
use strict; |
|
34
|
|
|
|
|
337
|
|
|
34
|
|
|
|
|
873
|
|
4
|
34
|
|
|
34
|
|
145
|
use warnings; |
|
34
|
|
|
|
|
47
|
|
|
34
|
|
|
|
|
840
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# Older versions cannot complete the test suite successfully |
7
|
34
|
|
|
34
|
|
537
|
use 5.018; |
|
34
|
|
|
|
|
90
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '3.001'; |
10
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=encoding utf8 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Ryu - asynchronous stream building blocks |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#!/usr/bin/env perl |
21
|
|
|
|
|
|
|
use strict; |
22
|
|
|
|
|
|
|
use warnings; |
23
|
|
|
|
|
|
|
use Ryu qw($ryu); |
24
|
|
|
|
|
|
|
my ($lines) = |
25
|
|
|
|
|
|
|
$ryu->from(\*STDIN) |
26
|
|
|
|
|
|
|
->by_line |
27
|
|
|
|
|
|
|
->filter(qr/\h/) |
28
|
|
|
|
|
|
|
->count |
29
|
|
|
|
|
|
|
->get; |
30
|
|
|
|
|
|
|
print "Had $lines line(s) containing whitespace\n"; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Provides data flow processing for asynchronous coding purposes. It's a bit like L in |
35
|
|
|
|
|
|
|
concept. Where possible, it tries to provide a similar API. It is not a directly-compatible implementation, however. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
For more information, start with L. That's where most of the |
38
|
|
|
|
|
|
|
useful parts are. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 Why would I be using this? |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Eventually some documentation pages might appear, but at the moment they're unlikely to exist. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=over 4 |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item * Network protocol implementations - if you're bored of stringing together C, C, C |
47
|
|
|
|
|
|
|
and C, try L or L. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item * Extract, Transform, Load workflows (ETL) - need to pull data from somewhere, mangle it into shape, push it to |
50
|
|
|
|
|
|
|
a database? that'd be L |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item * Reactive event handling - L |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=back |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
As an expert software developer with a keen eye for useful code, you may already be bored of this documentation |
57
|
|
|
|
|
|
|
and on the verge of reaching for alternatives. The L section may speed you on your way. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 Compatibility |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Since L follows the ReactiveX conventions quite closely, we'd expect to have |
62
|
|
|
|
|
|
|
the ability to connect L observables to a L, and provide an |
63
|
|
|
|
|
|
|
adapter from a L to act as an L-style observable. This is not yet |
64
|
|
|
|
|
|
|
implemented, but may be added in a future version. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Most of the other modules in L are either not used widely enough or not a good |
67
|
|
|
|
|
|
|
semantic fit for a compatibility layer - but if you're interested in this, |
68
|
|
|
|
|
|
|
L or provide patches! |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 Components |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head3 Sources |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
A source emits items. See L. If in doubt, this is likely to be the class |
75
|
|
|
|
|
|
|
that you wanted. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Items can be any scalar value - some examples: |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=over 4 |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item * a single byte |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item * a character |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item * a byte string |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item * a character string |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item * an object instance |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item * an arrayref or hashref |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=back |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head3 Sinks |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
A sink receives items. It's the counterpart to a source. See L. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head3 Streams |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
A stream is a thing with a source. See L, which is likely to be something that does not yet |
102
|
|
|
|
|
|
|
have much documentation - in practice, the L implementation covers most use-cases. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 So what does this module do? |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Nothing. It's just a top-level loader for pulling in all the other components. |
107
|
|
|
|
|
|
|
You wanted L instead, or possibly L. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 Some notes that might not relate to anything |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
With a single parameter, L and L will use the given |
112
|
|
|
|
|
|
|
instance as a L or L respectively. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Multiple parameters are a shortcut for instantiating the given source |
115
|
|
|
|
|
|
|
or sink: |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my $stream = Ryu::Stream->from( |
118
|
|
|
|
|
|
|
file => 'somefile.bin' |
119
|
|
|
|
|
|
|
); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
is equivalent to |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $stream = Ryu::Stream->from( |
124
|
|
|
|
|
|
|
Ryu::Source->new( |
125
|
|
|
|
|
|
|
file => 'somefile.bin' |
126
|
|
|
|
|
|
|
) |
127
|
|
|
|
|
|
|
); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 Why the name? |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=over 4 |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item * C< $ryu > lines up with typical 4-character indentation settings. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item * there's Rx for other languages, and this is based on the same ideas |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item * 流 was too hard for me to type |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=back |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
34
|
|
|
34
|
|
201
|
use Exporter qw(import export_to_level); |
|
34
|
|
|
|
|
50
|
|
|
34
|
|
|
|
|
1096
|
|
144
|
|
|
|
|
|
|
|
145
|
34
|
|
|
34
|
|
17177
|
use Ryu::Source; |
|
34
|
|
|
|
|
97
|
|
|
34
|
|
|
|
|
6427
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
our $ryu = __PACKAGE__->new; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
our @EXPORT_OK = qw($ryu); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
our $FUTURE_FACTORY = sub { |
152
|
|
|
|
|
|
|
Future->new->set_label($_[1]) |
153
|
|
|
|
|
|
|
}; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 METHODS |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Note that you're more likely to find useful methods in the following classes: |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=over 4 |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item * L |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item * L |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item * L |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=back |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 new |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Instantiates a L object, allowing L, L and other methods. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|
177
|
35
|
|
|
35
|
1
|
5672
|
sub new { bless { @_[1..$#_] }, $_[0] } |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 from |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Helper method which returns a L from a list of items. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub from { |
186
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
187
|
0
|
|
|
|
|
|
my $src = Ryu::Source->new; |
188
|
0
|
|
|
|
|
|
$src->from(@_) |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 just |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Helper method which returns a single-item L. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=cut |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub just { |
198
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
199
|
0
|
|
|
|
|
|
my $src = Ryu::Source->new; |
200
|
0
|
|
|
|
|
|
$src->from(shift); |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
1; |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
__END__ |