in reply to URI Inheritence
Many programs out there already rely on being able to use a URI::URL object as a scalar… ie. 'print if $uri =~ /pdf\s+$/;’ Is there any way to control the value returned when an object is used in a scalar context?
You can overload the "" (stringification) operation:
package Pkg; use overload '""' => sub { "[[[" . $_[0]->{val} . "]]]" }; package Main; my $x = { val => '10' }; bless $x, Pkg; print $x; # [[[10]]]
|
|---|