Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Well, personally, I would just put it under DBIx::Transaction. It's just a syntactic sugar module, and doesn't actually implement any kind of transactions. Calling it Transactions could be misleading to people.

I'm open to suggestions, but not to DBIx::. This module has a much wider scope. Currently, I know of no other modules that use begin_work, rollback and commit, but in theory any transaction capable module could be used with this.

This sample code doesn't actually work, does it? The use transactions part would be executed at compile time before $dbh has a value.

That's correct. I tested without a database, and was lazy so I supplied a string literal. I thought it was possible to reference the container instead of the value, but I was wrong. No, the module doesn't work.

If you only pass in $dbh at compile time (because it's done with a use), the $dbh inside transactions will never get updated.

That will have to be changed.

Defining your subs inline like that looks pretty strange.

That's because they're closures that share the same $dbh. Kind of useless if you consider that $dbh is a reference to undef, but I didn't know that at that time.

I don't think you need to take a reference to $_1, since it is a ref already.

That was because it was used in other subs, which have @_'s of their own. Needed to reference to avoid copying.

Creating a routine that takes sub refs but does not appear to (like transaction()) leads to many scoping bugs.

I will document that. Sourcefilters are an ugly solution. I'd rather introduce one very obvious bug than lots of subtle parsing bugs.

Maybe I'll make the module OO after all, but I think this looks ugly:

my $t = Transaction->new($dbh); $t->transaction(sub { for (1..10) { my $sth = $dbh->prepare(...); $sth->execute() or $t->rollback; } });
Or I can just have a function called transaction_select (lots of typing - better names welcome)
transaction_select $dbh; transaction { for (1..10) { my $sth = $dbh->prepare(...); $sth->execute() or rollback; } };
One thing's for sure: the module as pasted in this thread's root node does not work and needs to be fixed. Thanks for pointing that out.

Update: new version, with working code. I thought the OO solution was way too ugly and I didn't like transaction_select either. I decided to use a package global $T instead.

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


In reply to Re: Re: RFC: transactions.pm by Juerd
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-25 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found