1
2require 5;
3package Pod::Simple::Debug;
4use strict;
5use vars qw($VERSION );
6$VERSION = '3.28';
7
8sub import {
9  my($value,$variable);
10
11  if(@_ == 2) {
12    $value = $_[1];
13  } elsif(@_ == 3) {
14    ($variable, $value) = @_[1,2];
15
16    ($variable, $value) = ($value, $variable)
17       if     defined $value    and ref($value)    eq 'SCALAR'
18      and not(defined $variable and ref($variable) eq 'SCALAR')
19    ; # tolerate getting it backwards
20
21    unless( defined $variable and ref($variable) eq 'SCALAR') {
22      require Carp;
23      Carp::croak("Usage:\n use Pod::Simple::Debug (NUMVAL)\nor"
24                . "\n use Pod::Simple::Debug (\\\$var, STARTNUMVAL)\nAborting");
25    }
26  } else {
27    require Carp;
28    Carp::croak("Usage:\n use Pod::Simple::Debug (NUMVAL)\nor"
29                    . "\n use Pod::Simple::Debug (\\\$var, STARTNUMVAL)\nAborting");
30  }
31
32  if( defined &Pod::Simple::DEBUG ) {
33    require Carp;
34    Carp::croak("It's too late to call Pod::Simple::Debug -- "
35              . "Pod::Simple has already loaded\nAborting");
36  }
37
38  $value = 0 unless defined $value;
39
40  unless($value =~ m/^-?\d+$/) {
41    require Carp;
42    Carp::croak( "$value isn't a numeric value."
43            . "\nUsage:\n use Pod::Simple::Debug (NUMVAL)\nor"
44                    . "\n use Pod::Simple::Debug (\\\$var, STARTNUMVAL)\nAborting");
45  }
46
47  if( defined $variable ) {
48    # make a not-really-constant
49    *Pod::Simple::DEBUG = sub () { $$variable } ;
50    $$variable = $value;
51    print "# Starting Pod::Simple::DEBUG = non-constant $variable with val $value\n";
52  } else {
53    *Pod::Simple::DEBUG = eval " sub () { $value } ";
54    print "# Starting Pod::Simple::DEBUG = $value\n";
55  }
56
57  require Pod::Simple;
58  return;
59}
60
611;
62
63
64__END__
65
66=head1 NAME
67
68Pod::Simple::Debug -- put Pod::Simple into trace/debug mode
69
70=head1 SYNOPSIS
71
72 use Pod::Simple::Debug (5);  # or some integer
73
74Or:
75
76 my $debuglevel;
77 use Pod::Simple::Debug (\$debuglevel, 0);
78 ...some stuff that uses Pod::Simple to do stuff, but which
79  you don't want debug output from...
80
81 $debug_level = 4;
82 ...some stuff that uses Pod::Simple to do stuff, but which
83  you DO want debug output from...
84
85 $debug_level = 0;
86
87=head1 DESCRIPTION
88
89This is an internal module for controlling the debug level (a.k.a. trace
90level) of Pod::Simple.  This is of interest only to Pod::Simple
91developers.
92
93
94=head1 CAVEATS
95
96Note that you should load this module I<before> loading Pod::Simple (or
97any Pod::Simple-based class).  If you try loading Pod::Simple::Debug
98after &Pod::Simple::DEBUG is already defined, Pod::Simple::Debug will
99throw a fatal error to the effect that
100"it's s too late to call Pod::Simple::Debug".
101
102Note that the C<use Pod::Simple::Debug (\$x, I<somenum>)> mode will make
103Pod::Simple (et al) run rather slower, since &Pod::Simple::DEBUG won't
104be a constant sub anymore, and so Pod::Simple (et al) won't compile with
105constant-folding.
106
107
108=head1 GUTS
109
110Doing this:
111
112  use Pod::Simple::Debug (5);  # or some integer
113
114is basically equivalent to:
115
116  BEGIN { sub Pod::Simple::DEBUG () {5} }  # or some integer
117  use Pod::Simple ();
118
119And this:
120
121  use Pod::Simple::Debug (\$debug_level,0);  # or some integer
122
123is basically equivalent to this:
124
125  my $debug_level;
126  BEGIN { $debug_level = 0 }
127  BEGIN { sub Pod::Simple::DEBUG () { $debug_level }
128  use Pod::Simple ();
129
130=head1 SEE ALSO
131
132L<Pod::Simple>
133
134The article "Constants in Perl", in I<The Perl Journal> issue
13521.  See L<http://interglacial.com/tpj/21/>
136
137=head1 SUPPORT
138
139Questions or discussion about POD and Pod::Simple should be sent to the
140pod-people@perl.org mail list. Send an empty email to
141pod-people-subscribe@perl.org to subscribe.
142
143This module is managed in an open GitHub repository,
144L<https://github.com/theory/pod-simple/>. Feel free to fork and contribute, or
145to clone L<git://github.com/theory/pod-simple.git> and send patches!
146
147Patches against Pod::Simple are welcome. Please send bug reports to
148<bug-pod-simple@rt.cpan.org>.
149
150=head1 COPYRIGHT AND DISCLAIMERS
151
152Copyright (c) 2002 Sean M. Burke.
153
154This library is free software; you can redistribute it and/or modify it
155under the same terms as Perl itself.
156
157This program is distributed in the hope that it will be useful, but
158without any warranty; without even the implied warranty of
159merchantability or fitness for a particular purpose.
160
161=head1 AUTHOR
162
163Pod::Simple was created by Sean M. Burke <sburke@cpan.org>.
164But don't bother him, he's retired.
165
166Pod::Simple is maintained by:
167
168=over
169
170=item * Allison Randal C<allison@perl.org>
171
172=item * Hans Dieter Pearcey C<hdp@cpan.org>
173
174=item * David E. Wheeler C<dwheeler@cpan.org>
175
176=back
177
178=cut
179