perlancar has asked for the wisdom of the Perl Monks concerning the following question:

Currently, overriding filetest operator can be done via overload, but this has limited use because you cannot override the common case of things like -x "filename". Would it be a good idea for the filetest operators to lookup stat() in the current package first and thus make them overridable via overriding stat()? Much like the backtick operator is overridable by overriding readpipe() (which I employ in IPC::System::Options).

One use-case I'm thinking of for overriding the filetest operators is testing. In test script I sometimes check for the existence of programs like /bin/bash and skip tests accordingly. I want to simulate the absence of /bin/bash even though my system has the program.

  • Comment on Overriding filetest operators via overriding stat()?

Replies are listed 'Best First'.
Re: Overriding filetest operators via overriding stat()?
by salva (Canon) on Feb 01, 2018 at 07:23 UTC
    A long time ago in a galaxy far, far away.... Overridable Filetest operators.

    update: IMO, your idea of making file test operators honor and overloaded stat would be a better approach than overloading them separately.

      Wow.

      Are you still interested in doing something like this, using the stat() approach?

Re: Overriding filetest operators via overriding stat()?
by haukex (Archbishop) on Feb 01, 2018 at 12:41 UTC