[Dbix-class] Overriding create(), txn_do, and 'No next::method' from Class::C3

Brandon Black blblack at gmail.com
Tue Jul 10 21:21:20 GMT 2007


On 7/10/07, Pedro Melo <melo at simplicidade.org> 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);
   });
}



More information about the Dbix-class mailing list