X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Foverload.pm;h=d511f2c142e87261908f8f10a786591db5183740;hb=b30bcf62f5b15c203de3cee9cf8d918ec38ad867;hp=1853499da065985e372bd60a52dc5062e0543e2c;hpb=d411a6a9eb5df09116806ed1c441d30d37e8d5e8;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/overload.pm b/lib/overload.pm index 1853499..d511f2c 100644 --- a/lib/overload.pm +++ b/lib/overload.pm @@ -1,6 +1,6 @@ package overload; -our $VERSION = '1.02'; +our $VERSION = '1.04'; $overload::hint_bits = 0x20000; # HINT_LOCALIZE_HH @@ -93,11 +93,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) = @_; @@ -174,7 +170,7 @@ __END__ =head1 NAME -overload - Package for overloading perl operations +overload - Package for overloading Perl operations =head1 SYNOPSIS @@ -426,7 +422,7 @@ The dereference operators must be specified explicitly they will not be passed t =item * I - "nomethod", "fallback", "=", + "nomethod", "fallback", "=", "~~", see L>. @@ -521,6 +517,11 @@ The key C<"fallback"> governs what to do if a method for a particular operation is not found. Three different cases are possible depending on the value of C<"fallback">: +=head2 Smart Match + +The key C<"~~"> allows you to override the smart matching used by +the switch construct. See L. + =over 16 =item * C @@ -667,6 +668,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 +739,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 +800,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.