Gearman::Driver::Adaptor - Adaptor to gearman libraries


Gearman-Driver documentation Contained in the Gearman-Driver distribution.

Index


Code Index:

NAME

Top

Gearman::Driver::Adaptor - Adaptor to gearman libraries

DESCRIPTION

Top

Gearman::Driver works with Gearman::XS as well as with the pure Perl modules Gearman and Gearman::Server. By default it tries to use Gearman::XS. If that fails Gearman is used. You can also export an environment variable GEARMAN_DRIVER_ADAPTOR to force usage of Gearman even if you have Gearman::XS.

Example:

* export GEARMAN_DRIVER_ADAPTOR="Gearman::Driver::Adaptor::XS"
* export GEARMAN_DRIVER_ADAPTOR="Gearman::Driver::Adaptor::PP"

AUTHOR

Top

See Gearman::Driver.

COPYRIGHT AND LICENSE

Top

SEE ALSO

Top

* Gearman::Driver
* Gearman::Driver::Console
* Gearman::Driver::Console::Basic
* Gearman::Driver::Console::Client
* Gearman::Driver::Job
* Gearman::Driver::Job::Method
* Gearman::Driver::Loader
* Gearman::Driver::Observer
* Gearman::Driver::Worker::AttributeParser
* Gearman::Driver::Worker::Base

Gearman-Driver documentation Contained in the Gearman-Driver distribution.
package Gearman::Driver::Adaptor;

use Moose;
use Class::MOP;

has 'backend' => (
    builder => '_build_backend',
    handles => [
        qw(
          add_servers
          add_function
          error
          work
          )
    ],
    is => 'ro',
);

has 'server' => (
    is       => 'rw',
    isa      => 'Str',
    required => 1,
);

sub _build_backend {
    my ($self) = @_;

    my @classes = qw(Gearman::Driver::Adaptor::XS Gearman::Driver::Adaptor::PP);

    unshift @classes, $ENV{GEARMAN_DRIVER_ADAPTOR} if defined $ENV{GEARMAN_DRIVER_ADAPTOR};

    foreach my $class (@classes) {
        eval "require $class";
        unless ($@) {
            return $class->new( server => $self->server );
        }
    }

    die "None of the supported adaptors could be loaded: %s\n", join ', ', @classes;
}

sub BUILD {
    my ($self) = @_;
    $self->add_servers( $self->server );
}

1;