|
NAMEDevel::Messenger - Let Your Code Talk to YouSYNOPSISuse Devel::Messenger qw{note}; # set up localized subroutine local *note = Devel::Messenger::note { output => 'print', level => 2, pkgname => 1, linenumber => 1, wrap => ["<!--", "-->\n"], }; # print a note note "This is a sample note\n"; # print a multipart note note "This is line two. "; note "continue", "This is still line two.\n"; # print if 'level' is high enough note \2, "This is debug level two\n"; DESCRIPTIONDo you want your program to tell you what it is doing? Send this messenger into the abyss of your code to bring back to you all the pertinent information you want.First, set notes in your code, in-line comments that start with "note" instead of "#". # this is an in-line comment (it is boring) note "this is a note (things start getting exciting now)\n"; To keep your program from giving you terrible errors about "note" not being defined, give it something to do. use subs qw{note}; sub note {} Or you could import the slightly more powerful "note" subroutine defined in Devel::Messenger. use Devel::Messenger qw{note}; By itself, "note" does not do anything. Right now, all it is doing is making sure Perl doesn't give you an error message and die. So how do you make Devel::Messenger go and activate these notes? Specify What You Want Your Messenger to DoDevel::Messenger wants to help you and your code talk to each other. It will act as a messenger between you both.First, you tell Devel::Messenger which notes to talk to, and how you want it to return messages to you. Then, it goes off and starts negotiating with your code. Use Devel::Messenger's own "note" subroutine to specify your instructions. local *note = Devel::Messenger::note \%instructions; Your instructions must be in the form of a HASH reference for Devel::Messenger to understand you. You may wish to use an anonymous HASH reference. local *note = Devel::Messenger::note { output => 'print', level => 2, }; Here, we have told our messenger to "print" any notes which are specified as level one or level two, which appear in the current package. When you run your code, Devel::Messenger will look for notes that match your instructions. Any notes that match those criteria will be printed via the Perl function "print". You may also request Devel::Messenger to look for notes in other packages. local *Other::Module::note = Devel::Messenger::note { output => 'print', level => 2, }; If you are going to search for notes in multiple packages, it might be easier to capture the instructions in a SCALAR, then use the SCALAR in several places. my $note = Devel::Messenger::note { output => 'print', level => 2, }; local *note = $note; local *Other::Module::note = $note; You may have noticed that I have been using the Perl function "local" in all my GLOB assignments. This is not necessary. In fact, it can be downright annoying at times. Do it anyway. If you are using the Perl module "warnings", or are running Perl with the "-w" switch, every time you redefine a subroutine, a warning is generated. Using "local" avoids these errors. If you are running any of your code under "mod_perl", having a globally assigned subroutine for debugging can cause other "mod_perl" copies of your code to also be sending you debugging information. That gets nasty. Using "local" avoids this problem. However, when you use "local", you must be careful that your "note" definition stays in scope for as long as you wish it to. Otherwise, Devel::Messenger will forget what it is doing and go back to sleep. In object-oriented programming, you may wish to store your instructions in your object. my $self = bless {}; $self->{note} = Devel::Messenger::note { output => 'print', level => 2, }; $self->{note}->("This is my note\n"); local *note = $self->{note}; note "This is also my note\n"; Nitty-GrittyYour instructions to "Devel::Messenger::note" must be in a HASH reference. The keys of that HASH instruct Devel::Messenger to do different things.
Common Debug LevelsAs explained above, notes can specify what level they are. The level could theoretically be from one all the way up to your integer limit.However, levels could become almost meaningless if we allowed so many different levels. My standard levels are:
AUTHORNathan Gray - kolibrie@southernvirginia.eduCOPYRIGHTDevel::Messenger is Copyright (c) 2001 Nathan Gray. All rights reserved.You may distribute under the terms of either the GNU General Public License, or the Perl Artistic License.
Visit the GSP FreeBSD Man Page Interface. |