Perl’s bignum bigint and bigrat pragmas helpfully contain an in_effect function that will detect if the pragma is loaded into a scope by probing the hints hash. However, this only works in version 5.9.4 and later of perl, since that’s when the lexical hints hash was introduced.
Is there any good way of determining if these pragmas are in effect in earlier versions of perl? For my uses, I would like to support back to version 5.8.8.
Update: mob’s solution below will work if I had access to the lexical space where bignum may be in effect. However, for my use case, I am writing a function that will be called from that space, and inside that function I need to determine if the caller’s scope has bignum loaded. (ie, in my code I am calling something like bignum::in_effect(2) to look a few frames up the call stack)
sub test_sub {is_bignum_in_effect_in_the_caller}
# bignum::in_effect(1) in 5.9.4+
test_sub(); # no bignum
{use bignum; test_sub()} # yes bignum
I don’t know if this qualifies as a ‘good’ way, but you can do a simple operation and see if you are getting the bigint/bigrat result or the conventional Perl result.
At the risk of making this answer even less good, how can you determine whether bigint is enabled in the caller’s scope?
One. Require the caller to tell you whether bignum is enabled.
Two. Source filtering? Hack the op tree? Use either of these methods to insert an argument to the method call or to set a global variable prior to the method call.