| 1 | package Data::Riak::Fast::MapReduce::Phase::Map; | ||||||||||||||
| 2 | 22 | ▶ | use Mouse; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 22 | ▶ | use Mouse::Util::TypeConstraints; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 22 | ▶ | use JSON::XS (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | # ABSTRACT: Map phase of a MapReduce | ||||||||||||||
| 8 | |||||||||||||||
| 9 | 22 | with ('Data::Riak::Fast::MapReduce::Phase'); | |||||||||||||
| 10 | |||||||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||||||
| 12 | |||||||||||||||
| 13 | A map/reduce map phase for Data::Riak::Fast | ||||||||||||||
| 14 | |||||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||||
| 16 | |||||||||||||||
| 17 | my $mp = Data::Riak::Fast::MapReduce::Phase::Map->new( | ||||||||||||||
| 18 | language => "javascript", # The default | ||||||||||||||
| 19 | source => "function(v) { return [ v ] }", | ||||||||||||||
| 20 | keep => 1 # The default | ||||||||||||||
| 21 | ); | ||||||||||||||
| 22 | |||||||||||||||
| 23 | =head2 keep | ||||||||||||||
| 24 | |||||||||||||||
| 25 | Flag controlling whether the results of this phase are included in the final | ||||||||||||||
| 26 | result of the map/reduce. Defaults to true. | ||||||||||||||
| 27 | |||||||||||||||
| 28 | =head2 language | ||||||||||||||
| 29 | |||||||||||||||
| 30 | The language used with this phase. One of C<javascript> or C<erlang>. This | ||||||||||||||
| 31 | attribute is required. | ||||||||||||||
| 32 | |||||||||||||||
| 33 | =cut | ||||||||||||||
| 34 | |||||||||||||||
| 35 | 22 | has language => ( | |||||||||||||
| 36 | is => 'ro', | ||||||||||||||
| 37 | isa => enum([qw(javascript erlang)]), | ||||||||||||||
| 38 | required => 1 | ||||||||||||||
| 39 | ); | ||||||||||||||
| 40 | |||||||||||||||
| 41 | =head2 name | ||||||||||||||
| 42 | |||||||||||||||
| 43 | The name, used with built-in functions provided by Riak such as | ||||||||||||||
| 44 | C<Riak.mapValues>. | ||||||||||||||
| 45 | |||||||||||||||
| 46 | =cut | ||||||||||||||
| 47 | |||||||||||||||
| 48 | 22 | has name => ( | |||||||||||||
| 49 | is => 'ro', | ||||||||||||||
| 50 | isa => 'Str', | ||||||||||||||
| 51 | predicate => 'has_name' | ||||||||||||||
| 52 | ); | ||||||||||||||
| 53 | |||||||||||||||
| 54 | 22 | has phase => ( | |||||||||||||
| 55 | is => 'ro', | ||||||||||||||
| 56 | isa => 'Str', | ||||||||||||||
| 57 | default => 'map' | ||||||||||||||
| 58 | ); | ||||||||||||||
| 59 | |||||||||||||||
| 60 | =head2 arg | ||||||||||||||
| 61 | |||||||||||||||
| 62 | The static argument passed to the map function. | ||||||||||||||
| 63 | |||||||||||||||
| 64 | =cut | ||||||||||||||
| 65 | |||||||||||||||
| 66 | 22 | has arg => ( | |||||||||||||
| 67 | is => 'ro', | ||||||||||||||
| 68 | isa => 'Str|HashRef', | ||||||||||||||
| 69 | predicate => 'has_arg' | ||||||||||||||
| 70 | ); | ||||||||||||||
| 71 | |||||||||||||||
| 72 | =head2 module | ||||||||||||||
| 73 | |||||||||||||||
| 74 | The module name, if you are using a riak built-in function. | ||||||||||||||
| 75 | |||||||||||||||
| 76 | =cut | ||||||||||||||
| 77 | |||||||||||||||
| 78 | 22 | has module => ( | |||||||||||||
| 79 | is => 'ro', | ||||||||||||||
| 80 | isa => 'Str', | ||||||||||||||
| 81 | predicate => 'has_module' | ||||||||||||||
| 82 | ); | ||||||||||||||
| 83 | |||||||||||||||
| 84 | =head2 function | ||||||||||||||
| 85 | |||||||||||||||
| 86 | The function name, if you are using a riak built-in function. | ||||||||||||||
| 87 | |||||||||||||||
| 88 | =cut | ||||||||||||||
| 89 | |||||||||||||||
| 90 | 22 | has function => ( | |||||||||||||
| 91 | is => 'ro', | ||||||||||||||
| 92 | isa => 'Str', | ||||||||||||||
| 93 | predicate => 'has_function' | ||||||||||||||
| 94 | ); | ||||||||||||||
| 95 | |||||||||||||||
| 96 | =head2 source | ||||||||||||||
| 97 | |||||||||||||||
| 98 | The source of the function used in this phase. | ||||||||||||||
| 99 | |||||||||||||||
| 100 | =cut | ||||||||||||||
| 101 | |||||||||||||||
| 102 | 22 | has source => ( | |||||||||||||
| 103 | is => 'ro', | ||||||||||||||
| 104 | isa => 'Str', | ||||||||||||||
| 105 | predicate => 'has_source' | ||||||||||||||
| 106 | ); | ||||||||||||||
| 107 | |||||||||||||||
| 108 | =head1 METHOD | ||||||||||||||
| 109 | =head2 pack() | ||||||||||||||
| 110 | |||||||||||||||
| 111 | Serialize this map phase. | ||||||||||||||
| 112 | |||||||||||||||
| 113 | =cut | ||||||||||||||
| 114 | |||||||||||||||
| 115 | 0 | ▶ | sub pack { | ||||||||||||
|
Subroutine
pack: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||
| 116 | 0 | my $self = shift; | |||||||||||||
| 117 | |||||||||||||||
| 118 | 0 | my $href = {}; | |||||||||||||
| 119 | |||||||||||||||
| 120 | 0 | ▶ | $href->{keep} = $self->keep ? JSON::XS::true() : JSON::XS::false() if $self->has_keep; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 121 | 0 | $href->{language} = $self->language; | |||||||||||||
| 122 | 0 | ▶ | $href->{name} = $self->name if $self->has_name; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 123 | 0 | ▶ | $href->{source} = $self->source if $self->has_source; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 124 | 0 | ▶ | $href->{module} = $self->module if $self->has_module; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 125 | 0 | ▶ | $href->{function} = $self->function if $self->has_function; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 126 | 0 | ▶ | $href->{arg} = $self->arg if $self->has_arg; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 127 | |||||||||||||||
| 128 | 0 | $href; | |||||||||||||
| 129 | } | ||||||||||||||
| 130 | |||||||||||||||
| 131 | 22 | 1; | |||||||||||||