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

> 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

Replies are listed 'Best First'.
Re^18: Try::Tiny and -E (False Negative)
by ikegami (Patriarch) on Jan 07, 2026 at 15:20 UTC

    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

        If you can patch *feature.pm*, you can patch the *feature itself*. Both are Perl. No need to patch Try::Tiny to add a warning to Perl.

        And I prefer to see the warning at the line where the use appears

        Then we're back to false negatives and false positives. This subthread was discussing how to avoid those.

Re^18: Try::Tiny and -E (False Negative)
by LanX (Saint) on Jan 07, 2026 at 01:49 UTC
    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