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

It's very much possible with a pure-Perl module like I said. The _enabled routines in feature are basically checking the hinthash %^H returned by caller for the needed level.

But the problem is that the code isn't even compiled into a call to Try::Tiny's try, so how is it supposed to check the hints? That requires hooking into the compiler.

Replies are listed 'Best First'.
Re^7: Try::Tiny and -E
by LanX (Saint) on Dec 29, 2025 at 12:05 UTC
    Not sure what you are objecting about, the newest feature has code examples showing how an import() of a module can check the hinthash of the caller.

    Try::Tiny or others could do this too, if they come second.

    From feature_enabled($feature, $depth)

    package MyStandardEnforcer; use feature (); use Carp "croak"; sub import { croak "disable indirect!" if feature::feature_enabled("indirect"); }

    And yes, the implementation of feature_enabled() is in pure Perl.

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

      That solution will give both false positives (warn when it shouldn't) and false negatives (not warn when it should). The order loaded will determine if you can get false positives or false negatives, but it you can get false results regardless of the order in which they are loaded. Again, the order in which you load the modules is irrelevant. And that's because you're checking at the wrong time to get consistent results. For that, you need to check when try use is compiled, not when the module is loaded.

        > For that, you need to check when try use is compiled,

        What do you mean?

        > That solution will give both false positives (warn when it shouldn't) and false negatives (not warn when it should).

        Please elaborate or demonstrate those cases.

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