Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Help seperating business logic from controller (catalyst/dbic)

by uG (Scribe)
on Sep 10, 2008 at 04:46 UTC ( #710261=note: print w/ replies, xml ) Need Help??


in reply to Help seperating business logic from controller (catalyst/dbic)

Thanks to the advice I have received, I have made the following modifications which I will include for future reference to anyone who may have had the same questions as me... thanks dhoss and perrin!

Controller

sub create :Local{ my ( $self, $c ) = @_; my $nation = $c->request->params->{nation}; #Action Logic; Form was submitted, lets create then #Check to see if the nation name already exists #UPDATED: create method overloaded to return 0 if #nation name exists if($nation) { if($c->user->nations->create({ name => $nation, owner => $c->user->get('id'), map_nation_resource => [ { resour +ce_id => 1 }, { resource_id => 2 } ], })){ $c->redirect($c->uri_for('/nation')); } else { $c->stash->{error_msg} = "Nation name already taken!"; } } return $c->stash->{template} = 'nation/create.tt2'; }

ResultSet subclass
package Game::DB::ResultSet::Nation; use strict; use warnings; use base 'DBIx::Class::ResultSet'; #Override nation's create method to check if nation name exists #Before creating. If it does, return 0 sub create { my $self = shift; my $nation) = shift; if($self->find( {name => $nation->{name}} ) ) { return 0; } $self->next::method($nation); } 1;


Comment on Re: Help seperating business logic from controller (catalyst/dbic)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://710261]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-09-17 00:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (55 votes), past polls