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