in reply to Overriding "-s", "-f" and other -X functions

Hello Doctrin,

I haven’t tried it, but here is an excerpt from the documentation for the core overload pragma, under “Overloadable Operations”:

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Overriding "-s", "-f" and other -X functions
by haukex (Archbishop) on Jul 07, 2018 at 08:00 UTC

    Note that this only works if the thing that you're calling the -X on is an object of the overloaded class.

    use warnings; use strict; { package Foo; use Data::Dump; use overload fallback=>0, '-X' => sub { dd @_; return 1 }; } my $foo = bless {}, 'Foo'; print -e $foo ? 'yes' : 'no', "\n"; my $bar = "doesnotexist"; print -e $bar ? 'yes' : 'no', "\n"; __END__ (bless({}, "Foo"), "e", "") yes no