1) Because

transaction $bdh => code{ ... }
reads better than
transaction $bdh, sub { ... }
. That's the only reason.

2) Well, it may contain the filename&linenumber of the original error message, but not of the place where the transaction ends and where therefore it's commited or rolled back. I think it makes more sense to append the position of the closing brace of the transaction block than some line within Transaction.pm. Try to throw an exception within a second level transaction. You'll end up with something like:

Some error commit not safe after errors, transaction rolled back at Transactions. +pm line 123 commit not safe after errors, transaction rolled back at Transactions. +pm line 123
Not very helpfull I'd think :-)

Here is the script I used to test my version of the module:

use Transactions; package Foo; sub begin_work { my $self = shift(); print "CALL begin_work on $self->{name}\n"; } sub rollback { my $self = shift(); print "CALL rollback on $self->{name}\n"; } sub commit { my $self = shift(); print "CALL commit on $self->{name}\n"; } sub new { bless {name => $_[1]}, $_[0]; } package main; $foo = new Foo 'jenda'; $foo1 = new Foo 'pavel'; $foo2 = new Foo 'martin'; #eval { transaction $foo => code{ print "Start of the outer transaction\n"; # die "Some error\n"; # eval { transaction [$foo1, $foo2] => code{ print "Start of the inner transaction\n"; die "Some error\n"; print "End of the inner transaction\n"; }; # }; # if ($@) {print "Error in inner trans: $@\nIGNORING!!!\n"}; # die "Some error\n"; print "End of the outer transaction\n"; }; #}; transaction $foo => code{ print "Start of the outer transaction\n"; print "End of the outer transaction\n"; };

Jenda
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
   -- Rick Osborne

Edit by castaway: Closed small tag in signature


In reply to Re: Re: Re: RFC: Transactions.pm by Jenda
in thread RFC: Transactions.pm by Juerd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.