File Coverage

blib/lib/Ryu.pm
Criterion Covered Total %
statement 18 24 75.0
branch n/a
condition n/a
subroutine 7 9 77.7
pod 3 3 100.0
total 28 36 77.7


line stmt bran cond sub pod time code
1             package Ryu;
2             # ABSTRACT: stream and data flow handling for async code
3 37     37   5061730 use strict;
  37         69  
  37         1412  
4 37     37   2089 use warnings;
  37         71  
  37         2097  
5              
6             # Older versions cannot complete the test suite successfully
7 37     37   627 use 5.018;
  37         156  
8              
9             our $VERSION = '4.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. The other half of a
108             L is a L.
109              
110             =head2 Some notes that might not relate to anything
111              
112             With a single parameter, L and L will use the given
113             instance as a L or L respectively.
114              
115             Multiple parameters are a shortcut for instantiating the given source
116             or sink:
117              
118             my $stream = Ryu::Stream->from(
119             file => 'somefile.bin'
120             );
121              
122             is equivalent to
123              
124             my $stream = Ryu::Stream->from(
125             Ryu::Source->new(
126             file => 'somefile.bin'
127             )
128             );
129              
130             =head1 Why the name?
131              
132             =over 4
133              
134             =item * C< $ryu > lines up with typical 4-character indentation settings.
135              
136             =item * there's Rx for other languages, and this is based on the same ideas
137              
138             =item * 流 was too hard for me to type
139              
140             =back
141              
142             =cut
143              
144 37     37   208 use Exporter qw(import export_to_level);
  37         3948  
  37         9492  
145              
146 37     37   24776 use Ryu::Source;
  37         140  
  37         2197  
147 37     37   22412 use Ryu::Sink;
  37         112  
  37         14114  
148              
149             our $ryu = __PACKAGE__->new;
150              
151             our @EXPORT_OK = qw($ryu);
152              
153             our $FUTURE_FACTORY = sub {
154             Future->new->set_label($_[1])
155             };
156              
157             =head1 METHODS
158              
159             Note that you're more likely to find useful methods in the following classes:
160              
161             =over 4
162              
163             =item * L
164              
165             =item * L
166              
167             =item * L
168              
169             =back
170              
171             =cut
172              
173             =head2 new
174              
175             Instantiates a L object, allowing L, L and other methods.
176              
177             =cut
178              
179 38     38 1 327897 sub new { bless { @_[1..$#_] }, $_[0] }
180              
181             =head2 from
182              
183             Helper method which returns a L from a list of items.
184              
185             =cut
186              
187             sub from {
188 0     0 1   my $self = shift;
189 0           my $src = Ryu::Source->new;
190 0           $src->from(@_)
191             }
192              
193             =head2 just
194              
195             Helper method which returns a single-item L.
196              
197             =cut
198              
199             sub just {
200 0     0 1   my $self = shift;
201 0           my $src = Ryu::Source->new;
202 0           $src->from(shift);
203             }
204              
205             1;
206              
207             __END__