Gearman::Driver::Loader - Loads worker classes
This module is responsible for loading worker classes and doing the introspection on them (looking for job method attributes etc). All methods and attributes are internally used in Gearman::Driver but this module (implemented as Moose::Role) might be of interest to use outside of Gearman::Driver.
Will be passed to Module::Find findallmod method to load worker modules. Each one of those modules has to be inherited from Gearman::Driver::Worker or a subclass of it. It's also possible to use the full package name to load a single module/file. There is also a method get_namespaces which returns a sorted list of all namespaces.
findallmod
See also: "wanted".
isa: ArrayRef
ArrayRef
required: True
True
isa: CodeRef
CodeRef
required: False
False
This CodeRef will be called on each of the modules found in your "namespace". The first and only parameter to this sub is the name of the module. If a true value is returned, the module will be loaded and checked if it's a valid Gearman::Driver::Worker subclass.
Let's say you have a namespace called My::Project:
My::Project
My::Project::Web
My::Project::Web::Controller::Root
My::Project::Web::Controller::Admin
My::Project::Web::Controller::User
My::Project::Web::Model::DBIC
My::Project::Worker::ScaleImage
My::Project::Worker::RemoveUser
To avoid every module being loaded and inspected being a Gearman::Driver::Worker subclass you can use wanted to only load classes having Worker in the package name:
wanted
Worker
my $driver = Gearman::Driver->new( interval => 0, namespaces => [qw(My::Project)], wanted => sub { return 1 if /Worker/; return 0; }, );
This would only load:
This is just for convenience to extend @INC from command line using gearman_driver.pl:
@INC
gearman_driver.pl
gearman_driver.pl --lib ./lib --lib /custom/lib --namespaces My::Workers
isa: Str
Str
Every worker module loaded by Module::Find will be added to this list. There are also two methods: get_modules and has_modules.
readonly: True
Returns a sorted list of namespaces.
Returns a sorted list of modules.
Returns the count of modules.
Parameters: $package
$package
Checks if the given $package is a valid subclass of Gearman::Driver::Worker.
Checks if the given $package has a valid job method.
Loops over all "namespaces" and uses findallmod to generate a list of modules to load. It verifies the module is "wanted" before it's being loaded using Module::Runtime::use_module. After loading "is_valid_worker_subclass" and has_wanted is used to verify it. After all tests have passed the modules are added. So finally the loader is ready and can be queried with get_modules for example.
See Gearman::Driver.
Gearman::Driver
Gearman::Driver::Adaptor
Gearman::Driver::Console
Gearman::Driver::Console::Client
Gearman::Driver::Job
Gearman::Driver::Job::Method
Gearman::Driver::Observer
Gearman::Driver::Worker
To install Gearman::Driver, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Gearman::Driver
CPAN shell
perl -MCPAN -e shell install Gearman::Driver
For more information on module installation, please visit the detailed CPAN module installation guide.