Skip Menu |

This queue is for tickets about the MooseX-Object-Pluggable CPAN distribution.

Report information
The Basics
Id: 29645
Status: open
Priority: 0/
Queue: MooseX-Object-Pluggable

People
Owner: Nobody in particular
Requestors: jjn1056 [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Allow plugins to be installed at instantiation
Hi, Thanks for the releasing this module, since I use it quite a bit and it has helped to make my code better. One thing that I personally do often is want to be able to load plugins at instantiation time. For example, I often want: my $decorated = MyDecorator->new({ wraps=>$object, plugins=>[qw/Autoload/]); So that the $decorated object already loads some plugins. I want this often enough that I created a role that does: has 'plugins' => ( is=>'rw', isa=>'ArrayRef', auto_deref=>1, trigger=>sub { my ($self) = @_; foreach my $plugin ($self->plugins) { $self->load_plugin($plugin); } }, ); To support the above. If you think a feature like this is valuable I'd be happy to fix it up with some tests and submit you a patch. I'd also appreciate your feedback about the feature and what could make it better. I understand your concern about polluting the caller's namespace, for example. Thanks! John Napiorkowski
On 2007-09-27 14:24:18, jjn1056@yahoo.com wrote: Show quoted text
> Hi, > > Thanks for the releasing this module, since I use it quite a bit and it > has helped to make my code better. One thing that I personally do often > is want to be able to load plugins at instantiation time.
Just thinking out loud here... One should be able to say: Foo->load_plugin('blah') and have it still work. We'd need load_plugin() to not just return boolean success, but also the modified class name (it needs to be a new class name, so when you instantiate it you use the new metaclass, with the role applied). Also, _plugin_ns needs to be callable on a bare class name, so it can no longer be a regular attribute, and we need somewhere to store (on the metaclass?) a list of plugins that have already been loaded, so we can combine this with plugins applied to an instance of this new class. You might be better off simply doing Moose::Util::apply_all_roles($applicant, @roles)? I don't see a nice way of shoehorning this into the existing Pluggable API. Thoughts, anyone?