line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gearman::Driver::Worker::AttributeParser; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
104211
|
use Moose::Role; |
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
default => sub { {} }, |
31
|
|
|
|
|
|
|
is => 'rw', |
32
|
|
|
|
|
|
|
isa => 'HashRef', |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has 'override_attributes' => ( |
36
|
|
|
|
|
|
|
default => sub { {} }, |
37
|
|
|
|
|
|
|
is => 'rw', |
38
|
|
|
|
|
|
|
isa => 'HashRef', |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has 'valid_attributes' => ( |
42
|
|
|
|
|
|
|
auto_deref => 1, |
43
|
|
|
|
|
|
|
default => sub { |
44
|
|
|
|
|
|
|
[ |
45
|
|
|
|
|
|
|
qw( |
46
|
|
|
|
|
|
|
Encode |
47
|
|
|
|
|
|
|
Decode |
48
|
|
|
|
|
|
|
Job |
49
|
|
|
|
|
|
|
MaxProcesses |
50
|
|
|
|
|
|
|
MinProcesses |
51
|
|
|
|
|
|
|
ProcessGroup |
52
|
|
|
|
|
|
|
) |
53
|
|
|
|
|
|
|
]; |
54
|
|
|
|
|
|
|
}, |
55
|
|
|
|
|
|
|
is => 'rw', |
56
|
|
|
|
|
|
|
isa => 'ArrayRef', |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _parse_attributes { |
60
|
|
|
|
|
|
|
my ($self) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $attributes = $self->attributes; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $result = {}; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
foreach my $attr ( keys %{ $self->default_attributes } ) { |
67
|
|
|
|
|
|
|
unshift @$attributes, sprintf '%s(%s)', $attr, $self->default_attributes->{$attr}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
foreach my $attr ( keys %{ $self->override_attributes } ) { |
71
|
|
|
|
|
|
|
push @$attributes, sprintf '%s(%s)', $attr, $self->override_attributes->{$attr}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
foreach my $attr (@$attributes) { |
75
|
|
|
|
|
|
|
my ( $type, $value ) = $attr =~ / (\w+) (?: \( (.*?) \) )*/x; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Default values |
78
|
|
|
|
|
|
|
$value ||= 'encode' if $type eq 'Encode'; |
79
|
|
|
|
|
|
|
$value ||= 'decode' if $type eq 'Decode'; |
80
|
|
|
|
|
|
|
$value ||= $self->name if $type eq 'ProcessGroup'; |
81
|
|
|
|
|
|
|
$value = 1 unless defined $value; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
unless ( grep $type eq $_, $self->valid_attributes ) { |
84
|
|
|
|
|
|
|
warn "Invalid attribute '$attr' in " . ref($self); |
85
|
|
|
|
|
|
|
next; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$result->{$type} = $value if defined $value; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
return $result; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
no Moose::Role; |
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
|
|
|
|
|
|
|
1; |