[Catalyst] ACCEPT_CONTEXT with Module::Pluggable::Object
Cylon Toaster
cylontoaster at gmx.de
Wed Oct 5 14:42:02 GMT 2011
Hello,
in the book 'Guide to Catalyst' is described how to build a Driver Model
using Module::Pluggable::Object.
You can find it on page 88, chapter 'A Driver Model for Generic
Translation'.
All works fine :-)
But now I wanted to implement ACCEPT_CONTEXT, which always worked fine
in 'normal' Models.
But when using 'Module::Pluggable::Object' and 'Class::MOP::load_class'
the ACCEPT_CONTEXT-method is not invoked.
I'm not a Perl-Guru, so anybody can tell me how I could accomplish this?
It must have something to do with this driver-model, because when
calling one of the loaded classes directly out of the controller, all
works fine.
Here's a small excerpt of my code:
sub _build_collectors {
my ($self) =@_;
my $base = __PACKAGE__.'::Driver';
my $mp = Module::Pluggable::Object->new(
search_path => [ $base ]
);
my @classes = $mp->plugins;
my %collectors;
foreach my $class (@classes) {
Class::MOP::load_class($class);
unless ($class->does(OccSumDriver)) {
confess "Class ${class} in ${base}:: namespace
does not implement Collection-Driver-Interface";
}
(my $name = $class) =~ s/^\Q${base}::\E//;
$collectors{$name} = $class->new;
}
return \%collectors;
}
one of the loaded classes:
__PACKAGE__ ->mk_accessors(qw|context|);
sub ACCEPT_CONTEXT {
my ($self, $c, @args) = @_;
$self->context($c);
return $self;
}
...
sub collect {
my ($self, $arg_ref) = @_;
return$self->context->model('DB::Nodes')->search({
node_status => 'active',
});
}
thank u in advance,
andy
More information about the Catalyst
mailing list