develooper Front page | perl.perl5.porters | Postings from October 2016

[perl #129947] warnings::warnif does not behave as documented

Thread Previous
From:
Karen Etheridge
Date:
October 23, 2016 21:04
Subject:
[perl #129947] warnings::warnif does not behave as documented
Message ID:
rt-4.0.24-15729-1477256654-1495.129947-75-0@perl.org
# New Ticket Created by  Karen Etheridge 
# Please include the string:  [perl #129947]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=129947 >



The documentation of warnings::warnif (perldoc warnings) says:

    warnings::warnif($message)
        Equivalent to:

            if (warnings::enabled())
              { warnings::warn($message) }

    warnings::warnif($category, $message)
        Equivalent to:

            if (warnings::enabled($category))
              { warnings::warn($category, $message) }


But it clearly isn't. Notice the difference in location identified in the
warning (*somewhat* as if if Carp::shortmess was used, but actually more than
one stack frame can be skipped):

    use strict;
    use warnings;

    {
	package Foo;

	sub foo {
	    warnings::warnif('deprecated', 'warning with warnif()');

	    warn 'warning with warn()' if warnings::enabled('deprecated'); 
	}
    }

    Foo::foo();

    __END__
    gives output:
    warning with warnif() at warn-repro.pl line 14.
    warning with warn() at warn-repro.pl line 10.


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About