Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
how can I access code ref contents, not call it?by knight (Friar) |
on Jan 04, 2001 at 04:37 UTC ( [id://49659]=perlquestion: print w/replies, xml ) | Need Help?? |
knight has asked for the wisdom of the Perl Monks concerning the following question:
This is definitely off the beaten track,
so it'll probably help if I start with why
I want to do something this screwy.
I'm extending Cons, a Perl-based substitute for Make, to support generating a target file by calling a Perl code ref instead of an external command. Cons will rebuild a target file if the file's build command changes. Cons tracks this by adding the command line into an MD5 signature for the target file. If the command line changes, the signature changes and the file gets rebuilt. Ideally, this should work the same for code refs. If the Perl code used to generate a target file changes, the file should get rebuilt. So how do I figure out if the code changed since the last build? What I'd like to do is be able to use the same MD5 signature mechanism on the "contents" of the code ref--maybe, for example, treat the compiled code as a byte string and generate an MD5 signature on that. Something like that would be cleanest for the Cons architecture, but the only things I can figure out to do with a code ref are: Note that I can't use the representation of the memory address itself, because that will likely be different each time Cons is run. If I knew how long the compiled code ended up being, I could theoretically generate the signature on N bytes starting at the supplied address, but I don't see how to do that, either. If there isn't any magic that will let me at the compiled "contents" of a code ref in this way, my workaround will be to use the MD5 signature of the entire config file in which the ref appears. That would have the drawback, though, of forcing anything with a code ref to be rebuilt anytime the config file changes, so I'd be grateful for any suggestions about other ways to try to do this...
Back to
Seekers of Perl Wisdom
|
|