Catalyst Tip: Don't pollute!
Currently, your "MyApp.pm" file is both your application class and your context class (NB: this is expected to change in 5.8000). We've been slowing suggesting that people move things out of th context/app class so as not to pollute it with an abundance of mehods which may occasionally have unwanted consequences -- for example "login : Global {}" conflicting with the Authentication plugin's login() method.
This tip is broken into two parts:
- It's been said time and time again (c.f. this and this [phaylon++]), not everthing has to be a plugin! If the sum total of your plugin is this:
You should reconsider. Either use the module directly, or make a controller base class. That should handle most cases.package Catalyst::Plugin::Foo;
use Foo;
sub foo {
my( $c, @rest ) = @_;
return Foo->new( @rest );
} - Be careful what you import into MyApp.pm! Some modules will export methods (and other symbols) by default, and sometimes you'll do it manually. Consider explicitly importing nothing:
before:
after:package MyApp;
use Digest::MD5 qw(md5_hex); # MyApp now has the md5_hex method
sub foo {
# ...
return md5_hex( $string );
}
If you want a quick-n-easy cleanup, try namespace::clean.package MyApp;
use Digest::MD5 (); # no imports
sub foo {
# ...
return Digest::MD5::md5_hex( $string );
}