Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I'm glad that PadWalker is getting so much use all of a sudden! But you're right that this isn't very robust. (If the sub has other lexical variables with the same names, you could get the wrong one. And some improvements in the latest beta actually make it *more* likely that you'd get the wrong one, sad to say.)

    This is the second module in a week that has used PadWalker as a way of finding out the names of the variables that are passed to a function. I should probably make a robust way of doing that and ad
    • But you're right that this isn't very robust. (If the sub has other lexical variables with the same names, you could get the wrong one. And some improvements in the latest beta actually make it *more* likely that you'd get the wrong one, sad to say.)

      Thankfully it is a little more robust than that - instead of assigning to the hash returned by PadWalker that hash is used as a reference to map parameters (i.e the lexicals passed to MAPARGS) to the named arguments. Simply assigning to the returned hash c

      --

      broquaint out

      • I did look at the code, and I grok what it's doing (which is very cool). What I mean is that:

        use Params::Named;
        sub ick {
            MAPARGS \my($foo, $bar);
            print "Foo = $foo\n";
            {my $foo}
        }

        ick(foo => 23)

        will give the spurious error The parameter '$foo' doesn't match argument type 'SCALAR'.

        The problem, of course, is that sub ick has more than one lexical called 'foo', and in this case peek_sub is returning the wrong one, so you don't

        • by broquaint (2964) on 2005.10.13 4:17 (#43863) Journal
          Ack! You're quite right :/ How about a patch to PadWalker [cpan.org] which adds another magical sub that returns a more detailed data structure than a flat hash, or some such? My XS is non-existant but how hard can it be, right? A reverse peek would be handy but my limited knowledge of perl's internals leads me to believe it'd involve something genuinely mad like adding debugging info to the optree. Which would be nice :)
          --

          broquaint out

          • Check out the latest PadWalker beta [man.ac.uk], which has a new function called var_name.

            Using that, you should also be able to make your module work from anonymous subs (which I assume it doesn't, at the moment).