Streaming/Reducer/Input/Iterator.pm

filter: Statementstmt 83.3% 25 / 30 Branchbran 50.0% 5 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 3 / 3 totaltotal 79.1% 38 / 48 SCAR 18.8
CC
6
Cov
75%
next
8.1
has_next
2.0
BEGIN
1.0
CRAP 6.6
↑ Summary Streaming/Reducer/Input.pm »
1 package Hadoop::Streaming::Reducer::Input::Iterator;
2 {
3 6 $Hadoop::Streaming::Reducer::Input::Iterator::VERSION = '0.122420';
4 }
5 6 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 with 'Hadoop::Streaming::Role::Iterator';
7  
8 6 ▶use Hadoop::Streaming::Reducer::Input::ValuesIterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #ABSTRACT: Collects values for each key together with an iterator interface
11  
12 6 has input => (
13 is => 'ro',
14 isa => 'Hadoop::Streaming::Reducer::Input',
15 required => 1,
16 );
17  
18 6 has current_key => (
19 is => 'rw',
20 does => 'Str'
21 );
22  
23  
24 sub has_next {
25 82 ▶ my $self = shift;
Subroutine has_next: called CC=2 SCAR=6.9
Pod documented
26 82 ▶ return if not defined $self->input->next_key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->input->next_key 5 77 82
27 77 1;
28 }
29  
30  
31 sub next {
32 77 ▶ my $self = shift;
Subroutine next: called CC=5 SCAR=20.9
Pod documented
33  
34 77 ▶ if ( not defined $self->current_key ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->current_key) 5 72 77
35 5 $self->current_key($self->input->next_key);
36 5 return $self->retval( $self->current_key );
37 }
38  
39 72 ▶ if ($self->current_key ne $self->input->next_key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->current_key ne $self->input->next_key) 72 0 72
40 72 $self->current_key($self->input->next_key);
41 72 return $self->retval( $self->current_key );
42 }
43  
44 0 my ($key, $value);
45 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$self->current_key eq $key and do { do { () = $self->input->each or return } } 0 0 0
46 0 ▶ ($key, $value) = $self->input->each or return;
Branch: 1 branch
BranchTrueFalseTotal
() = $self->input->each or return 0 0 0
47 } while ($self->current_key eq $key);
48 0 $self->current_key( $key );
49  
50 0 return $self->retval($key, $value);
51 }
52  
53  
54 sub retval {
55 77 ▶ my ($self, $key, $value) = @_;
Subroutine retval: called CC=1 SCAR=0.0
Pod documented
56 return (
57 77 $key,
58 Hadoop::Streaming::Reducer::Input::ValuesIterator->new(
59 input_iter => $self,
60 first => $value,
61 ),
62 );
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::Iterator - Collects values for each key together with an iterator interface
75  
76 =head1 VERSION
77  
78 version 0.122420
79  
80 =head1 METHODS
81  
82 =head2 has_next
83  
84 $Iterator->has_next();
85  
86 Checks if the iterator has a next_key. Returns 1 if there is another key in the input iterator.
87  
88 =head2 next
89  
90 $Iterator->next();
91  
92 Returns the key and value iterator for the next key. Discards any remaining values from the current key.
93  
94 Moves the iterator to the next key value, and returns the output of retval( $key, $value);
95  
96 =head2 retval
97  
98 $Iterator->retval($key );
99 $Iterator->retval($key, $value);
100  
101 Returns an two element array containing the key and a Hadoop::Streaming::Reducer::Input::ValuesIterator initialized with the given value as the first element.
102  
103 ( $key, $ValueIterator)
104  
105 =head1 AUTHORS
106  
107 =over 4
108  
109 =item *
110  
111 andrew grangaard <spazm@cpan.org>
112  
113 =item *
114  
115 Naoya Ito <naoya@hatena.ne.jp>
116  
117 =back
118  
119 =head1 COPYRIGHT AND LICENSE
120  
121 This software is copyright (c) 2012 by Naoya Ito <naoya@hatena.ne.jp>.
122  
123 This is free software; you can redistribute it and/or modify it under
124 the same terms as the Perl 5 programming language system itself.
125  
126 =cut
127  
↑ Summary Streaming/Reducer/Input.pm »