Print debugging statement: Difference between revisions

m
→‎{{header|Perl 6}}: visited Rufus Xavier Sarsaparilla and got a pronoun
m (→‎{{header|Perl 6}}: remove unnecessary parenthesis & whitespace)
m (→‎{{header|Perl 6}}: visited Rufus Xavier Sarsaparilla and got a pronoun)
Line 121:
=={{header|Perl 6}}==
{{works with|Rakudo|2019.07.1}}
There isn't anything built-in to do this in Rakudo Perl 6, though isit's pretty easy to cobble something together piggybacking off of the exception system. It would probably be better to instantiate a specific "DEBUG" exception to avoid interfering with other user instantiated ad-hoc exceptions, but for a quick-and-dirty demo, this should suffice.
 
This example will report any payload contents passed to the exception. If you want specific information, it will need to be passed in, though some of it may be determinable through introspection. Reports the file- name and line number where the "debug" call originated and unwinds the call stack to trace through the subroutine calls leading up to it. Will follow the call chain into included files and modules, though calls to the CORE setting and dispatcher are filtered out here to reduce noise.
 
Comments with the files line numbers are added here to make it easier to match up the debug output with the file. Typically you would be editing the file in an editor that provides line numbering so that wouldn't be necessary/helpful.
10,327

edits