[Dbix-class] transaction in a resultset class

shawn wilson ag4ve.us at gmail.com
Thu Apr 11 16:06:24 GMT 2013


On Thu, Apr 11, 2013 at 12:03 PM, shawn wilson <ag4ve.us at gmail.com> wrote:
> On Thu, Apr 11, 2013 at 11:28 AM, Peter Rabbitson <rabbit+dbic at rabbit.us> wrote:
>> On Thu, Apr 11, 2013 at 10:58:50AM -0400, shawn wilson wrote:
>>> Since txn_* is a part of the schema, how do I have a resultset method
>>> always run within one transaction without passing $schema (which just
>>> seems kludgy)? Since I can't find anything on google about doing this,
>>> I'm guessing it's a bad idea or there's some obviousness I'm missing?
>>
>> First
>>
>> http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/ResultSet.pm#result_source
>>
>> And then
>>
>> http://search.cpan.org/~ribasushi/DBIx-Class-0.08210/lib/DBIx/Class/ResultSource.pm#schema
>>
>
> I don't understand. I've got this resultset class:
>
> package DB::Schema::ResultSet::Page;
>
> use strict;
> use warnings;
>
> use base 'DBIx::Class::ResultSet';
>
> sub insert_page_array_ref
> {
>   my ($self, $pages) = @_;
>
>   foreach my $page (@$pages)
>   {
>         next unless $page =~
> m|^https?://(?:[\w]+\.)(?:\.?[\w]{2,})+(:[0-9]+)?(?:/[^/]+)+$|;
>     $self->create({
>       url   => $page,
>       stamp => time,
>     });
>   }
> }
>
> 1;
>
> How do I wrap that in say a $schema->txn_do(sub{ ... }); ?

Err, not sure if that was stated that well - how would I write something like:

    $schema->txn_do(sub{
      $self->create({
        url   => $page,
        stamp => time,
      });
    });



More information about the DBIx-Class mailing list