| Net-RRP documentation | Contained in the Net-RRP distribution. |
Net::RRP::Request - rrp request abstraction class
use Net::RRP::Request; my $request = new Net::RRP::Request;
This is a base class for all Request::* classes.
The constructor. You can pass entity && options attributes to this method. Example:
my $request = new Net::RRP::Request ( entity => new Net::RRP::Entity ( .... ),
options => { key => 'value' } );
my $request1 = new Net::RRP::Request ( );
Return a *real* name of this request. You must overwrite this method at child class. Example:
my $requestName = $request->getName(); print STDERR "EntityName is $requestName\n";
Setup the rrp entity for this request. Example:
$request->setEntity ( new Net::RRP::Entity ( ... ) );
Return a entity of this request. Example:
my $entity = $request->getEntity();
Can throw Net::RRP::Exception::MissingRequiredEntity exception
Return a request option by $optionName. Example:
print $request->getOption ( $optionName ); print $request->getOption ( 'ttt' ); # no '-' here
Can throw Net::RRP::Exception::MissingCommandOption() exception.
Set $optionName rrp request option to the $optionValue. Example:
$request->setOption ( $optionName => $optionValue ); $request->setOption ( tt => 'qq' );
Return a hash ref to the request options. Example:
my $options = $request->gtOptions();
map { print "$_ = " . $options->{$_} } keys %$options;
Return a true if response is successfull.
my $protocol = new Net::RRP::Protocol ( .... ); my $request = new Net::RRP::Request::Add ( .... ); $protocol->sendRequest ( $request ); my $response = $protocol->getResponse (); die "error" unless $request->isSuccessResponse ( $response );
Net::RRP::Request (C) Michael Kulakov, Zenon N.S.P. 2000
125124, 19, 1-st Jamskogo polja st,
Moscow, Russian Federation
mkul@cpan.org
All rights reserved.
You may distribute this package under the terms of either the GNU
General Public License or the Artistic License, as specified in the
Perl README file.
Net::RRP::Entity(3), Net::RRP::Response(3), Net::RRP::Codec(3), RFC 2832, Net::RRP::Exception::MissingCommandOption(3), Net::RRP::Exception::MissingRequiredEntity(3)
| Net-RRP documentation | Contained in the Net-RRP distribution. |
package Net::RRP::Request; use strict; use Net::RRP::Exception::MissingCommandOption; use Net::RRP::Exception::MissingRequiredEntity; $Net::RRP::Request::VERSION = (split " ", '# $Id: Request.pm,v 1.4 2000/09/11 15:34:14 mkul Exp $ ')[3];
sub new { my ( $class, %params ) = @_; bless { %params }, $class; }
sub getName { die "Must be implemented at child class"; }
sub setEntity { my ( $this, $entity ) = @_; my $old = $this->{entity}; $this->{entity} = $entity; $old; }
sub getEntity { my $this = shift; $this->{entity} || throw Net::RRP::Exception::MissingRequiredEntity(); }
sub getOption { my ( $this, $optionName ) = @_; $this->{options}->{ lc ( $optionName ) } || throw Net::RRP::Exception::MissingCommandOption(); }
sub setOption { my ( $this, $optionName, $optionValue ) = @_; $optionName = lc ( $optionName ); my $old = $this->{options}->{$optionName}; $this->{options}->{$optionName} = $optionValue; $old; }
sub getOptions { my $this = shift; $this->{options} }
sub isSuccessResponse { my ( $this, $response ) = @_; return 0 unless $response; return { 200 => 1, 220 => 1 }->{ $response->getCode() }; } 1;
__END__