in reply to Validating a Code Reference

This is a very interesting question, and I'd love to see an answers/solution from someone. I can't really provide an answer myself, but after thinking about it a bit, I'm not sure that this is going to be possible.

Think of anonymous subs, for example:

printf "%s\n", sub { "foo" };
That prints out
CODE(0x45f73b0)
The tricky thing that I'm pointing out here is that you certainly couldn't "look up" an anonymous sub to ensure that it exists; but the code reference looks just like a reference to a named subroutine, and if you do
my $type = ref $sub;
you'll get "CODE" either way. In other words, a reference to an anonymous sub looks just like a reference to a named sub; and if you can't look up one then you may not be able to look up the other. :)

The only "solution" really may be to try and run the sub. I guess the problem here is that the only way of dereferencing a code reference is to *run* it; and that's what you want to avoid. But if that's the only way, then... anyway.

I hope to see some more encouraging answers, though.