3 CXGN::Debug - a utility class for handling debug messages
7 Use CXGN::Debug for inserting debugging messages in your code. Example:
12 my $d = CXGN::Debug->new();
16 # use for only a portion of your code
21 The debug messages are printed to STDERR in a terminal context, and to
22 the Apache error log in a mod_perl context.
24 For CXGN objects, you could inherit from CXGN::Debug. Be sure to call
25 __PACKAGE__->SUPER::new() in any constructors that you write, though.
27 =head1 SWITCHING OFF AND ON
29 When a Debug object is created, it sets itself to be either on or off
30 (that is, printing or non-printing) based on:
32 the debug => option to its constructor, if passed
33 or if that is not passed, the CXGN_DEBUG environment variable
34 or if that is not present, the 'debug' setting in the (merged) vhost conf
35 or if that is not present, off.
39 Lukas Mueller and Robert Buels
49 Usage: $d = CXGN::Debug->new();
51 Args: a hash with parameters, currently:
53 calling CXGN::Debug->new( debug=>1) will
54 override the global configuration file
63 my $self = bless {}, $class;
65 my $conf_debug = CXGN
::Config
->load->{debug
};
67 my $initial_debug_setting =
68 defined $opts{debug
} ?
$opts{debug
}
69 : defined $ENV{CXGN_DEBUG
} ?
$ENV{CXGN_DEBUG
}
70 : defined $conf_debug ?
$conf_debug
73 $self->set_debug( $initial_debug_setting );
78 =head2 accessors get_debug(), set_debug()
80 Usage: $d->set_debug(1);
81 Desc: accessors for the debug property.
82 a true value turns debugging on, i.e., debug
83 messages will be printed to either STDERR or
84 the Apache error log (if running in mod_perl).
93 return $self->{debug
};
98 $self->{debug
} = shift;
101 =head2 debug() or d()
103 Usage: $d->d("The value of foo is $foo\n");
104 Desc: A debug message. Note that you have to provide the
106 Ret: nothing meaningful
107 Args: message to print
108 Side Effects: prints message to STDERR. if running under
109 mod_perl, uses log()->debug() method to print
110 the message to the log
112 $d->d('well here we are');
121 if ($self->get_debug()) {
123 $message .= "\n" unless $message =~ /\n$/;
126 if ($ENV{MOD_PERL
}) {
127 require Apache2
::RequestUtil
128 or die "must have Apache2::RequestUtil installed to use CXGN::Debug under mod_perl";
129 my $r= Apache2
::Request
->new();
130 $r->log()->debug($message);