New version of Catalyst

Ovid on 2006-02-21T18:41:07

A new version of Catalyst was released today. Amongst other things it fixed a problem I had with plugins. Basically, a plugin name pretty much had to start with Catalyst::Plugin::. If you wrote My::Plugin::DoesTheDishes, how do you get Catalyst to recognize that?

Well, there are a few ways. You could write a wrapper whose name starts with Catalyst::Plugin:: and redispatches to your plugin. That's kind of ugly. You could also inherit directly from the plugin, but that's ugly, too. You could also use a MyApp->plugin($name, $plugin); which is fairly clean, but appears to deny the plugin access to request phases.

In short, there are a whole bunch of different ways to do something subtly wrong. I want one to do the right thing. How are plugins normally loaded?

use Catalyst qw(
    DateTime
    Static::Simple
);

Of course, those are really Catalyst::Plugin::DateTime and Catalyst::Plugin::Static::Simple. I want, as much as possible, to drive all plugin creation through the same process. That way, if we change how plugins are used (eliminate MI, please!), then we have one spot to do it. So I committed a patch which lets you do this:

use Catalyst qw(
    DateTime
    Static::Simple
    +Fully::Qualified::Plugin::Name
);

That might not seem like that big of a deal, but the immediate payoff came when I wrote the tests. I needed to know which plugins were loaded and in Catalyst, there was no correct way of doing that. With the above patch, you get a bit of introspection:

foreach my @plugin ($c->registered_plugins) { 
  ...
}

if ($c->registered_plugins('Static::Simple')) {
  ...
}

if ($c->registered_plugins('Catalyst::Plugin::Static::Simple')) {
  ...
}

I have a slight reservation about allowing non-fully-qualified plugin names (e.g., "Static::Simple") to be used with this method, but since those are how most folks see the names, it felt more consistent.


Why?

sigzero on 2006-02-21T23:36:09

I am curious why you wouldn't want to keep it in the "Catalyst::plugin::" naming convention? Isn't that what naming conventions are for?

Re:Why?

Ovid on 2006-02-22T00:00:31

Let's say I create MyApp::Plugin::Foo. People can install that and there's no danger that someone else will create a Catalyst::Plugin::Foo which will conflict with that. In fact, they could use both at the same time:

use Catalyst qw(Foo +MyApp::Plugin::Foo);