X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Foverload.pm;h=0120882999a2f85523fc865c8f2068ed78cf6576;hb=e68ec53fb89aea41859fe8c109fe9b03a3599284;hp=8c0b899495b52bf696f0599e1c9747bce4543abf;hpb=00acedc188c9751ee95950dacf7675153b18a34f;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/overload.pm b/lib/overload.pm index 8c0b899..0120882 100644 --- a/lib/overload.pm +++ b/lib/overload.pm @@ -1,8 +1,6 @@ package overload; -our $VERSION = '1.03'; - -$overload::hint_bits = 0x20000; # HINT_LOCALIZE_HH +our $VERSION = '1.04'; sub nil {} @@ -93,11 +91,7 @@ sub AddrRef { return sprintf("$class_prefix$type(0x%x)", $addr); } -sub StrVal { - (ref $_[0] && Overloaded($_[0]) or ref($_[0]) eq 'Regexp') ? - (AddrRef(shift)) : - "$_[0]"; -} +*StrVal = *AddrRef; sub mycan { # Real can would leave stubs. my ($package, $meth) = @_; @@ -153,7 +147,7 @@ sub constant { } else { $^H{$_[0]} = $_[1]; - $^H |= $constants{$_[0]} | $overload::hint_bits; + $^H |= $constants{$_[0]}; } shift, shift; } @@ -174,7 +168,7 @@ __END__ =head1 NAME -overload - Package for overloading perl operations +overload - Package for overloading Perl operations =head1 SYNOPSIS @@ -426,7 +420,7 @@ The dereference operators must be specified explicitly they will not be passed t =item * I - "nomethod", "fallback", "=", + "nomethod", "fallback", "=", "~~", see L>. @@ -546,6 +540,11 @@ C<"nomethod"> value, and if this is missing, raises an exception. B C<"fallback"> inheritance via @ISA is not carved in stone yet, see L<"Inheritance and overloading">. +=head2 Smart Match + +The key C<"~~"> allows you to override the smart matching used by +the switch construct. See L. + =head2 Copy Constructor The value for C<"="> is a reference to a function with three @@ -667,6 +666,23 @@ value is a scalar and not a reference. =back +=head1 Minimal set of overloaded operations + +Since some operations can be automatically generated from others, there is +a minimal set of operations that need to be overloaded in order to have +the complete set of overloaded operations at one's disposal. +Of course, the autogenerated operations may not do exactly what the user +expects. See L above. The minimal set is: + + + - * / % ** << >> x + <=> cmp + & | ^ ~ + atan2 cos sin exp log sqrt int + +Additionally, you need to define at least one of string, boolean or +numeric conversions because any one can be used to emulate the others. +The string conversion can also be used to emulate concatenation. + =head1 Losing overloading The restriction for the comparison operation is that even if, for example, @@ -721,12 +737,12 @@ Returns C or a reference to the method that implements C. =head1 Overloading constants -For some application Perl parser mangles constants too much. It is possible -to hook into this process via overload::constant() and overload::remove_constant() -functions. +For some applications, the Perl parser mangles constants too much. +It is possible to hook into this process via C +and C functions. These functions take a hash as an argument. The recognized keys of this hash -are +are: =over 8 @@ -782,9 +798,6 @@ From these methods they may be called as overload::constant integer => sub {Math::BigInt->new(shift)}; } -B Currently overloaded-ness of constants does not propagate -into C. - =head1 IMPLEMENTATION What follows is subject to change RSN.