
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.
See also: "wanted".
ArrayRefTrueCodeRefFalseThis 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:
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:
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:
gearman_driver.pl --lib ./lib --lib /custom/lib --namespaces My::Workers
StrEvery worker module loaded by Module::Find will be added to this list. There are also two methods: get_modules and has_modules.
ArrayRefTrue
Returns a sorted list of namespaces.
Returns a sorted list of modules.
Returns the count of modules.
Parameters: $package
Checks if the given $package is a valid subclass of Gearman::Driver::Worker.
Parameters: $package
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 Class::MOP::load_class. 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.

See Gearman::Driver.
