LEOCHARRE::Debug - debug sub


LEOCHARRE-Debug documentation Contained in the LEOCHARRE-Debug distribution.

Index


Code Index:

NAME

Top

LEOCHARRE::Debug - debug sub

SYNOPSIS

Top

   use LEOCHARRE::Debug;

   debug('hey there');

   warnf '%s %s %s\n', 'this', 'is', 'a value';

SUBS

Top

Exported.

debug()

Arg is one or more strings to output, prepended with sub name.

warnf()

Works like

   warn sprintf '', @args




CAVEATS

Top

AUTHOR

Top

Leo Charre leocharre at cpan dot org

LICENSE

Top

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License".

DISCLAIMER

Top

This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the "GNU General Public License" for more details.


LEOCHARRE-Debug documentation Contained in the LEOCHARRE-Debug distribution.

package LEOCHARRE::Debug;
use strict;
use Carp;
our $VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /(\d+)/g;



sub import {
   my $caller = scalar(caller);
   no strict 'refs';
   no warnings;   

   # create the variable in caller, 
   # then get a ref to it for debug()
   ### $caller
   my $_flag = 0;
   *{"$caller\:\:DEBUG"} = \$_flag;

   *{"$caller\:\:debug"} = sub { 
      # my $subname = (caller(1))[3] || 'main::debug'; # seems like only reason is if debug() is used in main::debug, then shows  LEOCHARRE::Debug::__ANON__() , of course
      $_flag ? warn( sprintf "%s() @_\n", (caller(1))[3] || 'main::debug' ) : 1
   };
   *{"$caller\::warnf"} = sub { warn( sprintf "%s() @_", (caller(1))[3] || 'main::warnf') };

}







#3 at lib/LEOCHARRE/Debug.pm line 27.




1;

__END__