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



_______________________________________________
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/

Reply via email to