Difference between revisions of "Catalyst"
From Leaky
(Start page) |
(No difference)
|
Revision as of 14:44, 24 March 2016
Creating a model
This generates an interface for Catalyst to a 'MyApp::Item' object and passes all methods through to the object. The example merely passes a 'datadir' attribute on the object that contains the full path to the "data" directory within the application root.
package MyApp::Model::Item;
use strict;
use warnings;
use base 'Catalyst::Model';
use MyApp::Item;
use Moose;
our $AUTOLOAD;
has 'Instance' => (
is => 'rw',
isa => 'MyApp::Item',
);
__PACKAGE__->config( class => 'MyApp::Item' );
sub COMPONENT {
my ($self, $app) = @_;
return MyApp::Item->new( datadir => $app->path_to("data") );
}
sub AUTOLOAD {
my $self = shift;
my $name = $AUTOLOAD;
$name =~ s/.*://;
$self->Instance->$name(@_);
}
1;