Hi,

On Jul 10, 2007, at 9:21 PM, Brandon Black wrote:

On 7/10/07, Pedro Melo <[EMAIL PROTECTED]> wrote:
Hi,

I'm trying to override create() on a ResultSet subclass. Inside I
defined a create() method.

The simplest create I could find that triggers the error is this:

package S::BaseResultSet;

use strict;
use base qw( DBIx::Class::ResultSet );
use Class::C3;

sub create {
   my $self = shift;

   $self->result_source->schema->txn_do( sub {

      # do something here about logging

      $new_record = $self->next::method($values);
   });

   return $new_record;
}

The problem is that the next::method inside the closure will search
for the next method of the txn_do and not of the create call().

Any tips on how to go about this? For now, I replaced the txn_do with
txn_begin/commit/rollback, but my quick hack is not as good as the
txn_do inside DBIC::Storage::DBI...

Thanks in advance,

One way to accomplish this is to grab the next::method coderef before
jumping into the txn_do coderef, like:

sub create {
   my $self = shift;

  my $next_method = $self->next::can;

  $self->result_source->schema->txn_do(sub {
      # yadda yadda
     $next_method->($values);
  });
}

Thanks, I misses the next::can from the docs.

Best regards,
--
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: [EMAIL PROTECTED]
Use XMPP!



_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/dbix-class@lists.rawmode.org/

Reply via email to