To make it global beyond "within the current package":

sub ::DEBUG() { 1; } # Example use: DebugDump( \%hash ) if ::DEBUG();

As for how to do this in Apache, I'd probably just make "use DEBUG;" do this for you and then you can tell Apache to load the DEBUG module when you want this.

Update: But you'll want sub ::DEBUG() { 0; } when you don't want debugging so you probably need two different ways to "use DEBUG". You could have "use DEBUG;" turn on debugging (for easy use in an Apache config). Then "use DEBUG qw/inherit off/;" would only define ::DEBUG() if it hadn't already been defined (in which case it would define it as 0 or 1, depending on whether 'off' or 'on' was the second argument). So any code that uses ::DEBUG() would have the "use DEBUG qw/inherit off/;" near the top so that ::DEBUG() wouldn't try to call a non-existant subroutine.

package DEBUG; use strict; sub import { my $pkg= shift @_; my $default= 1; if( @_ && 'inherit' eq $_[0] ) { return if defined \&::DEBUG; shift @_; $default= 0; } if( @_ && $_[0] =~ /^(on|off)$/ ) { $default= 'on' eq $_[0] ? 1 : 0; shift @_; } if( @_ ) { require Carp; Carp::croak( "Usage: use DEBUG ['inherit',] ['on'|'off'];" ); } eval "sub ::DEBUG() { $default; }; 1" or die $@; } sub unimport { if( 2 < @_ || 2 == @_ && 'inherit' ne $_[1] ) { require Carp; Carp::croak( "Usage: no DEBUG ['inherit'];" ); } import(@_,'off'); }

- tye        


In reply to Re: DEBUG redux (use, ::) by tye
in thread DEBUG redux by cutlass2006

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.