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

📄 callback.pm

📁 1. 记录每个帖子的访问人情况
💻 PM
字号:
# Copyright 2001-2005 Six Apart.# SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS## $Id: Callback.pm 10418 2005-03-17 01:12:00Z bchoate $package MT::Callback;use strict;use MT::ErrorHandler;@MT::Callback::ISA = qw( MT::ErrorHandler );sub new {    my $class = shift;    my ($this) = ref$_[0] ? @_ : {@_};    bless $this, $class;}sub invoke {    my $this = shift;    return $this->{code}->($this, @_);}1;__END__=head1 NAMEMT::Callback - Movable Type wrapper for executable code with error state=head1 SYNOPSIS  $cb = new MT::Callback(<name>, sub { <callback code> } );E<lt>nameE<gt> is a human-readable string which identifies thesurrounding body of code, for example the name of a plugin--the namewill help identify errors in the activity log.=head1 CALLBACK CALLING CONVENTIONSThe parameters passed to each callback routine depends on the operationin questions, as follows:=over 4=item * load(), load_iter()Before loading items from the database, load() and load_iter()call the callback registered as <class>::pre_load, allowing a callbackwriter to munge the arguments before the database iscalled.An example E<lt>classE<gt>::pre_load might be written as follows:    sub pre_load {	my ($eh, $args) = @_;	....    }Each object I<returned> by load() or by an iterator will,before it is returned, be processeed by all callbacks registered asE<lt>classE<gt>::post_load. An example E<lt>classE<gt>::post_loadfunction         sub post_load {	my ($eh, $args, $obj) = @_;        ....    }The C<$args> parameter for both the C<pre_load> and C<post_load>callback is an array reference of all parametersthat were supplied to the load or load_iter methods.=item * save()Callbacks for the save method might be written as follows:    sub pre_save {	my ($eh, $obj, $original) = @_;	....    }    sub post_save {	my ($eh, $obj, $original) = @_;        ....    }By altering the $obj in pre_save, you can affect what data gets storedin the database.By creating pre_save and post_load functions which have inverseeffects on the object, you might be able to store data in the databasein a special form, while keeping the usual in-memory representation.=item * remove()E<lt>classE<gt>::pre_remove and E<lt>classE<gt>::post_removeare called at the very beginning and very end of the respectiveoperations. The callback routine is called as follows:    sub pre_remove {        my ($eh, $obj) = @_;        ....    }The signature for the post_remove operation is the same.E<lt>classE<gt>::pre_remove_all andE<lt>classE<gt>::post_remove_all are called at the very beginning andvery end of the respective operations, with no arguments except theMT::Callback object.=back=head1 ERROR HANDLINGThe first argument to any callback routine is an MT::ErrorHandlerobject. You can use this object to return errors to MT. The errorswill be displayed in the MT Activity Log (accessible from the mainweblog list).To use the error handler object, just use it's error() method:    sub my_callback {	my ($eh, $arg2, $arg3) = @_;		....	if (some_condition) {	    return $eh->error("The foofiddle was invalid.");	} 	...    }=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 + -