in reply to Re^14: Try::Tiny and -E
in thread Try::Tiny and -E

> False negative:

As I already said:

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

But that's also a convoluted edge case.

If one really needed to activate both Try::Tiny and feature try inside the same file - let's say while gradually refactoring legacy code - and wouldn't want to see the warning, it would be acceptable to require from the author to deactivate the warning class ( no warnings "shadow" or "mask" or whatever)

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

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

    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.

      > 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).

        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