Sprocket::Plugin - Base class for Sprocket plugins
use Sprocket qw( Plugin ); use base qw( Sprocket::Plugin ); sub new { shift->SUPER::new( name => 'MyPlugin', @_ ); } sub as_string { __PACKAGE__; } ...
This is a base class for Sprocket plugins. It provides several default methods for easy plugin implementation.
A plugin can define any of the methods below. All are optional, but a plugin should have a conncted and a receive method for it to function. See the Sprocket site for examples. http://sprocket.cc/ Plugins should use the template in the SYNOPSIS.
Also, this module is a subclass of Class::Accessor::Fast, so subclasses of Sprocket::Plugin can create accessors like so (in your new() method):
__PACKAGE__->mk_accessors( qw( foo bar baz ) );
These are methods that can be defined in a plugin for Sprocket server instances
Called with ( $self, $server, $con, $socket ) Defining this method is optional. The default behavior is to accept the connection. You can call $con->reject() or $con->accept() to reject or accept a connection. You can also call $self->take_connection( $con ); in this phase. See Sprocket::Connection for more information on the accept and reject methods.
Called with ( $self, $server, $con, $socket ) This is the last chance for a plugin to take a connection with $self->take_connection( $con ); You should apply your filters for the connection in this method. See Sprocket::Connection for details on how to access the connection's filters.
Called with ( $self, $server, $con, $data ) $data is the data from the filter applied to the connection.
Note: A connection's active time doesn't update automaticly for this event. You can call $con->active(), see Sprocket::Connection.
Called with ( $self, $server, $con, $error ) If error is true, then $operation, $errnum, and $errstr will also be defined after $error. If a connection was closed with $con->close() then $error will be false. If a connection was closed remotely but without an error then $error will be true, but $errnum will be 0. For more details, see ErrorEvent in POE::Wheel::ReadWrite.
Called with ( $self, $server, $operation, $errnum, $errstr ) This is only called when there is an error with the server wheel, like a bind error. ( $errnum will == EADDRINUSE, after: use Errno qw( EADDRINUSE ); ) The default behavior will be to shutdown the server if there is a bind error.
Called with ( $self, $server, $con, $time ) A time out occurred on the connection. This means the $con->active_time + $con->time_out is less than $time. You can choose to $con->close() or not. The default behavior is to close the connection. This event will only occur if you have set a time out with $con->set_time_out( $seconds )
Called with ( $self, $server, $con ) This is currently only called when a soft shutdown is initiated. You should make cleanup arrangements and close the connection asap. The server will wait for all connections to close. See the shutdown command in Sprocket::Server, and Sprocket::Client.
These are methods that can be defined in a plugin for Sprocket client instances
Why is there an accept method for client connections?! Well, good question. This method is here to allow you to set the filters and blocksize using the $con-accept method. See Sprocket::Connection
See local_accept.
See local_connected.
See local_receive.
See local_disconnected. You can call $con->reconnect() to attempt to reconnect to the host.
Called with ( $self, $client, $con ) If a connection wasn't attempted due to a DNS issue, $response_error, and $response_obj from POE::Component::DNS will follow $con. The remote_disconnected event will not be called. You can call $con->reconnect() to attempt to reconnect to the host.
Called with ( $self, $client, $con, $time ) A time out occurred on the connection. This means the $con->active_time + $con->time_out is less than $time. You can choose to $con->close() or not. The default behavior is to close the connection. This event will only occur if you have set a time out with $con->set_time_out( $seconds )
See local_shutdown.
Returns a list of connection ids currently active conenctions taken by the plugin. Use $sprocket->get_connection() to get the connection reference. Note: con_id_list in a scalar context will return an array ref
foreach ( $self->con_id_list ) { if ( my $con = $sprocket->get_connection( $_ ) ) { $con->send( "you are client:".$con->ID ); } }
Assigns the connection to your plugin. Usually done during the accept or connect phase.
Sprocket, Sprocket::Connection, Sprocket::AIO, Sprocket::Server, Sprocket::Client, Sprocket::Local
David Davis <xantus@cpan.org>
Copyright 2006-2007 by David Davis
See Sprocket for license information.
To install Sprocket, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sprocket
CPAN shell
perl -MCPAN -e shell install Sprocket
For more information on module installation, please visit the detailed CPAN module installation guide.