[Catalyst] Creating a thin Model
Jamie Neil
jamie at versado.net
Mon May 21 11:06:44 GMT 2007
Christopher H. Laco wrote:
>> Personally, I almost always do:
>>
>> sub COMPONENT {
>> my $self = NEXT::new
>>
>> diddle config...return $self
>> }
>>
>
> Sorry...that pseudo code was too vague:
>
>
> sub COMPONENT {
> my $self = shift->NEW::new(@_);
> $self->{'noncatclass'} = NonCatClass->new
> return $self
> }
>
> Then, delegate via autoload, or use real methods to forward request to
> the instance of the real class...
I assume you mean:
my $self = shift->NEXT::new(@_);
in which case it fails with:
Can't call NEXT::new from MyApp::Model::Widget::COMPONENT
I noticed that a number of newer models on CPAN were using this
construction:
use base qw/ Catalyst::Model /;
sub new {
my $self = shift->next::method(@_);
my $class = ref($self);
my ( $c, $args ) = @_;
$self->{'.mymodel'} = ExternalModule->new(
Catalyst::Utils::merge_hashes( $args, $self->config )
);
return $self;
}
sub ACCEPT_CONTEXT {
return shift->{'.mymodel'};
}
or is this only recommended if you need to make the context available in
the external module?
--
Jamie Neil | <jamie at versado.net> | 0870 7777 454
Versado I.T. Services Ltd. | http://versado.net/ | 0845 450 1254
More information about the Catalyst
mailing list