| 1 | package Hadoop::Streaming::Role::Emitter; | ||||||||||||
| 2 | { | ||||||||||||
| 3 | 10 | $Hadoop::Streaming::Role::Emitter::VERSION = '0.122420'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | 10 | ▶ | use Any::Moose qw(Role); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 10 | ▶ | use Params::Validate qw/validate_pos/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | #provides qw(run emit counter status); | ||||||||||||
| 9 | |||||||||||||
| 10 | # ABSTRACT: Role to provide emit, counter, and status interaction with Hadoop::Streaming. | ||||||||||||
| 11 | |||||||||||||
| 12 | |||||||||||||
| 13 | sub emit { | ||||||||||||
| 14 | 331 | ▶ | my ($self, $key, $value) = @_; | ||||||||||
|
Subroutine
emit: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||
| 15 | 331 | eval { | |||||||||||
| 16 | 331 | $self->put($key, $value); | |||||||||||
| 17 | }; | ||||||||||||
| 18 | 331 | ▶ | if ($@) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 19 | 0 | warn $@; | |||||||||||
| 20 | } | ||||||||||||
| 21 | } | ||||||||||||
| 22 | |||||||||||||
| 23 | |||||||||||||
| 24 | sub put | ||||||||||||
| 25 | { | ||||||||||||
| 26 | 331 | ▶ | my ($self, $key, $value) = validate_pos(@_, 1, 1, 1); | ||||||||||
|
Subroutine
put: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 27 | 331 | printf "%s\t%s\n", $key, $value; | |||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | |||||||||||||
| 31 | sub counter | ||||||||||||
| 32 | { | ||||||||||||
| 33 | 4 | ▶ | my ( $self, %opts ) = @_; | ||||||||||
|
Subroutine
counter: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||
| 34 | |||||||||||||
| 35 | 4 | ▶ | my $group = $opts{group} || 'group'; | ||||||||||
|
Condition50%1/2
$opts{'group'} || 'group'
MC/DC0%0/1
$opts{'group'} || 'group'
$opts{'group'}
Truth table50%1/2
A
A= $opts{'group'}
| |||||||||||||
| 36 | 4 | ▶ | my $counter = $opts{counter} || 'counter'; | ||||||||||
|
Condition50%1/2
$opts{'counter'} || 'counter'
MC/DC0%0/1
$opts{'counter'} || 'counter'
$opts{'counter'}
Truth table50%1/2
A
A= $opts{'counter'}
| |||||||||||||
| 37 | 4 | ▶ | my $amount = $opts{amount} || 'amount'; | ||||||||||
|
Condition50%1/2
$opts{'amount'} || 'amount'
MC/DC0%0/1
$opts{'amount'} || 'amount'
$opts{'amount'}
Truth table50%1/2
A
A= $opts{'amount'}
| |||||||||||||
| 38 | |||||||||||||
| 39 | 4 | my $msg | |||||||||||
| 40 | = sprintf( "reporter:counter:%s,%s,%s\n", $group, $counter, $amount ); | ||||||||||||
| 41 | 4 | print STDERR $msg; | |||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | |||||||||||||
| 45 | sub status | ||||||||||||
| 46 | { | ||||||||||||
| 47 | 0 | ▶ | my ($self, $message ) = @_; | ||||||||||
|
Subroutine
status: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 48 | |||||||||||||
| 49 | 0 | my $msg = sprintf( "reporter:status:%s\n", $message); | |||||||||||
| 50 | 0 | print STDERR $msg; | |||||||||||
| 51 | } | ||||||||||||
| 52 | |||||||||||||
| 53 | 10 | 1; | |||||||||||
| 54 | |||||||||||||
| 55 | __END__ | ||||||||||||
| 56 | =pod | ||||||||||||
| 57 | |||||||||||||
| 58 | =head1 NAME | ||||||||||||
| 59 | |||||||||||||
| 60 | Hadoop::Streaming::Role::Emitter - Role to provide emit, counter, and status interaction with Hadoop::Streaming. | ||||||||||||
| 61 | |||||||||||||
| 62 | =head1 VERSION | ||||||||||||
| 63 | |||||||||||||
| 64 | version 0.122420 | ||||||||||||
| 65 | |||||||||||||
| 66 | =head1 METHODS | ||||||||||||
| 67 | |||||||||||||
| 68 | =head2 emit | ||||||||||||
| 69 | |||||||||||||
| 70 | $object->emit( $key, $value ) | ||||||||||||
| 71 | |||||||||||||
| 72 | This method emits a key,value pair in the format expected by Hadoop::Streaming. | ||||||||||||
| 73 | It does this by calling $self->put(). This catches errors from put and turns | ||||||||||||
| 74 | them into warnings. | ||||||||||||
| 75 | |||||||||||||
| 76 | =head2 put | ||||||||||||
| 77 | |||||||||||||
| 78 | $object->put( $key, $value ) | ||||||||||||
| 79 | |||||||||||||
| 80 | This method emits a key,value pair to STDOUT in the format expected by | ||||||||||||
| 81 | Hadoop::Streaming: ( key \t value \n ) | ||||||||||||
| 82 | |||||||||||||
| 83 | =head2 counter | ||||||||||||
| 84 | |||||||||||||
| 85 | $object->counter( | ||||||||||||
| 86 | group => $group, | ||||||||||||
| 87 | counter => $countername, | ||||||||||||
| 88 | amount => $count, | ||||||||||||
| 89 | ); | ||||||||||||
| 90 | |||||||||||||
| 91 | This method emits a counter key to STDERR in the format expected by hadoop: | ||||||||||||
| 92 | reporter:counter:<group>,<counter>,<amount> | ||||||||||||
| 93 | |||||||||||||
| 94 | =head2 status | ||||||||||||
| 95 | |||||||||||||
| 96 | $object->status( $message ) | ||||||||||||
| 97 | |||||||||||||
| 98 | This method emits a status message to STDERR in the format expected by Hadoop::Streaming: | ||||||||||||
| 99 | reporter:status:$message\n | ||||||||||||
| 100 | |||||||||||||
| 101 | =head1 AUTHORS | ||||||||||||
| 102 | |||||||||||||
| 103 | =over 4 | ||||||||||||
| 104 | |||||||||||||
| 105 | =item * | ||||||||||||
| 106 | |||||||||||||
| 107 | andrew grangaard <spazm@cpan.org> | ||||||||||||
| 108 | |||||||||||||
| 109 | =item * | ||||||||||||
| 110 | |||||||||||||
| 111 | Naoya Ito <naoya@hatena.ne.jp> | ||||||||||||
| 112 | |||||||||||||
| 113 | =back | ||||||||||||
| 114 | |||||||||||||
| 115 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 116 | |||||||||||||
| 117 | This software is copyright (c) 2012 by Naoya Ito <naoya@hatena.ne.jp>. | ||||||||||||
| 118 | |||||||||||||
| 119 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 120 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 121 | |||||||||||||
| 122 | =cut | ||||||||||||
| 123 | |||||||||||||