[Catalyst] The model -is- where your business logic lives.

Ian Docherty catalyst at iandocherty.com
Thu Sep 27 11:51:26 GMT 2007


In a previous thread, Matt S Trout said.

>The model -is- where your business logic lives.
>
>The real question is whether your ORM should be directly in the model or
>not, but that's a whole different thread.

Based on this I have the following simple code.

####
package MyApp::Model::DBIC;

use strict;
use base qw(Catalyst::Model::DBIC::Schema);

####
package MyApp::Schema::Demo;

use base qw(DBIx::Class);

__PACKAGE__->load_components(qw(PK::Auto Core));
__PACKAGE__->table('demo');
__PACKAGE__->add_columns(qw(id name state));
__PACKAGE__->set_primary_key('id');


####
package MyApp::Model::DBIC::Demo;

sub do_some_business_logic_stuff {
    my ($self) = @_;

    if (<some complicated business logic>) {
        $self->state('pending');
        $self->update;
    }
}   


#### somewhere in my application

$demo = $c->model('DBIC::Demo')->find($index);
$demo->do_some_business_logic_stuff;

-------------

Is this a standard/typical/best-practice way to do this sort of thing? 

It seems to me that if I want to use the business logic in an external application (cronjob) then I am having to use the MyApp::Model::DBIC::Demo namespace as decreed by Catalyst (not that this is a big issue).

Regards
Ian





More information about the Catalyst mailing list