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

📄 errorhandler.pm

📁 1. 记录每个帖子的访问人情况
💻 PM
字号:
# Copyright 2001-2005 Six Apart.# SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS## $Id: ErrorHandler.pm 10197 2005-03-09 00:27:57Z ezra $package MT::ErrorHandler;use strict;use vars qw( $ERROR );sub new    { bless {}, shift }sub error  {    my $msg = $_[1] || '';    $msg .= "\n" unless $msg =~ /\n$/;    if (ref($_[0])) {        $_[0]->{_errstr} = $msg;    } else {        $ERROR = $msg;    }    return; }sub errstr { ref($_[0]) ? $_[0]->{_errstr} : $ERROR }1;__END__=head1 NAMEMT::ErrorHandler - MT error handling=head1 SYNOPSIS    package Foo;    use MT::ErrorHandler;    @Foo::ISA = qw( MT::ErrorHandler );    sub class_method {        my $class = shift;        ...        return $class->error("Help!")            unless $continue;    }    sub object_method {        my $obj = shift;        ...        return $obj->error("I am no more")            unless $continue;    }    package main;    use Foo;    Foo->class_method or die Foo->errstr;    my $foo = Foo->new;    $foo->object_method or die $foo->errstr;=head1 DESCRIPTIONI<MT::ErrorHandler> provides an error-handling mechanism for all <MT>modules/classes. It is meant to be used as a base class for classes that wishto use its error-handling methods: derived classes use its two methods,I<error> and I<errstr>, to communicate error messages back to the callingprogram.On failure (for whatever reason), a subclass should call I<error> and returnto the caller; I<error> itself sets the error message internally, then returnsC<undef>. This has the effect of the method internally, then returns C<undef>.This has the effect of the method that failed returning C<undef> to thecaller. The caller should check for errors by checking for a return value ofC<undef>, and in this case should call I<errstr> to get the value of the errormessage. Note that calling I<errstr> when an error has not occurred isundefined behavior and will I<rarely> do what you want.As demonstrated in the I<SYNOPSIS> (above), I<error> and I<errstr> work bothas class methods and as object methods.=head1 USAGE=head2 Class->error($message)=head2 $object->error($message)Sets the error message for either the class I<Class> or the objectI<$object> to the message I<$message>. Returns C<undef>.=head2 Class->errstr=head2 $object->errstrAccesses the last error message set in the class I<Class> or theobject I<$object>, respectively, and returns that error message.=head1 AUTHOR & COPYRIGHTSPlease see the I<MT> manpage for author, copyright, and license information.=cut

⌨️ 快捷键说明

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