I've gone about it this way, and although the business logic is not within Catalyst, somehow, what I've done doesn't feel right.<br><br>In myapp_server.pl I've had to add a few paths to @INC<br>use lib "/home/anthony/devel/lib";<br>use lib "/home/anthony/devel/lib/Test"<br><br>For my business layout I have ...<br><br>~/devel/lib/Test/TestSchema.pm<br>~/devel/lib/Test/TestSchema/UserProfile.pm<br>~/devel/lib/Test/Model/UserProfile.pm (see snippet two)<br>~/devel/lib/Test/Model/Base.pm (see snippet three)<br><br>Then I have for Catalyst<br><br>~/dev/websites/MyApp/lib/MyApp/Model/UserProfile.pm (see snippet one)<br><br>########### (snippet one)<br><br>package MyApp::Model::UserProfile;<br><br>use strict;<br>use base 'Catalyst::Model::DBIC::Schema';<br><br>use Test::Model::UserProfile;<br><br>__PACKAGE__->config(<br> schema_class => 'Test::TroveSchema',<br> connect_info => [<br>
'dbi:SQLite:db/test.db',<br> '',<br> '',<br><br> ],<br>);<br><br>sub new {<br> my $class = shift;<br> my $c = shift;<br> my $args = shift;<br><br> my $merged_args = Catalyst::Utils::merge_hashes( $args, $class->config() );<br> return Test::Model::UserProfile->new( $merged_args );<br><br>}<br><br>######################## (snippet two)<br><br><br>package Test::Model::UserProfile;<br><br>use strict;<br><br>use base 'Test::Model::Base';<br><br><methods><br><br>################## (snippet three)<br><br>package Test::Model::Base;<br><br>use base 'Class::Accessor';<br><br>use Carp;<br><br>use Test::TroveSchema;<br><br><br>__PACKAGE__->mk_accessors(qw|schema|);<br><br>sub new {<br> my $class = shift;<br> my $self = $class->next::method(@_);<br><br> croak "->connect_info must be defined" unless(
$self->{connect_info} );<br><br> $self->{schema} = Test::TroveSchema->connect( @{ $self->{connect_info} } );<br><br> $self<br>}<br><br>sub find {<br> my $self = shift;<br> my $id = shift;<br><br> my $calling_pkg = (caller(0))[0];<br> $calling_pkg =~ s|(.*)::(.*)$|$2|;<br><br> return $self->{'schema'}->resultset($calling_pkg)->find($id);<br>}<br><br>Now, what seems wrong to me is that I've had to write new() methods and also, for example, a find() method which is in Test::Model::Base. This doesn't seem right to me.I would've thought I would have all of DBIC's utils available to me without having to recall them.<br><br>Can anyone offer pointers?<br><br>Many thanks<br><br>-Ants<br><br><b><i>Matt S Trout <dbix-class@trout.me.uk></i></b> wrote:<blockquote class="replbq" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"> On Thu, Sep 27, 2007 at 11:51:26AM +0100, Ian Docherty
wrote:<br>> In a previous thread, Matt S Trout said.<br>> <br>> >The model -is- where your business logic lives.<br>> ><br>> >The real question is whether your ORM should be directly in the model or<br>> >not, but that's a whole different thread.<br>> <br>> Based on this I have the following simple code.<br>> <br>> ####<br>> package MyApp::Model::DBIC;<br>> <br>> use strict;<br>> use base qw(Catalyst::Model::DBIC::Schema);<br>> <br>> ####<br>> package MyApp::Schema::Demo;<br>> <br>> use base qw(DBIx::Class);<br>> <br>> __PACKAGE__->load_components(qw(PK::Auto Core));<br>> __PACKAGE__->table('demo');<br>> __PACKAGE__->add_columns(qw(id name state));<br>> __PACKAGE__->set_primary_key('id');<br>> <br>> <br>> ####<br>> package MyApp::Model::DBIC::Demo;<br><br>Put this code in MyApp::Schema::Demo.<br><br>I often call it e.g. MyApp::DataStore or MyApp::Domain to remind me
that<br>it's the business layer and the DBIC-ness is merely incidental.<br> <br>> sub do_some_business_logic_stuff {<br>> my ($self) = @_;<br>> <br>> if (<some complicated="" business="" logic="">) {<br>> $self->state('pending');<br>> $self->update;<br>> }<br>> } <br>> <br>> <br>> #### somewhere in my application<br>> <br>> $demo = $c->model('DBIC::Demo')->find($index);<br>> $demo->do_some_business_logic_stuff;<br>> <br>> -------------<br>> <br>> Is this a standard/typical/best-practice way to do this sort of thing? <br>> <br>> It seems to me that if I want to use the business logic in an external <br>> application (cronjob) then I am having to use the MyApp::Model::DBIC::Demo <br>> namespace as decreed by Catalyst (not that this is a big issue).<br><br>Having moved the logic out of MyApp::Model:: this ceases to be an issue.<br><br>Don't confuse class -names- with the
nature of classes. MyApp::Model:: is<br>*adapters* that make a model available to MyApp, not where your domain model<br>logic itself should live.<br><br>I usually these days have MyApp::Web for the catalyst app instead of MyApp so<br>I can deploy things like MyApp::DataStore from a separate dir tree.<br><br>-- <br> Matt S Trout Need help with your Catalyst or DBIx::Class project?<br> Technical Director http://www.shadowcat.co.uk/catalyst/<br> Shadowcat Systems Ltd. Want a managed development or deployment platform?<br>http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/<br><br>_______________________________________________<br>List: Catalyst@lists.rawmode.org<br>Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst<br>Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/<br>Dev site: http://dev.catalyst.perl.org/<br></some></blockquote><br><BR><BR>Disclaimer: Technically, I'm always
wrong!!<p> 
<hr size=1>
Yahoo! Answers - Get better answers from someone who knows. <a
href="http://uk.answers.yahoo.com/;_ylc=X3oDMTEydmViNG02BF9TAzIxMTQ3MTcxOTAEc2VjA21haWwEc2xrA3RhZ2xpbmU">Try
it now</a>.