> 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
- returns an object with methods
- know the references of the interpolated variables
- know the names of the interpolated variables
- know the values of the variables at interpolation time
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! :)
|