Net::RRP::Response - the base class for the Net::RRP::Response::* classes


Net-RRP documentation Contained in the Net-RRP distribution.

Index


Code Index:

NAME

Top

    Net::RRP::Response - the base class for the Net::RRP::Response::* classes

SYNOPSIS

Top

 use Net::RRP::Response;
 my $response = new Net::RRP::Response ();




DESCRIPTION

Top

This is a base class of all Response::* classes. Child class must overwrite a getCode method and setup own constrains for attributes at setAttribute method. Child classes must named Net::RRP::Response::nNNN, where NNN is a response number.

new

The constructor. You can setup attributes and description. Example:

 use Net::RRP::Response;
 my $response = new Net::RRP::Response ();
 my $otherResponse = new Net::RRP::Response ( attributes  => { qq => 'tt'},
					      description => 'this is a response description' );

newFromException

Construct new response object from exception infomation;

 my $response = newFromException Net::RRP::Response ( new Net::RRP::Exception ( "description", $code ) );

getCode

This method return a code (number) of response. Must be overwrited at child classes. Example:

 my $responseNumber = $response->getCode;

getDescription

Get response description. Example:

 my $description = $response->getDescription();

setDescription

Set response description. Example:

 $response->setDescription ( 'this is a response description' );

getAttribute

Return a named response attribute. Example:

 my $attribute = $response->getAttribute ( 'name' );

setAttribute

Setup a named attribute. Example:

 $response->setAttribute ( 'name' => 'value' );

getAttributes

Get response attributes hash ref. Example:

 my $attributes = $response->getAttributes;
 map { print "$_ = " . $attributes->{$_} } keys %$attributes;

AUTHOR AND COPYRIGHT

Top

SEE ALSO

Top

Net::RRP::Entity(3), Net::RRP::Request(3), Net::RRP::Codec(3), Net::RRP::Exception(3), RFC 2832


Net-RRP documentation Contained in the Net-RRP distribution.
package Net::RRP::Response;

use strict;
$Net::RRP::Response::VERSION = (split " ", '# 	$Id: Response.pm,v 1.6 2000/08/24 14:46:47 mkul Exp $	')[3];

sub new
{
    my $class = shift;
    my %options = @_ ? @_ : ( attributes  => {},
			      description => '' );
    bless { %options }, $class;
}

sub newFromException
{
    my ( $class, $exception ) = @_;
    my $code = $exception->value;
    my $packageName = "Net\:\:RRP\:\:Response\:\:n$code";
    eval "use $packageName;"; die $@ if $@;
    $packageName->new ( description => $exception->text || ' ' );
}

sub getCode
{
    die "Must be implemented at child class";
}

sub getDescription
{
    my $this = shift;
    $this->{description};
}

sub setDescription
{
    my ( $this, $description ) = @_;
    my $old = $this->{description};
    $this->{description} = $description;
    $old;
}

sub getAttribute
{
    my ( $this, $optionName ) = @_;
    $this->{attributes}->{$optionName}
}

sub setAttribute
{
    my ( $this, $optionName, $optionValue ) = @_;
    my $old = $this->{attributes}->{$optionName};
    $this->{attributes}->{$optionName} = $optionValue;
    $old;
}

sub getAttributes
{
    my $this = shift;
    $this->{attributes}
}

1;

__END__