Check warnings::enabled & warnings::warn __END__ --FILE-- abc.pm package abc ; use warnings "io" ; print "ok1\n" if ! warnings::enabled('all') ; print "ok2\n" if ! warnings::enabled("io") ; 1; --FILE-- no warnings; use abc ; EXPECT ok1 ok2 ######## --FILE-- abc.pm package abc ; no warnings ; print "ok1\n" if !warnings::enabled('all') ; print "ok2\n" if warnings::enabled("syntax") ; 1; --FILE-- use warnings 'syntax' ; use abc ; EXPECT ok1 ok2 ######## --FILE-- abc.pm package abc ; use warnings 'syntax' ; print "ok1\n" if warnings::enabled('io') ; print "ok2\n" if ! warnings::enabled("syntax") ; 1; --FILE-- use warnings 'io' ; use abc ; EXPECT ok1 ok2 ######## --FILE-- abc no warnings ; print "ok1\n" if !warnings::enabled('all') ; print "ok2\n" if warnings::enabled("syntax") ; 1; --FILE-- use warnings 'syntax' ; require "abc" ; EXPECT ok1 ok2 ######## --FILE-- abc use warnings 'syntax' ; print "ok1\n" if ! warnings::enabled('all') ; print "ok2\n" if ! warnings::enabled("syntax") ; print "ok3\n" if warnings::enabled("io") ; 1; --FILE-- use warnings 'io' ; require "abc" ; EXPECT ok1 ok2 ok3 ######## --FILE-- abc.pm package abc ; no warnings ; sub check { print "ok1\n" if !warnings::enabled('all') ; print "ok2\n" if warnings::enabled("syntax") ; } 1; --FILE-- use warnings 'syntax' ; use abc ; abc::check() ; EXPECT ok1 ok2 ######## --FILE-- abc.pm package abc ; use warnings 'io' ; sub check { print "ok1\n" if ! warnings::enabled('all') ; print "ok2\n" if warnings::enabled("syntax") ; print "ok3\n" if ! warnings::enabled("io") ; } 1; --FILE-- use warnings 'syntax' ; use abc ; abc::check() ; EXPECT ok1 ok2 ok3 ######## --FILE-- abc package abc ; no warnings ; sub check { print "ok1\n" if !warnings::enabled('all') ; print "ok2\n" if warnings::enabled("syntax") ; } 1; --FILE-- use warnings 'syntax' ; require "abc" ; abc::check() ; EXPECT ok1 ok2 ######## --FILE-- abc package abc ; use warnings 'io' ; sub check { print "ok1\n" if ! warnings::enabled('all') ; print "ok2\n" if warnings::enabled("syntax") ; print "ok3\n" if ! warnings::enabled("io") ; } 1; --FILE-- use warnings 'syntax' ; require "abc" ; abc::check() ; EXPECT ok1 ok2 ok3 ######## --FILE-- abc.pm package abc ; use warnings "io" ; print "ok1\n" if ! warnings::enabled('all') ; print "ok2\n" if ! warnings::enabled("io") ; 1; --FILE-- def.pm no warnings; use abc ; 1; --FILE-- use warnings; use def ; EXPECT ok1 ok2 ######## --FILE-- abc.pm package abc ; no warnings ; print "ok1\n" if ! warnings::enabled('all') ; print "ok2\n" if warnings::enabled("syntax") ; print "ok3\n" if !warnings::enabled("io") ; 1; --FILE-- def.pm use warnings 'syntax' ; print "ok4\n" if !warnings::enabled('all') ; print "ok5\n" if warnings::enabled("io") ; use abc ; 1; --FILE-- use warnings 'io' ; use def ; EXPECT ok1 ok2 ok3 ok4 ok5 ######## --FILE-- abc.pm package abc ; no warnings ; sub check { print "ok1\n" if !warnings::enabled('all') ; print "ok2\n" if warnings::enabled("syntax") ; } 1; --FILE-- use warnings 'syntax' ; use abc ; eval { abc::check() ; }; print $@ ; EXPECT ok1 ok2 ######## --FILE-- abc.pm package abc ; use warnings 'io' ; sub check { print "ok1\n" if ! warnings::enabled('all') ; print "ok2\n" if warnings::enabled("syntax") ; print "ok3\n" if ! warnings::enabled("io") ; } 1; --FILE-- use warnings 'syntax' ; use abc ; eval { abc::check() ; } ; print $@ ; EXPECT ok1 ok2 ok3 ######## --FILE-- abc package abc ; no warnings ; sub check { print "ok1\n" if !warnings::enabled('all') ; print "ok2\n" if warnings::enabled("syntax") ; } 1; --FILE-- use warnings 'syntax' ; require "abc" ; eval { abc::check() ; } ; print $@ ; EXPECT ok1 ok2 ######## --FILE-- abc package abc ; use warnings 'io' ; sub check { print "ok1\n" if !warnings::enabled('all') ; print "ok2\n" if warnings::enabled("syntax") ; print "ok3\n" if warnings::enabled("io") ; } 1; --FILE-- use warnings 'syntax' ; require "abc" ; eval { use warnings 'io' ; abc::check() ; }; abc::check() ; print $@ ; EXPECT ok1 ok2 ok3 ok1 ok2 ######## --FILE-- abc.pm package abc ; use warnings 'io' ; sub check { print "ok1\n" if ! warnings::enabled('all') ; print "ok2\n" if warnings::enabled("syntax") ; print "ok3\n" if ! warnings::enabled("io") ; } 1; --FILE-- use warnings 'syntax' ; use abc ; sub fred { abc::check() } fred() ; EXPECT ok1 ok2 ok3 ######## --FILE-- abc.pm package abc ; use warnings 'io' ; sub check { print "ok1\n" if ! warnings::enabled('all') ; } 1; --FILE-- use warnings 'syntax' ; use abc ; sub fred { no warnings ; abc::check() } fred() ; EXPECT ok1 ######## --FILE-- abc.pm package abc ; use warnings 'misc' ; sub check { print "ok1\n" if ! warnings::enabled('all') ; print "ok2\n" if warnings::enabled("syntax") ; print "ok3\n" if warnings::enabled("io") ; print "ok4\n" if ! warnings::enabled("misc") ; } 1; --FILE-- use warnings 'syntax' ; use abc ; sub fred { use warnings 'io' ; abc::check() } fred() ; EXPECT ok1 ok2 ok3 ok4 ######## # check warnings::warn use warnings ; eval { warnings::warn() } ; print $@ ; eval { warnings::warn("fred", "joe") } ; print $@ ; EXPECT Usage: warnings::warn([category,] 'message') at - line 4 unknown warnings category 'fred' at - line 6 require 0 called at - line 6 ######## --FILE-- abc.pm package abc ; use warnings 'misc' ; sub check { warnings::warn("io", "hello") } 1; --FILE-- use warnings "io" ; use abc; abc::check() ; EXPECT hello at - line 3 ######## --FILE-- abc.pm package abc ; use warnings 'misc' ; sub check { warnings::warn("misc", "hello") } 1; --FILE-- use warnings "io" ; use abc; abc::check() ; EXPECT hello at - line 3 ######## --FILE-- abc.pm package abc ; use warnings 'misc' ; sub check { warnings::warn("io", "hello") } 1; --FILE-- use warnings qw( FATAL deprecated ) ; use abc; eval { abc::check() ; } ; print "[[$@]]\n"; EXPECT hello at - line 3 [[]] ######## --FILE-- abc.pm package abc ; use warnings 'misc' ; sub check { warnings::warn("io", "hello") } 1; --FILE-- use warnings qw( FATAL io ) ; use abc; eval { abc::check() ; } ; print "[[$@]]\n"; EXPECT [[hello at - line 3 ]] ######## -W --FILE-- abc.pm package abc ; use warnings "io" ; print "ok1\n" if warnings::enabled("io") ; print "ok2\n" if warnings::enabled("all") ; 1; --FILE-- no warnings; use abc ; EXPECT ok1 ok2 ######## -X --FILE-- abc.pm package abc ; use warnings "io" ; print "ok1\n" if !warnings::enabled("io") ; print "ok2\n" if !warnings::enabled("all") ; 1; --FILE-- use warnings; use abc ; EXPECT ok1 ok2 ######## --FILE-- abc.pm package abc ; no warnings ; sub check { print "ok\n" if ! warnings::enabled() ; } 1; --FILE-- use warnings 'syntax' ; use abc ; abc::check() ; EXPECT package 'abc' not registered for warnings at - line 3 ######## --FILE-- abc.pm package abc ; use warnings 'io' ; use warnings::register ; sub check { print "ok1\n" if warnings::enabled ; print "ok2\n" if warnings::enabled("syntax") ; print "ok3\n" if !warnings::enabled("io") ; } 1; --FILE-- use warnings 'syntax' ; use abc ; use warnings 'abc' ; abc::check() ; EXPECT ok1 ok2 ok3 ######## --FILE-- abc.pm package abc ; use warnings 'io' ; use warnings::register ; sub check { print "ok1\n" if !warnings::enabled ; print "ok2\n" if warnings::enabled("syntax") ; print "ok3\n" if !warnings::enabled("io") ; } 1; --FILE-- use warnings 'syntax' ; use abc ; abc::check() ; EXPECT ok1 ok2 ok3 ######## --FILE-- abc.pm package abc ; no warnings ; use warnings::register ; sub check { print "ok1\n" if warnings::enabled ; print "ok2\n" if warnings::enabled("syntax") ; } 1; --FILE-- use warnings 'syntax' ; use abc ; use warnings 'abc' ; eval { abc::check() ; }; print $@ ; EXPECT ok1 ok2 ######## --FILE-- abc.pm package abc ; use warnings 'io' ; use warnings::register ; sub check { print "ok1\n" if !warnings::enabled ; print "ok2\n" if warnings::enabled("syntax") ; print "ok3\n" if !warnings::enabled("io") ; } 1; --FILE-- use warnings 'syntax' ; use abc ; eval { abc::check() ; } ; print $@ ; EXPECT ok1 ok2 ok3 ######## --FILE-- abc.pm package abc ; use warnings 'io' ; use warnings::register ; sub check { print "ok1\n" if warnings::enabled ; print "ok2\n" if warnings::enabled("syntax") ; print "ok3\n" if !warnings::enabled("io") ; } 1; --FILE-- use warnings 'syntax' ; use abc ; use warnings 'abc' ; sub fred { abc::check() } fred() ; EXPECT ok1 ok2 ok3 ######## --FILE-- abc.pm package abc ; use warnings 'io' ; use warnings::register ; sub check { print "ok1\n" if ! warnings::enabled ; } 1; --FILE-- use warnings 'syntax' ; use abc ; sub fred { no warnings ; abc::check() } fred() ; EXPECT ok1 ######## --FILE-- abc.pm package abc ; use warnings 'misc' ; use warnings::register; sub check { print "ok1\n" if warnings::enabled ; print "ok2\n" if warnings::enabled("syntax") ; print "ok3\n" if warnings::enabled("io") ; print "ok4\n" if ! warnings::enabled("misc") ; } 1; --FILE-- use warnings 'syntax' ; use abc ; use warnings 'abc' ; sub fred { use warnings 'io' ; abc::check() } fred() ; EXPECT ok1 ok2 ok3 ok4 ######## --FILE-- abc.pm package abc ; use warnings 'misc' ; use warnings::register; sub check { warnings::warn("hello") } 1; --FILE-- use abc; use warnings "abc" ; abc::check() ; EXPECT hello at - line 3 ######## --FILE-- abc.pm package abc ; use warnings::register; sub check { warnings::warn("hello") } 1; --FILE-- use abc; abc::check() ; EXPECT hello at - line 2 ######## --FILE-- abc.pm package abc ; use warnings::register ; sub check { warnings::warn("hello") } 1; --FILE-- use abc; use warnings qw( FATAL deprecated ) ; eval { abc::check() ; } ; print "[[$@]]\n"; EXPECT hello at - line 3 [[]] ######## --FILE-- abc.pm package abc ; use warnings::register ; sub check { warnings::warn("hello") } 1; --FILE-- use abc; use warnings qw( FATAL abc ) ; eval { abc::check() ; } ; print "[[$@]]\n"; EXPECT [[hello at - line 3 ]] ######## -W --FILE-- abc.pm package abc ; use warnings "io" ; use warnings::register ; sub check { print "ok1\n" if warnings::enabled() ; print "ok2\n" if warnings::enabled("io") ; print "ok3\n" if warnings::enabled("all") ; } 1; --FILE-- no warnings; use abc ; abc::check() ; EXPECT ok1 ok2 ok3 ######## -X --FILE-- abc.pm package abc ; use warnings "io" ; use warnings::register ; sub check { print "ok1\n" if !warnings::enabled() ; print "ok2\n" if !warnings::enabled("io") ; print "ok3\n" if !warnings::enabled("all") ; } 1; --FILE-- no warnings; use abc ; abc::check() ; EXPECT ok1 ok2 ok3 ######## --FILE-- abc.pm package abc ; use warnings "io" ; use warnings::register ; sub check { print "ok1\n" if warnings::enabled() ; print "ok2\n" if warnings::enabled("io") ; print "ok3\n" if warnings::enabled("all") ; } 1; --FILE-- use warnings 'all'; use abc ; abc::check() ; EXPECT ok1 ok2 ok3 ######## --FILE-- abc.pm package abc ; use warnings "io" ; use warnings::register ; sub check { print "ok1\n" if !warnings::enabled() ; print "ok2\n" if !warnings::enabled("io") ; print "ok3\n" if !warnings::enabled("all") ; } 1; --FILE-- use abc ; no warnings ; abc::check() ; EXPECT ok1 ok2 ok3 ######## --FILE-- abc.pm package abc ; use warnings "io" ; use warnings::register ; sub check { print "ok1\n" if !warnings::enabled() ; print "ok2\n" if !warnings::enabled("io") ; print "ok3\n" if !warnings::enabled("all") ; } 1; --FILE-- use abc ; use warnings 'abc'; no warnings ; abc::check() ; EXPECT ok1 ok2 ok3 ######## --FILE-- abc.pm package abc ; use warnings "io" ; use warnings::register ; sub check { print "abc self" . (warnings::enabled() ? "" : " not") . " enabled\n" ; print "abc def" . (warnings::enabled('def') ? "" : " not") . " enabled\n" ; print "abc all" . (warnings::enabled('all') ? "" : " not") . " enabled\n" ; } 1; --FILE-- def.pm package def ; use warnings "io" ; use warnings::register ; sub check { print "def self" . (warnings::enabled() ? "" : " not") . " enabled\n" ; print "def abc" . (warnings::enabled('abc') ? "" : " not") . " enabled\n" ; print "def all" . (warnings::enabled('all') ? "" : " not") . " enabled\n" ; } 1; --FILE-- use abc ; use def ; use warnings 'abc'; abc::check() ; def::check() ; no warnings 'abc' ; use warnings 'def' ; abc::check() ; def::check() ; use warnings 'abc' ; use warnings 'def' ; abc::check() ; def::check() ; no warnings 'abc' ; no warnings 'def' ; abc::check() ; def::check() ; use warnings; abc::check() ; def::check() ; no warnings 'abc' ; abc::check() ; def::check() ; EXPECT abc self enabled abc def not enabled abc all not enabled def self not enabled def abc enabled def all not enabled abc self not enabled abc def enabled abc all not enabled def self enabled def abc not enabled def all not enabled abc self enabled abc def enabled abc all not enabled def self enabled def abc enabled def all not enabled abc self not enabled abc def not enabled abc all not enabled def self not enabled def abc not enabled def all not enabled abc self enabled abc def enabled abc all enabled def self enabled def abc enabled def all enabled abc self not enabled abc def enabled abc all not enabled def self enabled def abc not enabled def all not enabled