3 package Pod::Simple::Debug;
12 ($variable, $value) = @_[1,2];
14 ($variable, $value) = ($value, $variable)
15 if defined $value and ref($value) eq 'SCALAR'
16 and not(defined $variable and ref($variable) eq 'SCALAR')
17 ; # tolerate getting it backwards
19 unless( defined $variable and ref($variable) eq 'SCALAR') {
21 Carp::croak("Usage:\n use Pod::Simple::Debug (NUMVAL)\nor"
22 . "\n use Pod::Simple::Debug (\\\$var, STARTNUMVAL)\nAborting");
26 Carp::croak("Usage:\n use Pod::Simple::Debug (NUMVAL)\nor"
27 . "\n use Pod::Simple::Debug (\\\$var, STARTNUMVAL)\nAborting");
30 if( defined &Pod::Simple::DEBUG ) {
32 Carp::croak("It's too late to call Pod::Simple::Debug -- "
33 . "Pod::Simple has already loaded\nAborting");
36 $value = 0 unless defined $value;
38 unless($value =~ m/^-?\d+$/) {
40 Carp::croak( "$value isn't a numeric value."
41 . "\nUsage:\n use Pod::Simple::Debug (NUMVAL)\nor"
42 . "\n use Pod::Simple::Debug (\\\$var, STARTNUMVAL)\nAborting");
45 if( defined $variable ) {
46 # make a not-really-constant
47 *Pod::Simple::DEBUG = sub () { $$variable } ;
49 print "# Starting Pod::Simple::DEBUG = non-constant $variable with val $value\n";
51 *Pod::Simple::DEBUG = eval " sub () { $value } ";
52 print "# Starting Pod::Simple::DEBUG = $value\n";
66 Pod::Simple::Debug -- put Pod::Simple into trace/debug mode
70 use Pod::Simple::Debug (5); # or some integer
75 use Pod::Simple::Debug (\$debuglevel, 0);
76 ...some stuff that uses Pod::Simple to do stuff, but which
77 you don't want debug output from...
80 ...some stuff that uses Pod::Simple to do stuff, but which
81 you DO want debug output from...
87 This is an internal module for controlling the debug level (a.k.a. trace
88 level) of Pod::Simple. This is of interest only to Pod::Simple
94 Note that you should load this module I<before> loading Pod::Simple (or
95 any Pod::Simple-based class). If you try loading Pod::Simple::Debug
96 after &Pod::Simple::DEBUG is already defined, Pod::Simple::Debug will
97 throw a fatal error to the effect that
98 "it's s too late to call Pod::Simple::Debug".
100 Note that the C<use Pod::Simple::Debug (\$x, I<somenum>)> mode will make
101 Pod::Simple (et al) run rather slower, since &Pod::Simple::DEBUG won't
102 be a constant sub anymore, and so Pod::Simple (et al) won't compile with
110 use Pod::Simple::Debug (5); # or some integer
112 is basically equivalent to:
114 BEGIN { sub Pod::Simple::DEBUG () {5} } # or some integer
119 use Pod::Simple::Debug (\$debug_level,0); # or some integer
121 is basically equivalent to this:
124 BEGIN { $debug_level = 0 }
125 BEGIN { sub Pod::Simple::DEBUG () { $debug_level }
132 The article "Constants in Perl", in I<The Perl Journal> issue
133 21. See L<http://interglacial.com/tpj/21/>
135 =head1 COPYRIGHT AND DISCLAIMERS
137 Copyright (c) 2002 Sean M. Burke. All rights reserved.
139 This library is free software; you can redistribute it and/or modify it
140 under the same terms as Perl itself.
142 This program is distributed in the hope that it will be useful, but
143 without any warranty; without even the implied warranty of
144 merchantability or fitness for a particular purpose.
148 Sean M. Burke C<sburke@cpan.org>