X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Foverload.pm;h=81c859869473d88c2afbf6ebd718ca5727ac452f;hb=3b0db4f96671dacfd3421850abb588b84e2ce6da;hp=715f10a277cb7cb1b0711d524527d43c395da58d;hpb=54f8c77382e6d92f19c4cf5463ad7c86c868a545;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/overload.pm b/lib/overload.pm index 715f10a..81c8598 100644 --- a/lib/overload.pm +++ b/lib/overload.pm @@ -2,7 +2,7 @@ package overload; our $VERSION = '1.00'; -$overload::hint_bits = 0x20000; +$overload::hint_bits = 0x20000; # HINT_LOCALIZE_HH sub nil {} @@ -91,7 +91,7 @@ sub AddrRef { } sub StrVal { - (OverloadedStringify($_[0]) or ref($_[0]) eq 'Regexp') ? + (ref $_[0] && OverloadedStringify($_[0]) or ref($_[0]) eq 'Regexp') ? (AddrRef(shift)) : "$_[0]"; } @@ -108,11 +108,11 @@ sub mycan { # Real can would leave stubs. } %constants = ( - 'integer' => 0x1000, - 'float' => 0x2000, - 'binary' => 0x4000, - 'q' => 0x8000, - 'qr' => 0x10000, + 'integer' => 0x1000, # HINT_NEW_INTEGER + 'float' => 0x2000, # HINT_NEW_FLOAT + 'binary' => 0x4000, # HINT_NEW_BINARY + 'q' => 0x8000, # HINT_NEW_STRING + 'qr' => 0x10000, # HINT_NEW_RE ); %ops = ( with_assign => "+ - * / % ** << >> x .", @@ -922,10 +922,7 @@ numeric value.) This prints: =head2 Two-face references Suppose you want to create an object which is accessible as both an -array reference and a hash reference, similar to the -L -builtin Perl type. Let's make it better than a pseudo-hash by -allowing index 0 to be treated as a normal element. +array reference and a hash reference. package two_refs; use overload '%{}' => \&gethash, '@{}' => sub { $ {shift()} };