Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Re: RFC: Transactions.pm

by Jenda (Abbot)
on Apr 28, 2003 at 13:38 UTC ( [id://253684]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: RFC: Transactions.pm
in thread RFC: Transactions.pm

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

Replies are listed 'Best First'.
Re^4: RFC: Transactions.pm
by Aristotle (Chancellor) on Apr 28, 2003 at 13:48 UTC
    Of course you can write that as
    transaction $dbh => sub { ... };
    as well. You know, thinking about this topic, it occured to me that this is where Perl6 user exposed parsing would allow us to superimpose such features on the language seamlessly, without all the caveats inherent to Perl5 solutions.

    Makeshifts last the longest.

      Yeah I know. It's the sub that looks kinda strange there.

      You are probably right about Perl6. I've tried to read a few Apocalypses&Exegei, but do not remember much. I need something to experiment with to grok such stuff.

      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

      it occured to me that this is where Perl6 user exposed parsing would allow us to superimpose such features on the language seamlessly, without all the caveats inherent to Perl5 solutions.

      You won't have to change the grammar or have a "parsed" trait on an operator. Every block is a closure, so something like this will work:

      multi transaction (Object $object, &block) { ...; block(); ...; }
      transaction $dbh -> { ... }
      (Note: this is probably wrong, but I can't check it since I don't have a working Perl 6 interpreter :)

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://253684]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 21:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found