| 1 | package Gearman::Driver::Adaptor; | ||||||||||
| 2 | |||||||||||
| 3 | 28 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 28 | ▶ | use Class::MOP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | =head1 NAME | ||||||||||
| 7 | |||||||||||
| 8 | Gearman::Driver::Adaptor - Adaptor to gearman libraries | ||||||||||
| 9 | |||||||||||
| 10 | =head1 DESCRIPTION | ||||||||||
| 11 | |||||||||||
| 12 | L<Gearman::Driver> works with L<Gearman::XS> as well as with the pure | ||||||||||
| 13 | Perl modules L<Gearman> and L<Gearman::Server>. By default it tries | ||||||||||
| 14 | to use L<Gearman::XS>. If that fails L<Gearman> is used. You can | ||||||||||
| 15 | also export an environment variable C<GEARMAN_DRIVER_ADAPTOR> to | ||||||||||
| 16 | force usage of L<Gearman> even if you have L<Gearman::XS>. | ||||||||||
| 17 | |||||||||||
| 18 | Example: | ||||||||||
| 19 | |||||||||||
| 20 | =over 4 | ||||||||||
| 21 | |||||||||||
| 22 | =item * C<export GEARMAN_DRIVER_ADAPTOR="Gearman::Driver::Adaptor::XS"> | ||||||||||
| 23 | |||||||||||
| 24 | =item * C<export GEARMAN_DRIVER_ADAPTOR="Gearman::Driver::Adaptor::PP"> | ||||||||||
| 25 | |||||||||||
| 26 | =back | ||||||||||
| 27 | |||||||||||
| 28 | =cut | ||||||||||
| 29 | |||||||||||
| 30 | 28 | has 'backend' => ( | |||||||||
| 31 | builder => '_build_backend', | ||||||||||
| 32 | handles => [ | ||||||||||
| 33 | qw( | ||||||||||
| 34 | add_servers | ||||||||||
| 35 | add_function | ||||||||||
| 36 | error | ||||||||||
| 37 | work | ||||||||||
| 38 | ) | ||||||||||
| 39 | ], | ||||||||||
| 40 | is => 'ro', | ||||||||||
| 41 | ); | ||||||||||
| 42 | |||||||||||
| 43 | 28 | has 'server' => ( | |||||||||
| 44 | is => 'rw', | ||||||||||
| 45 | isa => 'Str', | ||||||||||
| 46 | required => 1, | ||||||||||
| 47 | ); | ||||||||||
| 48 | |||||||||||
| 49 | 18 | ▶ | sub _build_backend { | ||||||||
|
Subroutine
_build_backend: called CC=4 SCAR=14.5
| |||||||||||
| 50 | 18 | my ($self) = @_; | |||||||||
| 51 | |||||||||||
| 52 | 18 | my @classes = qw(Gearman::Driver::Adaptor::XS Gearman::Driver::Adaptor::PP); | |||||||||
| 53 | |||||||||||
| 54 | 18 | ▶ | unshift @classes, $ENV{GEARMAN_DRIVER_ADAPTOR} if defined $ENV{GEARMAN_DRIVER_ADAPTOR}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | |||||||||||
| 56 | 18 | foreach my $class (@classes) { | |||||||||
| 57 | 18 | eval "require $class"; | |||||||||
| 58 | 18 | ▶ | unless ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 18 | return $class->new( server => $self->server ); | |||||||||
| 60 | } | ||||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 0 | die "None of the supported adaptors could be loaded: %s\n", join ', ', @classes; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 18 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 67 | 18 | my ($self) = @_; | |||||||||
| 68 | 18 | $self->add_servers( $self->server ); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | =head1 AUTHOR | ||||||||||
| 72 | |||||||||||
| 73 | See L<Gearman::Driver>. | ||||||||||
| 74 | |||||||||||
| 75 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 76 | |||||||||||
| 77 | See L<Gearman::Driver>. | ||||||||||
| 78 | |||||||||||
| 79 | =head1 SEE ALSO | ||||||||||
| 80 | |||||||||||
| 81 | =over 4 | ||||||||||
| 82 | |||||||||||
| 83 | =item * L<Gearman::Driver> | ||||||||||
| 84 | |||||||||||
| 85 | =item * L<Gearman::Driver::Console> | ||||||||||
| 86 | |||||||||||
| 87 | =item * L<Gearman::Driver::Console::Basic> | ||||||||||
| 88 | |||||||||||
| 89 | =item * L<Gearman::Driver::Console::Client> | ||||||||||
| 90 | |||||||||||
| 91 | =item * L<Gearman::Driver::Job> | ||||||||||
| 92 | |||||||||||
| 93 | =item * L<Gearman::Driver::Job::Method> | ||||||||||
| 94 | |||||||||||
| 95 | =item * L<Gearman::Driver::Loader> | ||||||||||
| 96 | |||||||||||
| 97 | =item * L<Gearman::Driver::Observer> | ||||||||||
| 98 | |||||||||||
| 99 | =item * L<Gearman::Driver::Worker::AttributeParser> | ||||||||||
| 100 | |||||||||||
| 101 | =item * L<Gearman::Driver::Worker::Base> | ||||||||||
| 102 | |||||||||||
| 103 | =back | ||||||||||
| 104 | |||||||||||
| 105 | =cut | ||||||||||
| 106 | |||||||||||
| 107 | 28 | 1; | |||||||||