Streaming/Reducer/Input.pm

filter: Statementstmt 96.8% 31 / 32 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 5 / 5 totaltotal 94.4% 51 / 54 CC 6 SCAR 7.0
CC
6
Cov
93%
next_key
3.0
getline
2.1
each
2.0
CRAP 2.0
« Streaming/Role/Emitter.pm ↑ Summary Streaming/Mapper.pm »
1 package Hadoop::Streaming::Reducer::Input;
2 6 $Hadoop::Streaming::Reducer::Input::VERSION = '0.143060';
3 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Hadoop::Streaming::Reducer::Input::Iterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 #ABSTRACT: Parse input stream for reducer
7  
8 6 has handle => (
9 is => 'ro',
10 does => 'FileHandle',
11 required => 1,
12 );
13  
14 6 has buffer => (
15 is => 'rw',
16 );
17  
18  
19 sub next_key
20 978 ▶{
Subroutine next_key: called CC=3 SCAR=11.0
Pod documented
21 978 my $self = shift;
22 978 ▶ my $line = $self->buffer ? $self->buffer : $self->next_line;
Branch: 1 branch
BranchTrueFalseTotal
$self->buffer ? : 669 309 978
23 978 ▶ return if not defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 10 968 978
24 968 my ( $key, $value ) = split /\t/, $line, 2;
25 968 return $key;
26 }
27  
28  
29 309 ▶sub next_line {
Subroutine next_line: called CC=2 SCAR=6.9
Pod documented
30 309 my $self = shift;
31 309 ▶ return if $self->handle->eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->handle->eof 10 299 309
32 299 $self->buffer( $self->handle->getline );
33 299 $self->buffer;
34 }
35  
36  
37 299 ▶sub getline {
Subroutine getline: called CC=2 SCAR=7.2
Pod documented
38 299 my $self = shift;
39 299 ▶ if (defined $self->buffer) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->buffer) { } 299 0 299
40 299 my $buf = $self->buffer;
41 299 $self->buffer(undef);
42 299 return $buf;
43 } else {
44 0 return $self->next_line;
45 }
46 }
47  
48  
49 5 ▶sub iterator {
Subroutine iterator: called CC=1 SCAR=0.0
Pod documented
50 5 my $self = shift;
51 5 Hadoop::Streaming::Reducer::Input::Iterator->new( input => $self );
52 }
53  
54  
55 sub each
56 299 ▶{
Subroutine each: called CC=2 SCAR=7.0
Pod documented
57 299 my $self = shift;
58 299 ▶ my $line = $self->getline or return;
Branch: 1 branch
BranchTrueFalseTotal
my $line = $self->getline or return 299 0 299
59 299 chomp $line;
60 299 split /\t/, $line, 2;
61 }
62  
63 6 __PACKAGE__->meta->make_immutable;
64  
65 6 1;
66  
67 __END__
« Streaming/Role/Emitter.pm ↑ Summary Streaming/Mapper.pm »