Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.
There are plenty of ways in Perl for the source code of a package to not match the "in memory" version of that code. Usually this is not a problem, but when it causes bugs, it can be very frustrating to debug. Here's one time where it caused me to waste over an hour of debugging:
use Test::More 'no_plan';
BEGIN {
use_ok 'Some::Package';
}
# many tests
ok foo($x), '... and foo($x) should return true';
What happened was that the use_ok failed, but since I forgot to put an or die modifier after it, I didn't notice that the use statement failed. Many tests scrolled past and I couldn't figure out why my final test was failing.
This can fail when you try to do something like this:
eval "use Some::Package";
my $object = Some::Package->new;
If we forget to check whether or not the eval succeeded, Perl attempts to compile the code and gives up when it can't. This can leave you with what is effectively a partially compiled namespace and strange bugs abound (I was getting a segfault).
To find out if what's in memory matches what you think it should be, I'm writing Devel::Recreate:
use Devel::Recreate 'recreate';
print recreate('Some::Package');
Due to the dynamic nature of Perl, this is very tough to do. Also, strange bugs have been cropping up (some of which I know are fixed in 5.9). Currently, I have it listing the variables defined and the subroutines defined. Now I'm working on the use and require statements. It should probably always be considered experimental as there are too many corner cases I don't know how to work out. I haven't figured out how to capture code outside of subroutines. BEGIN, END, INIT and CHECK blocks don't seem to be coverable (they're not really subroutines), and I can't distinguish between fully qualified package variables and variables declared with our.
All things considered, I'm not sure if this code will be useful or not, but it's an interesting tour of strange bits of Perl.
Perl_(begin|check|init|end)av[] (Score:1)
There might not be an array for UNITCHECK.
Manip::END lets you muck with END blocks from perl-space. There's another one which does other blocks but I forget its name.
Re: (Score:2)
Aw, crap. My XS skills are week. However, the code itself doesn't look too difficult. I'll play with it. Right now it appears to work, but the code itself isn't too useful because of the 'naked' code reference:
That produces:
Re: (Score:1)
It's the return value of the
printin theENDblock, isn't it?Re: (Score:2)
D'oh!
Naming (Score:1)
What’s next? Devel::KickBack? Devel::R’and’R?
Re: (Score:2)
Next is Devel::Procreate :)
For the record, I hate the Devel::Recreate namespace. Suggestions welcome.
Hmmm... (Score:1)
For most cases, a module similar to Apache::Reload is right. Put in a check for which modules have changed on disk since you loaded them, then reload them.
That doesn't help you in the case you have. But it is easy to create a module that redefines use and require. If you try to use
Re: (Score:2)
The above example is only one of many. If a module is not behaving the way I expect it to, particularly if "deep magic" is involved, than it's quite reasonable for me to want to see what's actually loaded in memory instead of what I think was loaded. Just a few areas where this would be helpful:
Re: (Score:1)
Carry on. :-)
Re: (Score:2)
Yes, I'm convinced that my module could only be used as a rough debugging guide. There are too many limitations that I cannot figure out how to get around, so it should probably only be a tool that developers can use if they read the docs carefully and really understand what its limitations are.
Re: (Score:1)
Actually I don’t think it is a bad idea at all. You are right that this is not applicable in all cases in Perl because Perl was not designed to facilitate such usage. However, think Smalltalk, where a lot of “magic” is no problem because what you are browsing is the live in-memory representation of the program and so you see what it looks like after the meta-program parts have taken place.
This is just the same thing for Perl. Of course it’s not going to work nearly as well in Perl