in reply to Warnings are enabled, but they aren't?
warnings::enabled() doesn't check if warnings are enabled "here" because you should already know that. It checks whether warnings are enabled in your caller. (In particular, it walks up the call stack to find the first caller level which is in a different package.)
use v5.16; package Foo { no warnings; sub foo { print( warnings::enabled( 'once' ) ? 'enabled' : 'disabled' ); } } package Bar { use warnings qw( once ); sub bar { Foo::foo(); } } Bar::bar();
Basically, it's designed so you can check if your caller wants warnings, to help you decide whether to warn them about stuffs.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Warnings are enabled, but they aren't?
by muthm (Sexton) on Feb 27, 2023 at 11:43 UTC |