From: Andrew Rodland Date: Sat, 14 Nov 2009 07:26:09 +0000 (-0600) Subject: Add code and starting perldoc for warnings::fatal_enabled. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ec983580254c32fd44889fde43973ac5dd74257b;p=p5sagit%2Fp5-mst-13.2.git Add code and starting perldoc for warnings::fatal_enabled. This is an analog for warnings::enabled, except it tests whether the given category has been set fatal using "use warnings FATAL => foo". This is mostly for symmetry. Assumes that the fatal bit for a category will have an offset one higher than the regular bit for the category, because otherwise much rewriting of __chk would be required. --- diff --git a/warnings.pl b/warnings.pl index dabc97d..9d84a79 100644 --- a/warnings.pl +++ b/warnings.pl @@ -529,6 +529,27 @@ Return TRUE if that warnings category is enabled in the first scope where the object is used. Otherwise returns FALSE. +=item warnings::fatal_enabled() + +Return TRUE if the warnings category with the same name as the current +package has been set to FATAL in the calling module. +Otherwise returns FALSE. + +=item warnings::fatal_enabled($category) + +Return TRUE if the warnings category C<$category> has been set to FATAL in +the calling module. +Otherwise returns FALSE. + +=item warnings::fatal_enabled($object) + +Use the name of the class for the object reference, C<$object>, as the +warnings category. + +Return TRUE if that warnings category has been set to FATAL in the first +scope where the object is used. +Otherwise returns FALSE. + =item warnings::warn($message) Print C<$message> to STDERR. @@ -756,6 +777,17 @@ sub enabled vec($callers_bitmask, $Offsets{'all'}, 1) ; } +sub fatal_enabled +{ + Croaker("Usage: warnings::fatal_enabled([category])") + unless @_ == 1 || @_ == 0 ; + + my ($callers_bitmask, $offset, $i) = __chk(@_) ; + + return 0 unless defined $callers_bitmask; + return vec($callers_bitmask, $offset + 1, 1) || + vec($callers_bitmask, $Offsets{'all'} + 1, 1) ; +} sub warn {