in reply to How do I test the validity of a CODE reference?
(I've not tested this approach beyond the extent provided by the above script.)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{}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do I test the validity of a CODE reference?
by ikegami (Patriarch) on Aug 08, 2008 at 02:24 UTC | |
by syphilis (Archbishop) on Aug 08, 2008 at 03:39 UTC | |
by ikegami (Patriarch) on Aug 08, 2008 at 05:14 UTC | |
by syphilis (Archbishop) on Aug 08, 2008 at 08:33 UTC | |
by ikegami (Patriarch) on Aug 08, 2008 at 20:03 UTC |