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


In reply to Re^2: How to prevent references from stringifying? by tachyon
in thread How to prevent references from stringifying? by diotalevi

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.