Seems you can also derive the answer by looking at the value of the CvOUTSIDE pointer attached to $sub. I think this will show up as the OUTSIDE value when you do a Devel::Peek::Dump($sub), but to access that value in a useful way from within a program you'll probably need XS/Inline::C:
use warnings; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; SV * validate(CV * coderef) { if(CvOUTSIDE(coderef)) return newSVuv(1); return newSVuv(0); } EOC $cref1 = \&existent; $cref2 = \&non_existent; $foo = 'hello world'; print "\$cref1: ", validate($cref1), "\n"; print "\$cref2: ", validate($cref2), "\n"; print "\$foo: ", validate($foo), "\n"; # Fatal Error sub existent{}
(I've not tested this approach beyond the extent provided by the above script.)

Cheers,
Rob

In reply to Re: How do I test the validity of a CODE reference? by syphilis
in thread How do I test the validity of a CODE reference? by pilap

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.