On Mon, 18 Jun 2001, Doug MacEachern wrote:
> On Sun, 17 Jun 2001, Stas Bekman wrote:
>
> >
> > What do you think about adding some semantics for the debug printing
> > during 'make test'. So users can visually tell warnings from errors, and
> > errors from notice statements.
> >
> > so we can use:
> >
> > mpt_warn("this is a warning");
> > mpt_error("this is an arror");
> > mpt_notice("this is a notice");
> >
> > (mpt stands for mod_perl_test) and
> >
> > sub mpt_error { print "!!!: ", join "\n", @_}
> > sub mpt_warn { print "***: ", join "\n", @_}
> > sub mpt_notice { print "---: ", join "\n", @_}
> >
> > or similar semantics, and the functions could handle the wrapping too (and
> > thus appending the right preamble to the beginning of every line).
> >
> > or may be we want to change the debug prints only for warn/error ones, so
> > the normal printing will stay as it is now.
> >
> > we can also overload these subs with a set of subs which use Curses (for
> > those who have it installed) and have the output colorized like
> > /usr/bin/colorgcc does. The latter uses Term::ANSIColor which seems to
> > come with the core perl (at least 5.6.0, not sure about earlier versions).
> >
> > finally we could ucfirst() the beginning of sentences :)
>
> this would be useful, maybe in its own module ModPerl::Trace that
> exports error(), warning(), notice(), debug(), etc.
Attached the first version of this module. Test with:
$ perl -MModPerl::Trace=error,dumper,warning,notice,debug,todo -lwe \
'error "error"; warning "warning"; notice "notice"; debug "debug"; \
todo "todo"; dumper [1..3]'
I've tried it in the Apache::TestRun and it works, the only thing I'm not
sure about is the need to extend @INC:
package Apache::TestRun;
...
use lib qw(./lib);
use ModPerl::Trace;
...
is this OK? Apache-Test becomes dependant on ModPerl::, or was it
dependant already?
Of course feel free to adjust the colors :)
I've also added the todo() and dumper() methods, which I find useful
during development process.
Another feature that would be nice to add is to be able to overload any of
these subs with NOPS via import(), so for example we could leave the debug
calls around the system and enable them only when we want. Sort of like
Carp.pm does.
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:[EMAIL PROTECTED] http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
package ModPerl::Trace;
use strict;
use Exporter ();
our @ISA = qw(Exporter);
our @EXPORT = qw(warning debug notice error todo dumper);
our $VERSION = '0.01';
use subs qw(warning debug notice error todo dumper);
BEGIN{
eval {require Term::ANSIColor};
use constant HAS_COLOR => $@ ? 0 : 1;
eval {require Data::Dumper};
use constant HAS_DUMPER => $@ ? 0 : 1;
}
my %colors = ();
if (HAS_COLOR) {
%colors =
(
error => Term::ANSIColor::color('bold red'),
warning => Term::ANSIColor::color('blue'),
notice => Term::ANSIColor::color('reset'),
debug => Term::ANSIColor::color('green'),
todo => Term::ANSIColor::color('underline'),
reset => Term::ANSIColor::color('reset'),
);
}
sub c_notice { print STDERR $colors{notice}, join("\n",@_,''), $colors{reset}; }
sub c_error { print STDERR $colors{error}, join("\n",@_,''), $colors{reset}; }
sub c_warning{ print STDERR $colors{warning}, join("\n",@_,''), $colors{reset}; }
sub c_debug { print STDERR $colors{debug}, join("\n",@_,''), $colors{reset}; }
sub c_todo { print STDERR $colors{todo}, join("\n",@_,''), $colors{reset}; }
sub nc_error { print STDERR map {"!!! : $_\n"} @_; }
sub nc_warning{ print STDERR map {"*** : $_\n"} @_; }
sub nc_notice { print STDERR map {" : $_\n"} @_; }
sub nc_debug { print STDERR map {"==> : $_\n"} @_; }
sub nc_todo { print STDERR map {"todo: $_\n"} @_; }
if (HAS_COLOR) {
$Term::ANSIColor::AUTORESET = 1;
*error = *c_error;
*warning = *c_warning;
*notice = *c_notice;
*debug = *c_debug;
*todo = *c_todo;
} else {
*error = *nc_error;
*warning = *nc_warning;
*notice = *nc_notice;
*debug = *nc_debug;
*todo = *nc_todo;
}
sub dumper {
HAS_DUMPER
? print(STDERR Data::Dumper::Dumper(@_))
: error("Install Data::Dumper to use dumper");
}
1;
__END__
=head1 ModPerl::Trace - Helper output generation functions
=head1 SYNOPSIS
use ModPerl::Trace;
error "this is an error";
warning "this is a warning";
notice "this is a notice";
debug "this is a debug";
todo "this is a todo message";
dumper [qw(a b c)];
=head1 DESCRIPTION
This module exports a number of functions that make it easier
generating various diagnostics messages in your programs in a
consistent way and saves some keystrokes as it handles the new lines
and sends the messages to STDERR for you.
warning() for generating warnings, error() for errors, notice() for
normal notices, debug() for debug messages and finally todo() is for
todo items (a reminder). If you have C<Term::ANSIColor> installed the
diagnostic messages will be colorized, otherwise a different prefix
will be used.
dumper() is a shortcut for debug dumping of complex datastructes. This
function is available if you have C<Data::Dumper> installed.
=cut
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]