[Catalyst] Handling Exceptions
Matt S Trout
dbix-class at trout.me.uk
Sun Apr 16 20:58:47 CEST 2006
Kiefer, Sascha wrote:
> Okay.
> But then, i have to do the rollback myself, right?
>
> my $model = $c->model('DBIC::PbUser');
> my $create_user = sub {
> my $user =
> $model->create(
> { username => $username, password => $csh->generate } );
> $user->create_related( 'profile', { email => $emailaddr } );
> die "Just for testing";
> $user->create_related( 'settings',
> { registerDate => DateTime->now } );
> };
>
> my $rs;
> eval { $rs = $model->schema_instance-> txn_do($create_user); };
> if ($@) {
> # ...
> }
>
> And now, i have a new in entry in my user and in my user_profile table.
It should roll back automatically - c.f.
http://search.cpan.org/src/JROBINSON/DBIx-Class-0.06001/t/run/21transactions.tl
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Catalyst
mailing list