Streaming/Reducer/Input.pm

filter: Statementstmt 96.9% 32 / 33 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 5 / 5 totaltotal 94.5% 52 / 55 SCAR 17.9
CC
6
Cov
93%
next_key
3.0
getline
2.1
each
2.0
CRAP 6.0
« Streaming/Reducer/Input/Iterator.pm ↑ Summary Streaming/Role/Emitter.pm »
1 package Hadoop::Streaming::Reducer::Input;
2 {
3 6 $Hadoop::Streaming::Reducer::Input::VERSION = '0.122420';
4 }
5 6 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Hadoop::Streaming::Reducer::Input::Iterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 #ABSTRACT: Parse input stream for reducer
9  
10 6 has handle => (
11 is => 'ro',
12 does => 'FileHandle',
13 required => 1,
14 );
15  
16 6 has buffer => (
17 is => 'rw',
18 );
19  
20  
21 sub next_key
22 {
23 978 ▶ my $self = shift;
Subroutine next_key: called CC=3 SCAR=11.0
Pod documented
24 978 ▶ my $line = $self->buffer ? $self->buffer : $self->next_line;
Branch: 1 branch
BranchTrueFalseTotal
$self->buffer ? : 669 309 978
25 978 ▶ return if not defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 10 968 978
26 968 my ( $key, $value ) = split /\t/, $line, 2;
27 968 return $key;
28 }
29  
30  
31 sub next_line {
32 309 ▶ my $self = shift;
Subroutine next_line: called CC=2 SCAR=6.9
Pod documented
33 309 ▶ return if $self->handle->eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->handle->eof 10 299 309
34 299 $self->buffer( $self->handle->getline );
35 299 $self->buffer;
36 }
37  
38  
39 sub getline {
40 299 ▶ my $self = shift;
Subroutine getline: called CC=2 SCAR=7.2
Pod documented
41 299 ▶ if (defined $self->buffer) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->buffer) { } 299 0 299
42 299 my $buf = $self->buffer;
43 299 $self->buffer(undef);
44 299 return $buf;
45 } else {
46 0 return $self->next_line;
47 }
48 }
49  
50  
51 sub iterator {
52 5 ▶ my $self = shift;
Subroutine iterator: called CC=1 SCAR=0.0
Pod documented
53 5 Hadoop::Streaming::Reducer::Input::Iterator->new( input => $self );
54 }
55  
56  
57 sub each
58 {
59 299 ▶ my $self = shift;
Subroutine each: called CC=2 SCAR=7.0
Pod documented
60 299 ▶ my $line = $self->getline or return;
Branch: 1 branch
BranchTrueFalseTotal
my $line = $self->getline or return 0 299 299
61 299 chomp $line;
62 299 split /\t/, $line, 2;
63 }
64  
65 6 __PACKAGE__->meta->make_immutable;
66  
67 6 1;
68  
69 __END__
70 =pod
71  
72 =head1 NAME
73  
74 Hadoop::Streaming::Reducer::Input - Parse input stream for reducer
75  
76 =head1 VERSION
77  
78 version 0.122420
79  
80 =head1 METHODS
81  
82 =head2 next_key
83  
84 $Input->next_key();
85  
86 Parses the next line into key/value (splits on tab) and returns the key portion.
87  
88 Returns undef if there is no next line.
89  
90 =head2 next_line
91  
92 $Input->next_line();
93  
94 Reads the next line into buffer and returns it.
95  
96 Returns undef if there are no more lines (end of file).
97  
98 =head2 getline
99  
100 $Input->getline();
101  
102 Returns the next available line. Clears the internal line buffer if set.
103  
104 =head2 iterator
105  
106 $Input->iterator();
107  
108 Returns a new Hadoop::Streaming::Reducer::Input::Iterator for this object.
109  
110 =head2 each
111  
112 $Input->each();
113  
114 Grabs the next line and splits on tabs. Returns an array containing the output of the split.
115  
116 =head1 AUTHORS
117  
118 =over 4
119  
120 =item *
121  
122 andrew grangaard <spazm@cpan.org>
123  
124 =item *
125  
126 Naoya Ito <naoya@hatena.ne.jp>
127  
128 =back
129  
130 =head1 COPYRIGHT AND LICENSE
131  
132 This software is copyright (c) 2012 by Naoya Ito <naoya@hatena.ne.jp>.
133  
134 This is free software; you can redistribute it and/or modify it under
135 the same terms as the Perl 5 programming language system itself.
136  
137 =cut
138  
« Streaming/Reducer/Input/Iterator.pm ↑ Summary Streaming/Role/Emitter.pm »