Storm.pm untested

filter: Statementstmt 0.0% 0 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod n/a totaltotal 0.0% 0 / 14 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 use v5.10;
2 use strict;
3 use warnings;
4  
5 package IO::Storm;
6 # ABSTRACT: IO::Storm allows you to write Bolts and Spouts for Storm in Perl.
7 $IO::Storm::VERSION = '0.16';
8 1;
9  
10 __END__
11  
12 =pod
13  
14 =head1 NAME
15  
16 IO::Storm - IO::Storm allows you to write Bolts and Spouts for Storm in Perl.
17  
18 =head1 VERSION
19  
20 version 0.16
21  
22 =head1 SYNOPSIS
23  
24 package SplitSentenceBolt;
25  
26 use Moo;
27 use namespace::clean;
28  
29 extends 'Storm::Bolt';
30  
31 sub process {
32 my ($self, $tuple) = @_;
33  
34 my @words = split(' ', $tuple->values->[0]);
35 foreach my $word (@words) {
36  
37 $self->emit([ $word ]);
38 }
39  
40 }
41  
42 SplitSentenceBolt->new->run;
43  
44 =head1 DESCRIPTION
45  
46 IO::Storm allows you to leverage Storm's multilang support to write Bolts and
47 Spouts in Perl. As of version 0.02, the API is designed to very closely mirror
48 that of the L<Streamparse Python library|http://streamparse.readthedocs.org/en/latest/api.html>. The exception being that we don't currently support
49 the C<BatchingBolt> class or the C<emit_many> methods.
50  
51 =encoding utf8
52  
53 =head1 Bolts
54  
55 To create a Bolt, you want to extend the C<Storm::Bolt> class.
56  
57 package SplitSentenceBolt;
58  
59 use Moo;
60 use namespace::clean;
61  
62 extends 'Storm::Bolt';
63  
64 =head2 Processing tuples
65  
66 To have your Bolt start processing tuples, you want to override the C<process>
67 method, which takes a C<IO::Storm::Tuple> as its only argument. This method
68 should do any processing you want to perform on the tuple and then C<emit> its
69 output.
70  
71 sub process {
72 my ($self, $tuple) = @_;
73  
74 my @words = split(' ', $tuple->values->[0]);
75 foreach my $word (@words) {
76  
77 $self->emit([ $word ]);
78 }
79  
80 }
81  
82 To actually start your Bolt, call the C<run> method, which will initialize the
83 bolt and start the event loop.
84  
85 SplitSentenceBolt->new->run;
86  
87 =head2 Automatic reliability
88  
89 By default, the Bolt will automatically handle acks, anchoring, and
90 failures. If you would like to customize the behavior of any of these things,
91 you will need to set the C<auto_anchor>, C<auto_anchor>, or C<auto_fail>
92 attributes to 0. For more information about Storm's guaranteed message
93 processing, please L<see their documentation|https://storm.incubator.apache.org/documentation/Guaranteeing-message-processing.html#what-is-storms-reliability-api>.
94  
95 =head1 Spouts
96  
97 To create a Spout, you want to extend the C<Storm::Spout> class.
98  
99 package SentenceSpout;
100  
101 use Moo;
102 use namespace::clean;
103  
104 extends 'Storm::Spout';
105  
106 =head2 Emitting tuples
107  
108 To actually emit anything on your Spout, you have to implement the
109 C<next_tuple> method.
110  
111 my $sentences = ["a little brown dog",
112 "the man petted the dog",
113 "four score and seven years ago",
114 "an apple a day keeps the doctor away",];
115 my $num_sentences = scalar(@$sentences);
116  
117 sub next_tuple {
118 my ($self) = @_;
119  
120 $self->emit( [ $sentences->[ rand($num_sentences) ] ] );
121  
122 }
123  
124 To actually start your Spout, call the C<run> method, which will initialize the
125 Spout and start the event loop.
126  
127 SentenceSpout->new->run;
128  
129 =head1 Methods supported by Spouts and Bolts
130  
131 =head2 Custom initialization
132  
133 If you need to have some custom action happen when your component is being
134 initialized, just override C<initialize> method, which receives the Storm
135 configuration for the component and information about its place in the topology
136 as its arguments.
137  
138 sub initialize {
139 my ( $self, $storm_conf, $context ) = @_;
140 }
141  
142 =head2 Logging
143  
144 Use the C<log> method to send messages back to the Storm ShellBolt parent
145 process which will be added to the general Storm log.
146  
147 sub process {
148 my ($self, $tuple) = @_;
149 ...
150 $self->log("Working on $tuple");
151 ...
152 }
153  
154 =head1 AUTHORS
155  
156 =over 4
157  
158 =item *
159  
160 Dan Blanchard <dblanchard@ets.org>
161  
162 =item *
163  
164 Cory G Watson <gphat@cpan.org>
165  
166 =back
167  
168 =head1 COPYRIGHT AND LICENSE
169  
170 This software is copyright (c) 2014 by Educational Testing Service.
171  
172 This is free software; you can redistribute it and/or modify it under
173 the same terms as the Perl 5 programming language system itself.
174  
175 =cut