[Catalyst-dev] Documentation
Brian Cassidy
brian.cassidy at nald.ca
Fri May 12 21:56:13 CEST 2006
Also, as discussed on IRC,
Regarding documentation, if there were such a section on how to write custom
models and views then we should include an important best practice for a
specific situation...
I'm finding it hard to find the right wording but something like
* Creating models and views with a specific base class
Several older models on CPAN have what I call the "multiple-inheritance
new() hack" which looks something like this:
package Catalyst::Model::MyClass;
use base qw( Catalyst::Base MyClass );
sub new {
my( $class, $c, $options ) = @_;
# ...or some variant of the following:
$class->MyClass::new( %{ $class->NEXT::new( $c, $options ) } );
}
See Catalyst::Model::Gedcom 0.02 [1] for an example.
Instead the preferred method would to use COMPONENT(). I can't quite
remember what version introduced it, though.
Here's how it would look:
package Catalyst::Model::MyClass;
use base qw( MyClass );
sub COMPONENT {
my( $class, $c, $config ) = @_;
return $class->new( %$config );
}
See Catalyst::Model::Gedcom 0.03 [2] for an updated example.
Cheers,
-Brian
[1]
http://search.cpan.org/src/BRICAS/Catalyst-Model-Gedcom-0.02/lib/Catalyst/Mo
del/Gedcom.pm
[2]
http://search.cpan.org/src/BRICAS/Catalyst-Model-Gedcom-0.03/lib/Catalyst/Mo
del/Gedcom.pm
More information about the Catalyst-dev
mailing list