Here are two ways of doing the same thing with txn_do():

  my $author = $schema->resultset('Author');
  my @titles = qw/Night Day It/;

  # 1: giving a closure to txn_do()
  $schema->txn_do(
    sub {
      $author->create_related('books', {
        title => $_
      }) for @titles;
    };
  );

  # 2: giving a code ref together with all external variables
  $rs = $schema->txn_do(
    sub {
      my ($author, $titles) = @_;
      $author->create_related('books', {
        title => $_
      }) for @$titles;
    }, $author, \...@titles
  );

Does it make any difference?
Is there a recommended way of doing it (better use or avoid closure)?

Bernhard Graf

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to