Skip Menu |

This queue is for tickets about the Class-Autouse CPAN distribution.

Report information
The Basics
Id: 18545
Status: resolved
Priority: 0/
Queue: Class-Autouse

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: 1.24
Fixed in: (no value)



Subject: $DEBUG bugs.
There are two problems with $DEBUG. 1) If it is set to a false value debugging will be turned on. This is contrary to the docs and common sense. 2) $DEBUG should be set in a BEGIN block in the SYNOPSIS so it is set before the use Class::Autouse happens. Patch attached.
Subject: DEBUG.patch
Tue Apr 4 19:59:01 PDT 2006 Michael G Schwern <schwern@pobox.com> * DEBUG bugs diff -rN -u old-Class-Autouse-1.24/lib/Class/Autouse.pm new-Class-Autouse-1.24/lib/Class/Autouse.pm --- old-Class-Autouse-1.24/lib/Class/Autouse.pm 2006-04-04 19:59:58.000000000 -0700 +++ new-Class-Autouse-1.24/lib/Class/Autouse.pm 2006-04-04 19:59:58.000000000 -0700 @@ -14,7 +14,7 @@ # to be optimised out at compile time if not needed. use vars qw{$DEBUG}; use constant DEBUG => $DEBUG; -print "Class::Autouse::autoload -> Debugging Activated.\n" if defined DEBUG; +print "Class::Autouse::autoload -> Debugging Activated.\n" if DEBUG; # Become an exporter so we don't get complaints when we act as a pragma. # I don't fully understand the reason for this, but it works and I can't @@ -75,7 +75,7 @@ # Developer mode flag. # Cannot be turned off once turned on. sub devel { - _debug(\@_, 1) if defined DEBUG; + _debug(\@_, 1) if DEBUG; # Enable if not already return 1 if $DEVEL; @@ -94,7 +94,7 @@ # The process here is to replace the &UNIVERSAL::AUTOLOAD sub # ( which is just a dummy by default ) with a flexible class loader. sub superloader { - _debug(\@_, 1) if defined DEBUG; + _debug(\@_, 1) if DEBUG; unless ( $SUPERLOAD ) { # Overwrite UNIVERSAL::AUTOLOAD and catch any @@ -121,7 +121,7 @@ # Ignore calls with no arguments return 1 unless @_; - _debug(\@_) if defined DEBUG; + _debug(\@_) if DEBUG; foreach my $class ( grep { $_ } @_ ) { # Control flag handling @@ -180,7 +180,7 @@ # Completely load a class ( The class and all its dependencies ). sub load { - _debug(\@_, 1) if defined DEBUG; + _debug(\@_, 1) if DEBUG; my $class = $_[1] or _cry('No class name specified to load'); return 1 if $LOADED{$class}; @@ -209,7 +209,7 @@ # Is a particular class installed in out @INC somewhere # OR is it loaded in our program already sub class_exists { - _debug(\@_, 1) if defined DEBUG; + _debug(\@_, 1) if DEBUG; _namespace_occupied($_[1]) or _file_exists($_[1]); } @@ -219,7 +219,7 @@ # Returns 0 if the class is not loaded ( or autouse'd ) # Returns 1 if the class can be used. sub can_call_methods { - _debug(\@_, 1) if defined DEBUG; + _debug(\@_, 1) if DEBUG; _namespace_occupied($_[1]) or exists $INC{_class_file($_[1])}; } @@ -228,7 +228,7 @@ # Autouse not only a class, but all others below it. sub autouse_recursive { - _debug(\@_, 1) if defined DEBUG; + _debug(\@_, 1) if DEBUG; # Just load if in devel mode return Class::Autouse->load_recursive($_[1]) if $DEVEL; @@ -242,7 +242,7 @@ # Load not only a class and all others below it sub load_recursive { - _debug(\@_, 1) if defined DEBUG; + _debug(\@_, 1) if DEBUG; # Load the parent class, and its children foreach ( $_[1], _child_classes($_[1]) ) { @@ -264,7 +264,7 @@ # Get's linked via the symbol table to any AUTOLOADs are required sub _AUTOLOAD { - _debug(\@_, 0, ", AUTOLOAD = '$Class::Autouse::AUTOLOAD'") if defined DEBUG; + _debug(\@_, 0, ", AUTOLOAD = '$Class::Autouse::AUTOLOAD'") if DEBUG; # Loop detection ( Just in case ) my $method = $Class::Autouse::AUTOLOAD or _cry('Missing method name'); @@ -296,7 +296,7 @@ # This just handles the call and does nothing sub _DESTROY { - _debug(\@_) if defined DEBUG; + _debug(\@_) if DEBUG; } @@ -358,7 +358,7 @@ # Load a single class sub _load ($) { - _debug(\@_) if defined DEBUG; + _debug(\@_) if DEBUG; # Don't attempt to load special classes my $class = shift or _cry('Did not specify a class to load'); @@ -386,7 +386,7 @@ } # Load the file - print _call_depth(1) . " Class::Autouse::load -> Loading in $file\n" if defined DEBUG; + print _call_depth(1) . " Class::Autouse::load -> Loading in $file\n" if DEBUG; eval { CORE::require($file); }; @@ -401,7 +401,7 @@ # Find all the child classes for a parent class. # Returns in the list context. sub _child_classes ($) { - _debug(\@_) if defined DEBUG; + _debug(\@_) if DEBUG; # Find where it is in @INC my $base_file = _class_file(shift); @@ -463,7 +463,7 @@ # Does a class or file exists somewhere in our include path. For # convenience, returns the unresolved file name ( even if passed a class ) sub _file_exists ($) { - _debug(\@_) if defined DEBUG; + _debug(\@_) if DEBUG; # What are we looking for? my $file = shift or return undef; @@ -482,7 +482,7 @@ # Is a namespace occupied by anything significant sub _namespace_occupied ($) { - _debug(\@_) if defined DEBUG; + _debug(\@_) if DEBUG; # Handle the most likely case my $class = shift or return undef; @@ -507,7 +507,7 @@ # Establish our call depth sub _call_depth { my $spaces = shift; - if ( defined DEBUG and ! $spaces ) { _debug(\@_) } + if ( DEBUG and ! $spaces ) { _debug(\@_) } # Search up the caller stack to find the first call that isn't us. my $level = 0; @@ -526,7 +526,7 @@ # Die gracefully sub _cry { - _debug() if defined DEBUG; + _debug() if DEBUG; local $Carp::CarpLevel; $Carp::CarpLevel += _call_depth(); Carp::croak( $_[0] ); @@ -534,7 +534,7 @@ # Adaptive debug print generation BEGIN { - eval <<'END_DEBUG' if defined DEBUG; + eval <<'END_DEBUG' if DEBUG; sub _debug { my $args = shift; @@ -600,7 +600,7 @@ =head1 SYNOPSIS # Debugging (if you go that way) must be set before the first use - $Class::Autouse::DEBUG = 1; + BEGIN { $Class::Autouse::DEBUG = 1; } # Load a class on method call use Class::Autouse;