> You didn't answer my question about package vars though, which is one of the potential issues with using closures:

I read your post 3 times and I couldn't find a question about package vars. neither "our" nor "package"

Package vars are actually easier to handle than lexicals, that's why it's not included in the first demo.

PadWalker::peek_our and local are all you need.

Though I haven't thought it thru yet.

> if you don't know that this is what happens, you don't understand that you only have to use lexicals (assuming your code doesn't work with package vars).

with "if you" you mean "if one" or "me" ? (English is confusing sometimes)

> Also, what would the following do, search for Eily twice or work as intended?

Search "Eily" twice is intended, prepare statements are meant to speed up repeated execution, i.e. $username is normally set inside a loop.

for (qw/Lanx Eily/) { $username = $_; $req1->xexecute(); $req2->xexecute(); }

You could also use a DBI::do otherwise which prepares and executes in one run.

Or one could also provide a prepare which stores the variables at preparation time, if really needed.

Again, I didn't have time to think about the best API, because DBI is vast and allows plenty of approaches.

> If they work as intended

Hmm I think DBI doesn't work like you intend it to

> the main issue might be package vars

I don't see a difference.

> my %vars = (rank => 'Pope', xp => 4);

well I could also allow that bound variables are overriden if xexecute gets arguments. (not sure if that's what you mean)

$req1->xexecute(username=>'value');

main issue

Look my main problem is that I want to inspect into interpolation in a sane way, that's why I inspect the closed over variables inside an anonymous sub and replace them.

Like this I don't need to write a SQL parser to find variables in strings. (the same technique can be used for other kind of embedded string DSL languages)

This placeholder{"string"} function is analysing the interpolation and

I have full flexibility to implement any wanted (your "intention") behaviour then.

The real problem is to identify the use cases and to find the right names for the methods.

update

but you are raising good points, thanks! :)

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery


In reply to Re^4: RFC: Placeholder creation for SQL statements by LanX
in thread RFC: Placeholder creation for SQL statements by LanX

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.