in reply to •Re: How to prevent references from stringifying?
in thread How to prevent references from stringifying?
If you s/Perl_croak/Perl_warner/ in the patches above then you can make it a warning, rather than a fatal. Then you can install a signal handler to deal with it as desired. Nothing should break, although things might get a bit noisy.
Perl_warner( aTHX_ WARN_SYNTAX, "Stringified reference\n" ); /* or you could make references REALLY strict ;-) */ if ( PL_hints & HINT_STRICT_REFS ) Perl_croak( aTHX_ "Stringification of reference disallowed\n" );
It looks like it is pretty easy to add a new item to strict as well. *Untested* there appear to be only 3 modifications required. The PL_hints var contains a number of hints set at compile/runtime. The hints are accessed via HINT_ constants set in perl.h There are plenty of spare mask bits. 0x04 is documented as unused so you could
/* in perl.h with the rest of the HINT_ defines */ + #define HINT_STRICT_STRINGIFY 0x00000004 /* in sv.c as noted by xmath */ + if ( PL_Hints & HINT_STRICT_STRINGIFY ) + Perl_croak(aTHX_ "Stringification of reference disallowed"); # in strict.pm my %bitmask = ( + stringify => 0x00000004, refs => 0x00000002, subs => 0x00000200, vars => 0x00000400 ); sub bits { my $bits = 0; foreach my $s (@_){ $bits |= $bitmask{$s} || 0; }; $bits; } sub import { shift; - $^H |= bits(@_ ? @_ : qw(refs subs vars)); + $^H |= bits(@_ ? @_ : qw(refs subs vars stringify)); } sub unimport { shift; - $^H &= ~ bits(@_ ? @_ : qw(refs subs vars)); + $^H &= ~ bits(@_ ? @_ : qw(refs subs vars stringify)); }
As you can see you could leave strict alone and just doe $^H |= 0x00000004 to set it.
cheers
tachyon
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: How to prevent references from stringifying?
by xmath (Hermit) on Oct 04, 2004 at 07:49 UTC | |
by tachyon (Chancellor) on Oct 04, 2004 at 12:49 UTC | |
by xmath (Hermit) on Oct 05, 2004 at 05:40 UTC |