in reply to Re^15: Try::Tiny and -E (False Negative)
in thread Try::Tiny and -E

In this case feature "try" would need to warn about the subs in the caller's stash.

Doing it at run-time won't work. We're trying to issue the warning before the compilation error.

  • Comment on Re^16: Try::Tiny and -E (False Negative)

Replies are listed 'Best First'.
Re^17: Try::Tiny and -E (False Negative)
by LanX (Saint) on Jan 06, 2026 at 21:20 UTC
    > Doing it at run-time won't work

    And I'm talking about compile time:

    Pragmas like use feature have the same import-timing like modules and all subs are declared at compile time.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      Ah, you were talking about patching feature.pm. Yes, that (or something like that) would work. That's in line with what I said about it not being Try::Tiny's issue to resolve. Also, having feature.pm (or perlcritic) handle it would help with all non-builtin implementations of try (not just Try::Tiny's).

        As I already said, both need to be patched. I don't see a way how use feature could warn about a later use Try::Tiny (... well except of a general solution°)

        And I prefer to see the warning at the line where the use appears, not the one with conflicting 'try {}'.

        In general any module exporting subs that conflict with potential built-ins should check at import time.

        The needed code to check the hint-hash should be refactored from feature.pm into a separate module.

        footnote
        °) In theory one could write an INC-hook which wraps around each use and require and checks the namespaces and hint-hashes for conflicts.

        Like this no modules need to be patched.

        Not sure if this is not an overkill tho.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery

      DEMO:

      use strict; use warnings; # selfcontained simulation of feature pragma package my_feature; use Carp; sub import { my $pkg = (caller)[0]; if ( grep {$_ eq "try"} @_ ) { for my $func (qw/try catch finally/) { carp "Warning: ${pkg}::$func() will be shadowed by feature 'tr +y'" if exists &{"${pkg}::$func"}; } } } 1; BEGIN { $INC{"my_feature.pm"} = "DEMO from " . __FILE__ } # end simulation package Foo; use Try::Tiny; use my_feature "try";

      -->
      perl /home/lanx/perl/pm/check_stash_sub.pl Warning: Foo::try() will be shadowed by feature 'try' at /home/lanx/pe +rl/pm/check_stash_sub.pl line 23. Warning: Foo::catch() will be shadowed by feature 'try' at /home/lanx/ +perl/pm/check_stash_sub.pl line 23. Warning: Foo::finally() will be shadowed by feature 'try' at /home/lan +x/perl/pm/check_stash_sub.pl line 23.

      NB: The warnings are emitted before any code following the use feature is compiled.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery