warnings.pm 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. # -*- buffer-read-only: t -*-
  2. # !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
  3. # This file is built by regen/warnings.pl.
  4. # Any changes made here will be lost!
  5. package warnings;
  6. our $VERSION = "1.34";
  7. # Verify that we're called correctly so that warnings will work.
  8. # see also strict.pm.
  9. unless ( __FILE__ =~ /(^|[\/\\])\Q${\__PACKAGE__}\E\.pmc?$/ ) {
  10. my (undef, $f, $l) = caller;
  11. die("Incorrect use of pragma '${\__PACKAGE__}' at $f line $l.\n");
  12. }
  13. our %Offsets = (
  14. # Warnings Categories added in Perl 5.008
  15. 'all' => 0,
  16. 'closure' => 2,
  17. 'deprecated' => 4,
  18. 'exiting' => 6,
  19. 'glob' => 8,
  20. 'io' => 10,
  21. 'closed' => 12,
  22. 'exec' => 14,
  23. 'layer' => 16,
  24. 'newline' => 18,
  25. 'pipe' => 20,
  26. 'unopened' => 22,
  27. 'misc' => 24,
  28. 'numeric' => 26,
  29. 'once' => 28,
  30. 'overflow' => 30,
  31. 'pack' => 32,
  32. 'portable' => 34,
  33. 'recursion' => 36,
  34. 'redefine' => 38,
  35. 'regexp' => 40,
  36. 'severe' => 42,
  37. 'debugging' => 44,
  38. 'inplace' => 46,
  39. 'internal' => 48,
  40. 'malloc' => 50,
  41. 'signal' => 52,
  42. 'substr' => 54,
  43. 'syntax' => 56,
  44. 'ambiguous' => 58,
  45. 'bareword' => 60,
  46. 'digit' => 62,
  47. 'parenthesis' => 64,
  48. 'precedence' => 66,
  49. 'printf' => 68,
  50. 'prototype' => 70,
  51. 'qw' => 72,
  52. 'reserved' => 74,
  53. 'semicolon' => 76,
  54. 'taint' => 78,
  55. 'threads' => 80,
  56. 'uninitialized' => 82,
  57. 'unpack' => 84,
  58. 'untie' => 86,
  59. 'utf8' => 88,
  60. 'void' => 90,
  61. # Warnings Categories added in Perl 5.011
  62. 'imprecision' => 92,
  63. 'illegalproto' => 94,
  64. # Warnings Categories added in Perl 5.013
  65. 'non_unicode' => 96,
  66. 'nonchar' => 98,
  67. 'surrogate' => 100,
  68. # Warnings Categories added in Perl 5.017
  69. 'experimental' => 102,
  70. 'experimental::lexical_subs' => 104,
  71. 'experimental::lexical_topic' => 106,
  72. 'experimental::regex_sets' => 108,
  73. 'experimental::smartmatch' => 110,
  74. # Warnings Categories added in Perl 5.019
  75. 'experimental::autoderef' => 112,
  76. 'experimental::postderef' => 114,
  77. 'experimental::signatures' => 116,
  78. 'syscalls' => 118,
  79. # Warnings Categories added in Perl 5.021
  80. 'experimental::bitwise' => 120,
  81. 'experimental::const_attr' => 122,
  82. 'experimental::re_strict' => 124,
  83. 'experimental::refaliasing' => 126,
  84. 'experimental::win32_perlio' => 128,
  85. 'locale' => 130,
  86. 'missing' => 132,
  87. 'redundant' => 134,
  88. );
  89. our %Bits = (
  90. 'all' => "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55", # [0..67]
  91. 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [29]
  92. 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [30]
  93. 'closed' => "\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
  94. 'closure' => "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
  95. 'debugging' => "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [22]
  96. 'deprecated' => "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
  97. 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [31]
  98. 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
  99. 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
  100. 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x55\x15\x55\x01", # [51..58,60..64]
  101. 'experimental::autoderef' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00", # [56]
  102. 'experimental::bitwise' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [60]
  103. 'experimental::const_attr' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00", # [61]
  104. 'experimental::lexical_subs' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00", # [52]
  105. 'experimental::lexical_topic' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00", # [53]
  106. 'experimental::postderef' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00", # [57]
  107. 'experimental::re_strict' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00", # [62]
  108. 'experimental::refaliasing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [63]
  109. 'experimental::regex_sets' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [54]
  110. 'experimental::signatures' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00", # [58]
  111. 'experimental::smartmatch' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", # [55]
  112. 'experimental::win32_perlio' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [64]
  113. 'glob' => "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
  114. 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00", # [47]
  115. 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [46]
  116. 'inplace' => "\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [23]
  117. 'internal' => "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [24]
  118. 'io' => "\x00\x54\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [5..11,59]
  119. 'layer' => "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
  120. 'locale' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04", # [65]
  121. 'malloc' => "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [25]
  122. 'misc' => "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
  123. 'missing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", # [66]
  124. 'newline' => "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
  125. 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00", # [48]
  126. 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00", # [49]
  127. 'numeric' => "\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
  128. 'once' => "\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
  129. 'overflow' => "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
  130. 'pack' => "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [16]
  131. 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", # [32]
  132. 'pipe' => "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
  133. 'portable' => "\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [17]
  134. 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00", # [33]
  135. 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00", # [34]
  136. 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", # [35]
  137. 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", # [36]
  138. 'recursion' => "\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [18]
  139. 'redefine' => "\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [19]
  140. 'redundant' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40", # [67]
  141. 'regexp' => "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [20]
  142. 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", # [37]
  143. 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00", # [38]
  144. 'severe' => "\x00\x00\x00\x00\x00\x54\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [21..25]
  145. 'signal' => "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [26]
  146. 'substr' => "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [27]
  147. 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [50]
  148. 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\x55\x55\x15\x00\x40\x00\x00\x00\x00\x00", # [28..38,47]
  149. 'syscalls' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [59]
  150. 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00", # [39]
  151. 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00", # [40]
  152. 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00", # [41]
  153. 'unopened' => "\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
  154. 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00", # [42]
  155. 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00", # [43]
  156. 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x15\x00\x00\x00\x00", # [44,48..50]
  157. 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00", # [45]
  158. );
  159. our %DeadBits = (
  160. 'all' => "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", # [0..67]
  161. 'ambiguous' => "\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [29]
  162. 'bareword' => "\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [30]
  163. 'closed' => "\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [6]
  164. 'closure' => "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [1]
  165. 'debugging' => "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [22]
  166. 'deprecated' => "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [2]
  167. 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [31]
  168. 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7]
  169. 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3]
  170. 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xaa\x2a\xaa\x02", # [51..58,60..64]
  171. 'experimental::autoderef' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00", # [56]
  172. 'experimental::bitwise' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [60]
  173. 'experimental::const_attr' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00", # [61]
  174. 'experimental::lexical_subs' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00", # [52]
  175. 'experimental::lexical_topic' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00", # [53]
  176. 'experimental::postderef' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00", # [57]
  177. 'experimental::re_strict' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00", # [62]
  178. 'experimental::refaliasing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [63]
  179. 'experimental::regex_sets' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [54]
  180. 'experimental::signatures' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00", # [58]
  181. 'experimental::smartmatch' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00", # [55]
  182. 'experimental::win32_perlio' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [64]
  183. 'glob' => "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [4]
  184. 'illegalproto' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00", # [47]
  185. 'imprecision' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [46]
  186. 'inplace' => "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [23]
  187. 'internal' => "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [24]
  188. 'io' => "\x00\xa8\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [5..11,59]
  189. 'layer' => "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [8]
  190. 'locale' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08", # [65]
  191. 'malloc' => "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [25]
  192. 'misc' => "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [12]
  193. 'missing' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20", # [66]
  194. 'newline' => "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [9]
  195. 'non_unicode' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00", # [48]
  196. 'nonchar' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00", # [49]
  197. 'numeric' => "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [13]
  198. 'once' => "\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [14]
  199. 'overflow' => "\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [15]
  200. 'pack' => "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [16]
  201. 'parenthesis' => "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", # [32]
  202. 'pipe' => "\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [10]
  203. 'portable' => "\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [17]
  204. 'precedence' => "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00", # [33]
  205. 'printf' => "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00", # [34]
  206. 'prototype' => "\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00", # [35]
  207. 'qw' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", # [36]
  208. 'recursion' => "\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [18]
  209. 'redefine' => "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [19]
  210. 'redundant' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80", # [67]
  211. 'regexp' => "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [20]
  212. 'reserved' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", # [37]
  213. 'semicolon' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00", # [38]
  214. 'severe' => "\x00\x00\x00\x00\x00\xa8\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [21..25]
  215. 'signal' => "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [26]
  216. 'substr' => "\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [27]
  217. 'surrogate' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [50]
  218. 'syntax' => "\x00\x00\x00\x00\x00\x00\x00\xaa\xaa\x2a\x00\x80\x00\x00\x00\x00\x00", # [28..38,47]
  219. 'syscalls' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [59]
  220. 'taint' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", # [39]
  221. 'threads' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00", # [40]
  222. 'uninitialized' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00", # [41]
  223. 'unopened' => "\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [11]
  224. 'unpack' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00", # [42]
  225. 'untie' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", # [43]
  226. 'utf8' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x2a\x00\x00\x00\x00", # [44,48..50]
  227. 'void' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00", # [45]
  228. );
  229. # These are used by various things, including our own tests
  230. our $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
  231. our $DEFAULT = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x00\x55\x15\x55\x05", # [2,56,60,61,52,53,57,62,63,54,58,55,64,4,65,22,23,25]
  232. our $LAST_BIT = 136 ;
  233. our $BYTES = 17 ;
  234. our $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
  235. sub Croaker
  236. {
  237. require Carp; # this initializes %CarpInternal
  238. local $Carp::CarpInternal{'warnings'};
  239. delete $Carp::CarpInternal{'warnings'};
  240. Carp::croak(@_);
  241. }
  242. sub _bits {
  243. my $mask = shift ;
  244. my $catmask ;
  245. my $fatal = 0 ;
  246. my $no_fatal = 0 ;
  247. foreach my $word ( @_ ) {
  248. if ($word eq 'FATAL') {
  249. $fatal = 1;
  250. $no_fatal = 0;
  251. }
  252. elsif ($word eq 'NONFATAL') {
  253. $fatal = 0;
  254. $no_fatal = 1;
  255. }
  256. elsif ($catmask = $Bits{$word}) {
  257. $mask |= $catmask ;
  258. $mask |= $DeadBits{$word} if $fatal ;
  259. $mask &= ~($DeadBits{$word}|$All) if $no_fatal ;
  260. }
  261. else
  262. { Croaker("Unknown warnings category '$word'")}
  263. }
  264. return $mask ;
  265. }
  266. sub bits
  267. {
  268. # called from B::Deparse.pm
  269. push @_, 'all' unless @_ ;
  270. return _bits(undef, @_) ;
  271. }
  272. sub import
  273. {
  274. shift;
  275. my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ;
  276. if (vec($mask, $Offsets{'all'}, 1)) {
  277. $mask |= $Bits{'all'} ;
  278. $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
  279. }
  280. # append 'all' when implied (after a lone "FATAL" or "NONFATAL")
  281. push @_, 'all' if @_==1 && ( $_[0] eq 'FATAL' || $_[0] eq 'NONFATAL' );
  282. # Empty @_ is equivalent to @_ = 'all' ;
  283. ${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ;
  284. }
  285. sub unimport
  286. {
  287. shift;
  288. my $catmask ;
  289. my $mask = ${^WARNING_BITS} // ($^W ? $Bits{all} : $DEFAULT) ;
  290. if (vec($mask, $Offsets{'all'}, 1)) {
  291. $mask |= $Bits{'all'} ;
  292. $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
  293. }
  294. # append 'all' when implied (empty import list or after a lone "FATAL")
  295. push @_, 'all' if !@_ || @_==1 && $_[0] eq 'FATAL';
  296. foreach my $word ( @_ ) {
  297. if ($word eq 'FATAL') {
  298. next;
  299. }
  300. elsif ($catmask = $Bits{$word}) {
  301. $mask &= ~($catmask | $DeadBits{$word} | $All);
  302. }
  303. else
  304. { Croaker("Unknown warnings category '$word'")}
  305. }
  306. ${^WARNING_BITS} = $mask ;
  307. }
  308. my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = ();
  309. sub MESSAGE () { 4 };
  310. sub FATAL () { 2 };
  311. sub NORMAL () { 1 };
  312. sub __chk
  313. {
  314. my $category ;
  315. my $offset ;
  316. my $isobj = 0 ;
  317. my $wanted = shift;
  318. my $has_message = $wanted & MESSAGE;
  319. unless (@_ == 1 || @_ == ($has_message ? 2 : 0)) {
  320. my $sub = (caller 1)[3];
  321. my $syntax = $has_message ? "[category,] 'message'" : '[category]';
  322. Croaker("Usage: $sub($syntax)");
  323. }
  324. my $message = pop if $has_message;
  325. if (@_) {
  326. # check the category supplied.
  327. $category = shift ;
  328. if (my $type = ref $category) {
  329. Croaker("not an object")
  330. if exists $builtin_type{$type};
  331. $category = $type;
  332. $isobj = 1 ;
  333. }
  334. $offset = $Offsets{$category};
  335. Croaker("Unknown warnings category '$category'")
  336. unless defined $offset;
  337. }
  338. else {
  339. $category = (caller(1))[0] ;
  340. $offset = $Offsets{$category};
  341. Croaker("package '$category' not registered for warnings")
  342. unless defined $offset ;
  343. }
  344. my $i;
  345. if ($isobj) {
  346. my $pkg;
  347. $i = 2;
  348. while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
  349. last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
  350. }
  351. $i -= 2 ;
  352. }
  353. else {
  354. $i = _error_loc(); # see where Carp will allocate the error
  355. }
  356. # Default to 0 if caller returns nothing. Default to $DEFAULT if it
  357. # explicitly returns undef.
  358. my(@callers_bitmask) = (caller($i))[9] ;
  359. my $callers_bitmask =
  360. @callers_bitmask ? $callers_bitmask[0] // $DEFAULT : 0 ;
  361. my @results;
  362. foreach my $type (FATAL, NORMAL) {
  363. next unless $wanted & $type;
  364. push @results, (vec($callers_bitmask, $offset + $type - 1, 1) ||
  365. vec($callers_bitmask, $Offsets{'all'} + $type - 1, 1));
  366. }
  367. # &enabled and &fatal_enabled
  368. return $results[0] unless $has_message;
  369. # &warnif, and the category is neither enabled as warning nor as fatal
  370. return if $wanted == (NORMAL | FATAL | MESSAGE)
  371. && !($results[0] || $results[1]);
  372. require Carp;
  373. Carp::croak($message) if $results[0];
  374. # will always get here for &warn. will only get here for &warnif if the
  375. # category is enabled
  376. Carp::carp($message);
  377. }
  378. sub _mkMask
  379. {
  380. my ($bit) = @_;
  381. my $mask = "";
  382. vec($mask, $bit, 1) = 1;
  383. return $mask;
  384. }
  385. sub register_categories
  386. {
  387. my @names = @_;
  388. for my $name (@names) {
  389. if (! defined $Bits{$name}) {
  390. $Bits{$name} = _mkMask($LAST_BIT);
  391. vec($Bits{'all'}, $LAST_BIT, 1) = 1;
  392. $Offsets{$name} = $LAST_BIT ++;
  393. foreach my $k (keys %Bits) {
  394. vec($Bits{$k}, $LAST_BIT, 1) = 0;
  395. }
  396. $DeadBits{$name} = _mkMask($LAST_BIT);
  397. vec($DeadBits{'all'}, $LAST_BIT++, 1) = 1;
  398. }
  399. }
  400. }
  401. sub _error_loc {
  402. require Carp;
  403. goto &Carp::short_error_loc; # don't introduce another stack frame
  404. }
  405. sub enabled
  406. {
  407. return __chk(NORMAL, @_);
  408. }
  409. sub fatal_enabled
  410. {
  411. return __chk(FATAL, @_);
  412. }
  413. sub warn
  414. {
  415. return __chk(FATAL | MESSAGE, @_);
  416. }
  417. sub warnif
  418. {
  419. return __chk(NORMAL | FATAL | MESSAGE, @_);
  420. }
  421. # These are not part of any public interface, so we can delete them to save
  422. # space.
  423. delete @warnings::{qw(NORMAL FATAL MESSAGE)};
  424. 1;
  425. __END__
  426. =head1 NAME
  427. warnings - Perl pragma to control optional warnings
  428. =head1 SYNOPSIS
  429. use warnings;
  430. no warnings;
  431. use warnings "all";
  432. no warnings "all";
  433. use warnings::register;
  434. if (warnings::enabled()) {
  435. warnings::warn("some warning");
  436. }
  437. if (warnings::enabled("void")) {
  438. warnings::warn("void", "some warning");
  439. }
  440. if (warnings::enabled($object)) {
  441. warnings::warn($object, "some warning");
  442. }
  443. warnings::warnif("some warning");
  444. warnings::warnif("void", "some warning");
  445. warnings::warnif($object, "some warning");
  446. =head1 DESCRIPTION
  447. The C<warnings> pragma gives control over which warnings are enabled in
  448. which parts of a Perl program. It's a more flexible alternative for
  449. both the command line flag B<-w> and the equivalent Perl variable,
  450. C<$^W>.
  451. This pragma works just like the C<strict> pragma.
  452. This means that the scope of the warning pragma is limited to the
  453. enclosing block. It also means that the pragma setting will not
  454. leak across files (via C<use>, C<require> or C<do>). This allows
  455. authors to independently define the degree of warning checks that will
  456. be applied to their module.
  457. By default, optional warnings are disabled, so any legacy code that
  458. doesn't attempt to control the warnings will work unchanged.
  459. All warnings are enabled in a block by either of these:
  460. use warnings;
  461. use warnings 'all';
  462. Similarly all warnings are disabled in a block by either of these:
  463. no warnings;
  464. no warnings 'all';
  465. For example, consider the code below:
  466. use warnings;
  467. my @a;
  468. {
  469. no warnings;
  470. my $b = @a[0];
  471. }
  472. my $c = @a[0];
  473. The code in the enclosing block has warnings enabled, but the inner
  474. block has them disabled. In this case that means the assignment to the
  475. scalar C<$c> will trip the C<"Scalar value @a[0] better written as $a[0]">
  476. warning, but the assignment to the scalar C<$b> will not.
  477. =head2 Default Warnings and Optional Warnings
  478. Before the introduction of lexical warnings, Perl had two classes of
  479. warnings: mandatory and optional.
  480. As its name suggests, if your code tripped a mandatory warning, you
  481. would get a warning whether you wanted it or not.
  482. For example, the code below would always produce an C<"isn't numeric">
  483. warning about the "2:".
  484. my $a = "2:" + 3;
  485. With the introduction of lexical warnings, mandatory warnings now become
  486. I<default> warnings. The difference is that although the previously
  487. mandatory warnings are still enabled by default, they can then be
  488. subsequently enabled or disabled with the lexical warning pragma. For
  489. example, in the code below, an C<"isn't numeric"> warning will only
  490. be reported for the C<$a> variable.
  491. my $a = "2:" + 3;
  492. no warnings;
  493. my $b = "2:" + 3;
  494. Note that neither the B<-w> flag or the C<$^W> can be used to
  495. disable/enable default warnings. They are still mandatory in this case.
  496. =head2 What's wrong with B<-w> and C<$^W>
  497. Although very useful, the big problem with using B<-w> on the command
  498. line to enable warnings is that it is all or nothing. Take the typical
  499. scenario when you are writing a Perl program. Parts of the code you
  500. will write yourself, but it's very likely that you will make use of
  501. pre-written Perl modules. If you use the B<-w> flag in this case, you
  502. end up enabling warnings in pieces of code that you haven't written.
  503. Similarly, using C<$^W> to either disable or enable blocks of code is
  504. fundamentally flawed. For a start, say you want to disable warnings in
  505. a block of code. You might expect this to be enough to do the trick:
  506. {
  507. local ($^W) = 0;
  508. my $a =+ 2;
  509. my $b; chop $b;
  510. }
  511. When this code is run with the B<-w> flag, a warning will be produced
  512. for the C<$a> line: C<"Reversed += operator">.
  513. The problem is that Perl has both compile-time and run-time warnings. To
  514. disable compile-time warnings you need to rewrite the code like this:
  515. {
  516. BEGIN { $^W = 0 }
  517. my $a =+ 2;
  518. my $b; chop $b;
  519. }
  520. The other big problem with C<$^W> is the way you can inadvertently
  521. change the warning setting in unexpected places in your code. For example,
  522. when the code below is run (without the B<-w> flag), the second call
  523. to C<doit> will trip a C<"Use of uninitialized value"> warning, whereas
  524. the first will not.
  525. sub doit
  526. {
  527. my $b; chop $b;
  528. }
  529. doit();
  530. {
  531. local ($^W) = 1;
  532. doit()
  533. }
  534. This is a side-effect of C<$^W> being dynamically scoped.
  535. Lexical warnings get around these limitations by allowing finer control
  536. over where warnings can or can't be tripped.
  537. =head2 Controlling Warnings from the Command Line
  538. There are three Command Line flags that can be used to control when
  539. warnings are (or aren't) produced:
  540. =over 5
  541. =item B<-w>
  542. X<-w>
  543. This is the existing flag. If the lexical warnings pragma is B<not>
  544. used in any of you code, or any of the modules that you use, this flag
  545. will enable warnings everywhere. See L<Backward Compatibility> for
  546. details of how this flag interacts with lexical warnings.
  547. =item B<-W>
  548. X<-W>
  549. If the B<-W> flag is used on the command line, it will enable all warnings
  550. throughout the program regardless of whether warnings were disabled
  551. locally using C<no warnings> or C<$^W =0>.
  552. This includes all files that get
  553. included via C<use>, C<require> or C<do>.
  554. Think of it as the Perl equivalent of the "lint" command.
  555. =item B<-X>
  556. X<-X>
  557. Does the exact opposite to the B<-W> flag, i.e. it disables all warnings.
  558. =back
  559. =head2 Backward Compatibility
  560. If you are used to working with a version of Perl prior to the
  561. introduction of lexically scoped warnings, or have code that uses both
  562. lexical warnings and C<$^W>, this section will describe how they interact.
  563. How Lexical Warnings interact with B<-w>/C<$^W>:
  564. =over 5
  565. =item 1.
  566. If none of the three command line flags (B<-w>, B<-W> or B<-X>) that
  567. control warnings is used and neither C<$^W> nor the C<warnings> pragma
  568. are used, then default warnings will be enabled and optional warnings
  569. disabled.
  570. This means that legacy code that doesn't attempt to control the warnings
  571. will work unchanged.
  572. =item 2.
  573. The B<-w> flag just sets the global C<$^W> variable as in 5.005. This
  574. means that any legacy code that currently relies on manipulating C<$^W>
  575. to control warning behavior will still work as is.
  576. =item 3.
  577. Apart from now being a boolean, the C<$^W> variable operates in exactly
  578. the same horrible uncontrolled global way, except that it cannot
  579. disable/enable default warnings.
  580. =item 4.
  581. If a piece of code is under the control of the C<warnings> pragma,
  582. both the C<$^W> variable and the B<-w> flag will be ignored for the
  583. scope of the lexical warning.
  584. =item 5.
  585. The only way to override a lexical warnings setting is with the B<-W>
  586. or B<-X> command line flags.
  587. =back
  588. The combined effect of 3 & 4 is that it will allow code which uses
  589. the C<warnings> pragma to control the warning behavior of $^W-type
  590. code (using a C<local $^W=0>) if it really wants to, but not vice-versa.
  591. =head2 Category Hierarchy
  592. X<warning, categories>
  593. A hierarchy of "categories" have been defined to allow groups of warnings
  594. to be enabled/disabled in isolation.
  595. The current hierarchy is:
  596. all -+
  597. |
  598. +- closure
  599. |
  600. +- deprecated
  601. |
  602. +- exiting
  603. |
  604. +- experimental --+
  605. | |
  606. | +- experimental::autoderef
  607. | |
  608. | +- experimental::bitwise
  609. | |
  610. | +- experimental::const_attr
  611. | |
  612. | +- experimental::lexical_subs
  613. | |
  614. | +- experimental::lexical_topic
  615. | |
  616. | +- experimental::postderef
  617. | |
  618. | +- experimental::re_strict
  619. | |
  620. | +- experimental::refaliasing
  621. | |
  622. | +- experimental::regex_sets
  623. | |
  624. | +- experimental::signatures
  625. | |
  626. | +- experimental::smartmatch
  627. | |
  628. | +- experimental::win32_perlio
  629. |
  630. +- glob
  631. |
  632. +- imprecision
  633. |
  634. +- io ------------+
  635. | |
  636. | +- closed
  637. | |
  638. | +- exec
  639. | |
  640. | +- layer
  641. | |
  642. | +- newline
  643. | |
  644. | +- pipe
  645. | |
  646. | +- syscalls
  647. | |
  648. | +- unopened
  649. |
  650. +- locale
  651. |
  652. +- misc
  653. |
  654. +- missing
  655. |
  656. +- numeric
  657. |
  658. +- once
  659. |
  660. +- overflow
  661. |
  662. +- pack
  663. |
  664. +- portable
  665. |
  666. +- recursion
  667. |
  668. +- redefine
  669. |
  670. +- redundant
  671. |
  672. +- regexp
  673. |
  674. +- severe --------+
  675. | |
  676. | +- debugging
  677. | |
  678. | +- inplace
  679. | |
  680. | +- internal
  681. | |
  682. | +- malloc
  683. |
  684. +- signal
  685. |
  686. +- substr
  687. |
  688. +- syntax --------+
  689. | |
  690. | +- ambiguous
  691. | |
  692. | +- bareword
  693. | |
  694. | +- digit
  695. | |
  696. | +- illegalproto
  697. | |
  698. | +- parenthesis
  699. | |
  700. | +- precedence
  701. | |
  702. | +- printf
  703. | |
  704. | +- prototype
  705. | |
  706. | +- qw
  707. | |
  708. | +- reserved
  709. | |
  710. | +- semicolon
  711. |
  712. +- taint
  713. |
  714. +- threads
  715. |
  716. +- uninitialized
  717. |
  718. +- unpack
  719. |
  720. +- untie
  721. |
  722. +- utf8 ----------+
  723. | |
  724. | +- non_unicode
  725. | |
  726. | +- nonchar
  727. | |
  728. | +- surrogate
  729. |
  730. +- void
  731. Just like the "strict" pragma any of these categories can be combined
  732. use warnings qw(void redefine);
  733. no warnings qw(io syntax untie);
  734. Also like the "strict" pragma, if there is more than one instance of the
  735. C<warnings> pragma in a given scope the cumulative effect is additive.
  736. use warnings qw(void); # only "void" warnings enabled
  737. ...
  738. use warnings qw(io); # only "void" & "io" warnings enabled
  739. ...
  740. no warnings qw(void); # only "io" warnings enabled
  741. To determine which category a specific warning has been assigned to see
  742. L<perldiag>.
  743. Note: Before Perl 5.8.0, the lexical warnings category "deprecated" was a
  744. sub-category of the "syntax" category. It is now a top-level category
  745. in its own right.
  746. Note: Before 5.21.0, the "missing" lexical warnings category was
  747. internally defined to be the same as the "uninitialized" category. It
  748. is now a top-level category in its own right.
  749. =head2 Fatal Warnings
  750. X<warning, fatal>
  751. The presence of the word "FATAL" in the category list will escalate
  752. warnings in those categories into fatal errors in that lexical scope.
  753. B<NOTE:> FATAL warnings should be used with care, particularly
  754. C<< FATAL => 'all' >>.
  755. Libraries using L<warnings::warn|/FUNCTIONS> for custom warning categories
  756. generally don't expect L<warnings::warn|/FUNCTIONS> to be fatal and can wind up
  757. in an unexpected state as a result. For XS modules issuing categorized
  758. warnings, such unanticipated exceptions could also expose memory leak bugs.
  759. Moreover, the Perl interpreter itself has had serious bugs involving
  760. fatalized warnings. For a summary of resolved and unresolved problems as
  761. of January 2015, please see
  762. L<this perl5-porters post|http://www.nntp.perl.org/group/perl.perl5.porters/2015/01/msg225235.html>.
  763. While some developers find fatalizing some warnings to be a useful
  764. defensive programming technique, using C<< FATAL => 'all' >> to fatalize
  765. all possible warning categories -- including custom ones -- is particularly
  766. risky. Therefore, the use of C<< FATAL => 'all' >> is
  767. L<discouraged|perlpolicy/discouraged>.
  768. The L<strictures|strictures/VERSION-2> module on CPAN offers one example of
  769. a warnings subset that the module's authors believe is relatively safe to
  770. fatalize.
  771. B<NOTE:> users of FATAL warnings, especially those using
  772. C<< FATAL => 'all' >>, should be fully aware that they are risking future
  773. portability of their programs by doing so. Perl makes absolutely no
  774. commitments to not introduce new warnings or warnings categories in the
  775. future; indeed, we explicitly reserve the right to do so. Code that may
  776. not warn now may warn in a future release of Perl if the Perl5 development
  777. team deems it in the best interests of the community to do so. Should code
  778. using FATAL warnings break due to the introduction of a new warning we will
  779. NOT consider it an incompatible change. Users of FATAL warnings should
  780. take special caution during upgrades to check to see if their code triggers
  781. any new warnings and should pay particular attention to the fine print of
  782. the documentation of the features they use to ensure they do not exploit
  783. features that are documented as risky, deprecated, or unspecified, or where
  784. the documentation says "so don't do that", or anything with the same sense
  785. and spirit. Use of such features in combination with FATAL warnings is
  786. ENTIRELY AT THE USER'S RISK.
  787. The following documentation describes how to use FATAL warnings but the
  788. perl5 porters strongly recommend that you understand the risks before doing
  789. so, especially for library code intended for use by others, as there is no
  790. way for downstream users to change the choice of fatal categories.
  791. In the code below, the use of C<time>, C<length>
  792. and C<join> can all produce a C<"Useless use of xxx in void context">
  793. warning.
  794. use warnings;
  795. time;
  796. {
  797. use warnings FATAL => qw(void);
  798. length "abc";
  799. }
  800. join "", 1,2,3;
  801. print "done\n";
  802. When run it produces this output
  803. Useless use of time in void context at fatal line 3.
  804. Useless use of length in void context at fatal line 7.
  805. The scope where C<length> is used has escalated the C<void> warnings
  806. category into a fatal error, so the program terminates immediately when it
  807. encounters the warning.
  808. To explicitly turn off a "FATAL" warning you just disable the warning
  809. it is associated with. So, for example, to disable the "void" warning
  810. in the example above, either of these will do the trick:
  811. no warnings qw(void);
  812. no warnings FATAL => qw(void);
  813. If you want to downgrade a warning that has been escalated into a fatal
  814. error back to a normal warning, you can use the "NONFATAL" keyword. For
  815. example, the code below will promote all warnings into fatal errors,
  816. except for those in the "syntax" category.
  817. use warnings FATAL => 'all', NONFATAL => 'syntax';
  818. As of Perl 5.20, instead of C<< use warnings FATAL => 'all'; >> you can
  819. use:
  820. use v5.20; # Perl 5.20 or greater is required for the following
  821. use warnings 'FATAL'; # short form of "use warnings FATAL => 'all';"
  822. If you want your program to be compatible with versions of Perl before
  823. 5.20, you must use C<< use warnings FATAL => 'all'; >> instead. (In
  824. previous versions of Perl, the behavior of the statements
  825. C<< use warnings 'FATAL'; >>, C<< use warnings 'NONFATAL'; >> and
  826. C<< no warnings 'FATAL'; >> was unspecified; they did not behave as if
  827. they included the C<< => 'all' >> portion. As of 5.20, they do.)
  828. =head2 Reporting Warnings from a Module
  829. X<warning, reporting> X<warning, registering>
  830. The C<warnings> pragma provides a number of functions that are useful for
  831. module authors. These are used when you want to report a module-specific
  832. warning to a calling module has enabled warnings via the C<warnings>
  833. pragma.
  834. Consider the module C<MyMod::Abc> below.
  835. package MyMod::Abc;
  836. use warnings::register;
  837. sub open {
  838. my $path = shift;
  839. if ($path !~ m#^/#) {
  840. warnings::warn("changing relative path to /var/abc")
  841. if warnings::enabled();
  842. $path = "/var/abc/$path";
  843. }
  844. }
  845. 1;
  846. The call to C<warnings::register> will create a new warnings category
  847. called "MyMod::Abc", i.e. the new category name matches the current
  848. package name. The C<open> function in the module will display a warning
  849. message if it gets given a relative path as a parameter. This warnings
  850. will only be displayed if the code that uses C<MyMod::Abc> has actually
  851. enabled them with the C<warnings> pragma like below.
  852. use MyMod::Abc;
  853. use warnings 'MyMod::Abc';
  854. ...
  855. abc::open("../fred.txt");
  856. It is also possible to test whether the pre-defined warnings categories are
  857. set in the calling module with the C<warnings::enabled> function. Consider
  858. this snippet of code:
  859. package MyMod::Abc;
  860. sub open {
  861. if (warnings::enabled("deprecated")) {
  862. warnings::warn("deprecated",
  863. "open is deprecated, use new instead");
  864. }
  865. new(@_);
  866. }
  867. sub new
  868. ...
  869. 1;
  870. The function C<open> has been deprecated, so code has been included to
  871. display a warning message whenever the calling module has (at least) the
  872. "deprecated" warnings category enabled. Something like this, say.
  873. use warnings 'deprecated';
  874. use MyMod::Abc;
  875. ...
  876. MyMod::Abc::open($filename);
  877. Either the C<warnings::warn> or C<warnings::warnif> function should be
  878. used to actually display the warnings message. This is because they can
  879. make use of the feature that allows warnings to be escalated into fatal
  880. errors. So in this case
  881. use MyMod::Abc;
  882. use warnings FATAL => 'MyMod::Abc';
  883. ...
  884. MyMod::Abc::open('../fred.txt');
  885. the C<warnings::warnif> function will detect this and die after
  886. displaying the warning message.
  887. The three warnings functions, C<warnings::warn>, C<warnings::warnif>
  888. and C<warnings::enabled> can optionally take an object reference in place
  889. of a category name. In this case the functions will use the class name
  890. of the object as the warnings category.
  891. Consider this example:
  892. package Original;
  893. no warnings;
  894. use warnings::register;
  895. sub new
  896. {
  897. my $class = shift;
  898. bless [], $class;
  899. }
  900. sub check
  901. {
  902. my $self = shift;
  903. my $value = shift;
  904. if ($value % 2 && warnings::enabled($self))
  905. { warnings::warn($self, "Odd numbers are unsafe") }
  906. }
  907. sub doit
  908. {
  909. my $self = shift;
  910. my $value = shift;
  911. $self->check($value);
  912. # ...
  913. }
  914. 1;
  915. package Derived;
  916. use warnings::register;
  917. use Original;
  918. our @ISA = qw( Original );
  919. sub new
  920. {
  921. my $class = shift;
  922. bless [], $class;
  923. }
  924. 1;
  925. The code below makes use of both modules, but it only enables warnings from
  926. C<Derived>.
  927. use Original;
  928. use Derived;
  929. use warnings 'Derived';
  930. my $a = Original->new();
  931. $a->doit(1);
  932. my $b = Derived->new();
  933. $a->doit(1);
  934. When this code is run only the C<Derived> object, C<$b>, will generate
  935. a warning.
  936. Odd numbers are unsafe at main.pl line 7
  937. Notice also that the warning is reported at the line where the object is first
  938. used.
  939. When registering new categories of warning, you can supply more names to
  940. warnings::register like this:
  941. package MyModule;
  942. use warnings::register qw(format precision);
  943. ...
  944. warnings::warnif('MyModule::format', '...');
  945. =head1 FUNCTIONS
  946. =over 4
  947. =item use warnings::register
  948. Creates a new warnings category with the same name as the package where
  949. the call to the pragma is used.
  950. =item warnings::enabled()
  951. Use the warnings category with the same name as the current package.
  952. Return TRUE if that warnings category is enabled in the calling module.
  953. Otherwise returns FALSE.
  954. =item warnings::enabled($category)
  955. Return TRUE if the warnings category, C<$category>, is enabled in the
  956. calling module.
  957. Otherwise returns FALSE.
  958. =item warnings::enabled($object)
  959. Use the name of the class for the object reference, C<$object>, as the
  960. warnings category.
  961. Return TRUE if that warnings category is enabled in the first scope
  962. where the object is used.
  963. Otherwise returns FALSE.
  964. =item warnings::fatal_enabled()
  965. Return TRUE if the warnings category with the same name as the current
  966. package has been set to FATAL in the calling module.
  967. Otherwise returns FALSE.
  968. =item warnings::fatal_enabled($category)
  969. Return TRUE if the warnings category C<$category> has been set to FATAL in
  970. the calling module.
  971. Otherwise returns FALSE.
  972. =item warnings::fatal_enabled($object)
  973. Use the name of the class for the object reference, C<$object>, as the
  974. warnings category.
  975. Return TRUE if that warnings category has been set to FATAL in the first
  976. scope where the object is used.
  977. Otherwise returns FALSE.
  978. =item warnings::warn($message)
  979. Print C<$message> to STDERR.
  980. Use the warnings category with the same name as the current package.
  981. If that warnings category has been set to "FATAL" in the calling module
  982. then die. Otherwise return.
  983. =item warnings::warn($category, $message)
  984. Print C<$message> to STDERR.
  985. If the warnings category, C<$category>, has been set to "FATAL" in the
  986. calling module then die. Otherwise return.
  987. =item warnings::warn($object, $message)
  988. Print C<$message> to STDERR.
  989. Use the name of the class for the object reference, C<$object>, as the
  990. warnings category.
  991. If that warnings category has been set to "FATAL" in the scope where C<$object>
  992. is first used then die. Otherwise return.
  993. =item warnings::warnif($message)
  994. Equivalent to:
  995. if (warnings::enabled())
  996. { warnings::warn($message) }
  997. =item warnings::warnif($category, $message)
  998. Equivalent to:
  999. if (warnings::enabled($category))
  1000. { warnings::warn($category, $message) }
  1001. =item warnings::warnif($object, $message)
  1002. Equivalent to:
  1003. if (warnings::enabled($object))
  1004. { warnings::warn($object, $message) }
  1005. =item warnings::register_categories(@names)
  1006. This registers warning categories for the given names and is primarily for
  1007. use by the warnings::register pragma.
  1008. =back
  1009. See also L<perlmodlib/Pragmatic Modules> and L<perldiag>.
  1010. =cut
  1011. # ex: set ro: