| 1 | package Gearman::Driver::Worker::AttributeParser; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 15 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | Gearman::Driver::Worker::AttributeParser - Parses worker attributes | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | This module is responsible for parsing the | ||||||||||||||||||||||||||||
| 12 | L<method attributes|Gearman::Driver::Worker/METHODATTRIBUTES> | ||||||||||||||||||||||||||||
| 13 | of a worker. It has no public interface currently. | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =cut | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 15 | has 'parsed_attributes' => ( | |||||||||||||||||||||||||||
| 18 | builder => '_parse_attributes', | ||||||||||||||||||||||||||||
| 19 | handles => { | ||||||||||||||||||||||||||||
| 20 | has_attribute => 'defined', | ||||||||||||||||||||||||||||
| 21 | get_attribute => 'get', | ||||||||||||||||||||||||||||
| 22 | }, | ||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||
| 24 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 25 | lazy => 1, | ||||||||||||||||||||||||||||
| 26 | traits => [qw(Hash)], | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | has 'default_attributes' => ( | ||||||||||||||||||||||||||||
| 30 | 66 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 15 | is => 'rw', | |||||||||||||||||||||||||||
| 32 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | has 'override_attributes' => ( | ||||||||||||||||||||||||||||
| 36 | 66 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 15 | is => 'rw', | |||||||||||||||||||||||||||
| 38 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | has 'valid_attributes' => ( | ||||||||||||||||||||||||||||
| 42 | auto_deref => 1, | ||||||||||||||||||||||||||||
| 43 | 66 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | [ | ||||||||||||||||||||||||||||
| 45 | 66 | qw( | |||||||||||||||||||||||||||
| 46 | Encode | ||||||||||||||||||||||||||||
| 47 | Decode | ||||||||||||||||||||||||||||
| 48 | Job | ||||||||||||||||||||||||||||
| 49 | MaxProcesses | ||||||||||||||||||||||||||||
| 50 | MinProcesses | ||||||||||||||||||||||||||||
| 51 | ProcessGroup | ||||||||||||||||||||||||||||
| 52 | ) | ||||||||||||||||||||||||||||
| 53 | ]; | ||||||||||||||||||||||||||||
| 54 | }, | ||||||||||||||||||||||||||||
| 55 | 15 | is => 'rw', | |||||||||||||||||||||||||||
| 56 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 66 | ▶ | sub _parse_attributes { | ||||||||||||||||||||||||||
|
Subroutine
_parse_attributes: called CC=13 SCAR=26.1
| |||||||||||||||||||||||||||||
| 60 | 66 | my ($self) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 66 | my $attributes = $self->attributes; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 66 | my $result = {}; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 66 | foreach my $attr ( keys %{ $self->default_attributes } ) { | |||||||||||||||||||||||||||
| 67 | 24 | unshift @$attributes, sprintf '%s(%s)', $attr, $self->default_attributes->{$attr}; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 66 | foreach my $attr ( keys %{ $self->override_attributes } ) { | |||||||||||||||||||||||||||
| 71 | 12 | push @$attributes, sprintf '%s(%s)', $attr, $self->override_attributes->{$attr}; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 66 | foreach my $attr (@$attributes) { | |||||||||||||||||||||||||||
| 75 | 183 | my ( $type, $value ) = $attr =~ / (\w+) (?: \( (.*?) \) )*/x; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # Default values | ||||||||||||||||||||||||||||
| 78 | 183 | ▶ | $value ||= 'encode' if $type eq 'Encode'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$value ||= "encode"
MC/DC100%1/1
$value ||= "encode"
$value
Truth table100%2/2
A
A= $value
| |||||||||||||||||||||||||||||
| 79 | 183 | ▶ | $value ||= 'decode' if $type eq 'Decode'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$value ||= "decode"
MC/DC100%1/1
$value ||= "decode"
$value
Truth table100%2/2
A
A= $value
| |||||||||||||||||||||||||||||
| 80 | 183 | ▶ | $value ||= $self->name if $type eq 'ProcessGroup'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$value ||= $self->name
MC/DC0%0/2
$value ||= $self->name
$value
$self->name
Truth table33%1/3
A ||= B
A= $valueB= $self->name
| |||||||||||||||||||||||||||||
| 81 | 183 | ▶ | $value = 1 unless defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 183 | ▶ | unless ( grep $type eq $_, $self->valid_attributes ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | warn "Invalid attribute '$attr' in " . ref($self); | |||||||||||||||||||||||||||
| 85 | 0 | next; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 183 | ▶ | $result->{$type} = $value if defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 66 | return $result; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 15 | ▶ | no Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | See L<Gearman::Driver>. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | See L<Gearman::Driver>. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =over 4 | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =item * L<Gearman::Driver> | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =item * L<Gearman::Driver::Adaptor> | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =item * L<Gearman::Driver::Console> | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =item * L<Gearman::Driver::Console::Basic> | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =item * L<Gearman::Driver::Console::Client> | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =item * L<Gearman::Driver::Job> | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =item * L<Gearman::Driver::Job::Method> | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =item * L<Gearman::Driver::Loader> | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =item * L<Gearman::Driver::Observer> | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =item * L<Gearman::Driver::Worker> | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =item * L<Gearman::Driver::Worker::Base> | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =back | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =cut | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 15 | 1; | |||||||||||||||||||||||||||