2 package Pod::Simple::Debug;
4 use vars qw($VERSION );
13 ($variable, $value) = @_[1,2];
15 ($variable, $value) = ($value, $variable)
16 if defined $value and ref($value) eq 'SCALAR'
17 and not(defined $variable and ref($variable) eq 'SCALAR')
18 ; # tolerate getting it backwards
20 unless( defined $variable and ref($variable) eq 'SCALAR') {
22 Carp::croak("Usage:\n use Pod::Simple::Debug (NUMVAL)\nor"
23 . "\n use Pod::Simple::Debug (\\\$var, STARTNUMVAL)\nAborting");
27 Carp::croak("Usage:\n use Pod::Simple::Debug (NUMVAL)\nor"
28 . "\n use Pod::Simple::Debug (\\\$var, STARTNUMVAL)\nAborting");
31 if( defined &Pod::Simple::DEBUG ) {
33 Carp::croak("It's too late to call Pod::Simple::Debug -- "
34 . "Pod::Simple has already loaded\nAborting");
37 $value = 0 unless defined $value;
39 unless($value =~ m/^-?\d+$/) {
41 Carp::croak( "$value isn't a numeric value."
42 . "\nUsage:\n use Pod::Simple::Debug (NUMVAL)\nor"
43 . "\n use Pod::Simple::Debug (\\\$var, STARTNUMVAL)\nAborting");
46 if( defined $variable ) {
47 # make a not-really-constant
48 *Pod::Simple::DEBUG = sub () { $$variable } ;
50 print STDERR "# Starting Pod::Simple::DEBUG = non-constant $variable with val $value\n";
52 *Pod::Simple::DEBUG = eval " sub () { $value } ";
53 print STDERR "# Starting Pod::Simple::DEBUG = $value\n";
67 Pod::Simple::Debug -- put Pod::Simple into trace/debug mode
71 use Pod::Simple::Debug (5); # or some integer
76 use Pod::Simple::Debug (\$debuglevel, 0);
77 ...some stuff that uses Pod::Simple to do stuff, but which
78 you don't want debug output from...
81 ...some stuff that uses Pod::Simple to do stuff, but which
82 you DO want debug output from...
88 This is an internal module for controlling the debug level (a.k.a. trace
89 level) of Pod::Simple. This is of interest only to Pod::Simple
95 Note that you should load this module I<before> loading Pod::Simple (or
96 any Pod::Simple-based class). If you try loading Pod::Simple::Debug
97 after &Pod::Simple::DEBUG is already defined, Pod::Simple::Debug will
98 throw a fatal error to the effect that
99 "It's too late to call Pod::Simple::Debug".
101 Note that the C<use Pod::Simple::Debug (\$x, I<somenum>)> mode will make
102 Pod::Simple (et al) run rather slower, since &Pod::Simple::DEBUG won't
103 be a constant sub anymore, and so Pod::Simple (et al) won't compile with
111 use Pod::Simple::Debug (5); # or some integer
113 is basically equivalent to:
115 BEGIN { sub Pod::Simple::DEBUG () {5} } # or some integer
120 use Pod::Simple::Debug (\$debug_level,0); # or some integer
122 is basically equivalent to this:
125 BEGIN { $debug_level = 0 }
126 BEGIN { sub Pod::Simple::DEBUG () { $debug_level }
133 The article "Constants in Perl", in I<The Perl Journal> issue
134 21. See L<http://interglacial.com/tpj/21/>
138 Questions or discussion about POD and Pod::Simple should be sent to the
139 pod-people@perl.org mail list. Send an empty email to
140 pod-people-subscribe@perl.org to subscribe.
142 This module is managed in an open GitHub repository,
143 L<https://github.com/perl-pod/pod-simple/>. Feel free to fork and contribute, or
144 to clone L<git://github.com/perl-pod/pod-simple.git> and send patches!
146 Patches against Pod::Simple are welcome. Please send bug reports to
147 <bug-pod-simple@rt.cpan.org>.
149 =head1 COPYRIGHT AND DISCLAIMERS
151 Copyright (c) 2002 Sean M. Burke.
153 This library is free software; you can redistribute it and/or modify it
154 under the same terms as Perl itself.
156 This program is distributed in the hope that it will be useful, but
157 without any warranty; without even the implied warranty of
158 merchantability or fitness for a particular purpose.
162 Pod::Simple was created by Sean M. Burke <sburke@cpan.org>.
163 But don't bother him, he's retired.
165 Pod::Simple is maintained by:
169 =item * Allison Randal C<allison@perl.org>
171 =item * Hans Dieter Pearcey C<hdp@cpan.org>
173 =item * David E. Wheeler C<dwheeler@cpan.org>