summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/lib/overload.pm
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin/perl/lib/overload.pm')
-rw-r--r--gnu/usr.bin/perl/lib/overload.pm59
1 files changed, 47 insertions, 12 deletions
diff --git a/gnu/usr.bin/perl/lib/overload.pm b/gnu/usr.bin/perl/lib/overload.pm
index f83191b5cd0..7d09d69e055 100644
--- a/gnu/usr.bin/perl/lib/overload.pm
+++ b/gnu/usr.bin/perl/lib/overload.pm
@@ -1,6 +1,6 @@
package overload;
-our $VERSION = '1.07';
+our $VERSION = '1.10';
sub nil {}
@@ -9,6 +9,7 @@ sub OVERLOAD {
my %arg = @_;
my ($sub, $fb);
$ {$package . "::OVERLOAD"}{dummy}++; # Register with magic by touching.
+ $fb = ${$package . "::()"}; # preserve old fallback value RT#68196
*{$package . "::()"} = \&nil; # Make it findable via fetchmethod.
for (keys %arg) {
if ($_ eq 'fallback') {
@@ -104,6 +105,10 @@ sub AddrRef {
sub mycan { # Real can would leave stubs.
my ($package, $meth) = @_;
+ local $@;
+ local $!;
+ require mro;
+
my $mro = mro::get_linear_isa($package);
foreach my $p (@$mro) {
my $fqmeth = $p . q{::} . $meth;
@@ -130,8 +135,9 @@ sub mycan { # Real can would leave stubs.
unary => "neg ! ~",
mutators => '++ --',
func => "atan2 cos sin exp abs log sqrt int",
- conversion => 'bool "" 0+',
+ conversion => 'bool "" 0+ qr',
iterators => '<>',
+ filetest => "-X",
dereferencing => '${} @{} %{} &{} *{}',
matching => '~~',
special => 'nomethod fallback =');
@@ -394,15 +400,20 @@ floating-point-like types one should follow the same semantic. If
C<int> is unavailable, it can be autogenerated using the overloading of
C<0+>.
-=item * I<Boolean, string and numeric conversion>
+=item * I<Boolean, string, numeric and regexp conversions>
- 'bool', '""', '0+',
+ 'bool', '""', '0+', 'qr'
-If one or two of these operations are not overloaded, the remaining ones can
-be used instead. C<bool> is used in the flow control operators
-(like C<while>) and for the ternary C<?:> operation. These functions can
-return any arbitrary Perl value. If the corresponding operation for this value
-is overloaded too, that operation will be called again with this value.
+If one or two of these operations are not overloaded, the remaining ones
+can be used instead. C<bool> is used in the flow control operators
+(like C<while>) and for the ternary C<?:> operation; C<qr> is used for
+the RHS of C<=~> and when an object is interpolated into a regexp.
+
+C<bool>, C<"">, and C<0+> can return any arbitrary Perl value. If the
+corresponding operation for this value is overloaded too, that operation
+will be called again with this value. C<qr> must return a compiled
+regexp, or a ref to a compiled regexp (such as C<qr//> returns), and any
+further overloading on the return value will be ignored.
As a special case if the overload returns the object itself then it will
be used directly. An overloaded conversion returning the object is
@@ -421,6 +432,29 @@ I<globbing> syntax C<E<lt>${var}E<gt>>.
B<BUGS> Even in list context, the iterator is currently called only
once and with scalar context.
+=item * I<File tests>
+
+ "-X"
+
+This overload is used for all the filetest operators (C<-f>, C<-x> and
+so on: see L<perlfunc/-X> for the full list). Even though these are
+unary operators, the method will be called with a second argument which
+is a single letter indicating which test was performed. Note that the
+overload key is the literal string C<"-X">: you can't provide separate
+overloads for the different tests.
+
+Calling an overloaded filetest operator does not affect the stat value
+associated with the special filehandle C<_>. It still refers to the
+result of the last C<stat>, C<lstat> or unoverloaded filetest.
+
+If not overloaded, these operators will fall back to the default
+behaviour even without C<< fallback => 1 >>. This means that if the
+object is a blessed glob or blessed IO ref it will be treated as a
+filehandle, otherwise string overloading will be invoked and the result
+treated as a filename.
+
+This overload was introduced in perl 5.12.
+
=item * I<Matching>
The key C<"~~"> allows you to override the smart matching logic used by
@@ -489,8 +523,9 @@ A computer-readable form of the above table is available in the hash
unary => 'neg ! ~',
mutators => '++ --',
func => 'atan2 cos sin exp abs log sqrt',
- conversion => 'bool "" 0+',
+ conversion => 'bool "" 0+ qr',
iterators => '<>',
+ filetest => '-X',
dereferencing => '${} @{} %{} &{} *{}',
matching => '~~',
special => 'nomethod fallback ='
@@ -663,8 +698,8 @@ is not defined.
=item I<Conversion operations>
-String, numeric, and boolean conversion are calculated in terms of one
-another if not all of them are defined.
+String, numeric, boolean and regexp conversions are calculated in terms
+of one another if not all of them are defined.
=item I<Increment and decrement>