stringification - allow or forbid implicitly converting references into strings
stringification
no stringification; my $array = [ 1, 2, 3 ]; print "My array is $array\n"; # dies
Normally in Perl, a reference may be implicitly converted into a string, usually of a form like HASH(0x1234567).
HASH(0x1234567)
This module provides a lexically-scoped pragma which alters the behaviour of the following operations:
"$ref" # stringify $ref . "foo" # concat lc $ref lcfirst $ref uc $ref ucfirst $ref quotemeta $ref $ref =~ m// split //, $ref join $ref, @strs join "", $ref print $ref say $ref
When disabled by no stringification, all of these operations will fail with an exception when invoked on a non-object reference.
no stringification
$ perl -E 'no stringification; my $arr = []; say "Array is $arr"' Attempted to concat a reference at -e line 1.
The effects of this module are lexically scoped; to re-enable stringification of references during a lexical scope, use stringification again.
use stringification
More testing, especially around interoperatbility with other op-hooking modules.
Hook more ops; including
$ref =~ s///; s//$ref/; substr( $ref, 0, 0 ) substr( $str, 0, 0, $ref ) substr( $str, 0, 0 ) = $ref
Consider whether to detect for objects that don't have overload magic, and forbid these too.
A mode where string conversions just give warnings, rather than outright failures.
no stringification 'warn';
Paul Evans <leonerd@leonerd.org.uk>
To install stringification, copy and paste the appropriate command in to your terminal.
cpanm
cpanm stringification
CPAN shell
perl -MCPAN -e shell install stringification
For more information on module installation, please visit the detailed CPAN module installation guide.