Storm/Spout.pm

filter: Statementstmt 51.1% 23 / 45 Branchbran 12.5% 2 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 54.5% 6 / 11 Podpod 100% 6 / 6 totaltotal 47.4% 37 / 78 CC 9 SCAR 23.0
CC
9
Cov
41%
run
20.0
emit
16.0
initialize
2.0
CRAP 9.9
« Storm/Component.pm ↑ Summary Storm/Bolt.pm »
1 # ABSTRACT: The base class for all IO::Storm Spout.
2  
3 package IO::Storm::Spout;
4 1 $IO::Storm::Spout::VERSION = '0.16';
5 # Imports
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 extends 'IO::Storm::Component';
14  
15  
16 sub initialize {
17 0 ▶ my ( $self, $storm_conf, $context ) = @_;
Subroutine initialize: not called CC=1 SCAR=6.9
Pod documented
18 }
19  
20  
21 sub ack {
22 0 ▶ my ( $self, $id ) = @_;
Subroutine ack: not called CC=1 SCAR=6.9
Pod documented
23 }
24  
25  
26 sub fail {
27 0 ▶ my ( $self, $id ) = @_;
Subroutine fail: not called CC=1 SCAR=6.9
Pod documented
28 }
29  
30  
31 sub next_tuple {
32 0 ▶ my ($self) = @_;
Subroutine next_tuple: not called CC=1 SCAR=6.9
Pod documented
33 }
34  
35  
36 sub emit ($$;$) {
37 1 ▶ my ( $self, $tuple, $args ) = @_;
Subroutine emit: called CC=6 SCAR=27.7
Pod documented
38  
39 1 my $msg = { command => 'emit', tuple => $tuple };
40  
41 1 ▶ if ( defined($args) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args) 0 1 1
42 0 ▶ if ( defined( $args->{tup_id} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"tup_id"}) 0 0 0
43 0 $msg->{id} = $args->{tup_id};
44 }
45 0 ▶ if ( defined( $args->{stream} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"stream"}) 0 0 0
46 0 $msg->{stream} = $args->{stream};
47 }
48 0 ▶ if ( defined( $args->{direct_task} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"direct_task"}) 0 0 0
49 0 $msg->{task} = $args->{direct_task};
50 }
51 }
52  
53 1 $self->send_message($msg);
54  
55 1 ▶ if ( defined $msg->{task} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $msg->{'task'}) { } 0 1 1
56 0 return $msg->{task};
57 }
58 else {
59 1 return $self->read_task_ids();
60 }
61 }
62  
63  
64 sub run {
65 0 ▶ my ($self) = @_;
Subroutine run: not called CC=4 SCAR=30.0
Pod documented
66  
67 0 my ( $storm_conf, $context ) = $self->read_handshake();
68 0 $self->_setup_component( $storm_conf, $context );
69 0 $self->initialize( $storm_conf, $context );
70  
71 0 while (1) {
72 0 my $msg = $self->read_command();
73 0 ▶ if ( $msg->{command} eq 'next' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($msg->{'command'} eq 'next') { } 0 0 0
elsif ($msg->{'command'} eq 'ack') { } 0 0 0
elsif ($msg->{'command'} eq 'fail') { } 0 0 0
74 0 $self->next_tuple;
75 }
76 elsif ( $msg->{command} eq 'ack' ) {
77 0 $self->ack( $msg->{id} );
78 }
79 elsif ( $msg->{command} eq 'fail' ) {
80 0 $self->fail( $msg->{id} );
81 }
82 0 $self->sync();
83 }
84 }
85  
86 1 1;
87  
88 __END__
89  
90 =pod
91  
92 =head1 NAME
93  
94 IO::Storm::Spout - The base class for all IO::Storm Spout.
95  
96 =head1 VERSION
97  
98 version 0.16
99  
100 =head1 NAME
101  
102 IO::Storm::Spout - The base class for all IO::Storm Spout.
103  
104 =head1 VERSION
105  
106 version 0.06
107  
108 =head1 METHODS
109  
110 =head2 initialize
111  
112 Called immediately after the initial handshake with Storm and before the main
113 run loop. A good place to initialize connections to data sources.
114  
115 =head2 ack
116  
117 Called when a bolt acknowledges a tuple in the topology.
118  
119 =head2 fail
120  
121 Called when a tuple fails in the topology
122  
123 A Spout can choose to emit the tuple again or ignore the fail. The default is
124 to ignore.
125  
126 =head2 next_tuple
127  
128 Implement this function to emit tuples as necessary.
129  
130 This function should not block, or Storm will think the spout is dead. Instead,
131 let it return and streamparse will send a noop to storm, which lets it know the
132 spout is functioning.
133  
134 =head2 emit
135  
136 Emit a spout tuple message.
137  
138 :param tup: the tuple to send to Storm. Should contain only
139 JSON-serializable data.
140 :type tup: list
141 :param tup_id: the ID for the tuple. Leave this blank for an
142 unreliable emit.
143 :type tup_id: str
144 :param stream: ID of the stream this tuple should be emitted to.
145 Leave empty to emit to the default stream.
146 :type stream: str
147 :param direct_task: the task to send the tuple to if performing a
148 direct emit.
149 :type direct_task: int
150  
151 =head2 run
152  
153 Main run loop for all spouts.
154  
155 Performs initial handshake with Storm and reads tuples handing them off to
156 subclasses. Any exceptions are caught and logged back to Storm prior to the
157 Perl process exiting.
158  
159 Subclasses should **not** override this method.
160  
161 =head1 AUTHORS
162  
163 =over 4
164  
165 =item *
166  
167 Cory G Watson <gphat@cpan.org>
168  
169 =item *
170  
171 Dan Blanchard <dblanchard@ets.org>
172  
173 =back
174  
175 =head1 COPYRIGHT AND LICENSE
176  
177 This software is copyright (c) 2014 by Infinity Interactive, Inc.
178  
179 This is free software; you can redistribute it and/or modify it under
180 the same terms as the Perl 5 programming language system itself.
181  
182 =head1 AUTHORS
183  
184 =over 4
185  
186 =item *
187  
188 Dan Blanchard <dblanchard@ets.org>
189  
190 =item *
191  
192 Cory G Watson <gphat@cpan.org>
193  
194 =back
195  
196 =head1 COPYRIGHT AND LICENSE
197  
198 This software is copyright (c) 2014 by Educational Testing Service.
199  
200 This is free software; you can redistribute it and/or modify it under
201 the same terms as the Perl 5 programming language system itself.
202  
203 =cut
« Storm/Component.pm ↑ Summary Storm/Bolt.pm »