⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debug.pm

📁 1. 记录每个帖子的访问人情况
💻 PM
字号:
#!/usr/local/bin/perl -w## $Id: Debug.pm,v 1.12 1997/12/02 13:22:52 aas Exp $#package LWP::Debug;=head1 NAMELWP::Debug - debug routines for the libwww-perl library=head1 SYNOPSIS use LWP::Debug qw(+ -conns); # Used internally in the library LWP::Debug::trace('send()'); LWP::Debug::debug('url ok'); LWP::Debug::conns("read $n bytes: $data");=head1 DESCRIPTIONLWP::Debug provides tracing facilities. The trace(), debug() andconns() function are called within the library and they loginformation at increasing levels of detail. Which level of detail isactually printed is controlled with the C<level()> function.The following functions are available:=over 4=item level(...)The C<level()> function controls the level of detail beinglogged. Passing '+' or '-' indicates full and no loggingrespectively. Inidividual levels can switched on and of by passing thename of the level with a '+' or '-' prepended.  The levels are:  trace   : trace function calls  debug   : print debug messages  conns   : show all data transfered over the connectionsThe LWP::Debug module provide a special import() method that allowsyou to pass the level() arguments with initial use statement.  If ause argument start with '+' or '-' then it is passed to the levelfunction, else the name is exported as usual.  The following twostatements are thus equivalent (if you ignore that the second pollutesyour namespace):  use LWP::Debug qw(+);  use LWP::Debug qw(level); level('+');=item trace($msg)The C<trace()> function is used for tracing functioncalls. The package and calling subroutine name isprinted along with the passed argument. This shouldbe called at the start of every major function.=item debug($msg)The C<debug()> function is used for high-granularityreporting of state in functions.=item conns($msg)The C<conns()> function is used to show data beingtransferred over the connections. This may generateconsiderable output.=back=cutrequire Exporter;@ISA = qw(Exporter);@EXPORT_OK = qw(level trace debug conns);use Carp ();my @levels = qw(trace debug conns);%current_level = ();sub import{    my $pack = shift;    my $callpkg = caller(0);    my @symbols = ();    my @levels = ();    for (@_) {	if (/^[-+]/) {	    push(@levels, $_);	} else {	    push(@symbols, $_);	}    }    Exporter::export($pack, $callpkg, @symbols);    level(@levels);}sub level{    for (@_) {	if ($_ eq '+') {              # all on	    # switch on all levels	    %current_level = map { $_ => 1 } @levels;	} elsif ($_ eq '-') {           # all off	    %current_level = ();	} elsif (/^([-+])(\w+)$/) {	    $current_level{$2} = $1 eq '+';	} else {	    Carp::croak("Illegal level format $_");	}    }}sub trace  { _log(@_) if $current_level{'trace'}; }sub debug  { _log(@_) if $current_level{'debug'}; }sub conns  { _log(@_) if $current_level{'conns'}; }sub _log{    my $msg = shift;    $msg .= "\n" unless $msg =~ /\n$/;  # ensure trailing "\n"    my($package,$filename,$line,$sub) = caller(2);    print STDERR "$sub: $msg";}1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -