[Dbix-class] Overriding create(), txn_do,
and 'No next::method' from Class::C3
Pedro Melo
melo at simplicidade.org
Wed Jul 11 11:48:48 GMT 2007
Hi,
On Jul 10, 2007, at 9:21 PM, Brandon Black wrote:
> 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);
> });
> }
Thanks, I misses the next::can from the docs.
Best regards,
--
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: melo at simplicidade.org
Use XMPP!
More information about the Dbix-class
mailing list