| 1 | package Net::RRP::Response; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | $Net::RRP::Response::VERSION = (split " ", '# $Id: Response.pm,v 1.6 2000/08/24 14:46:47 mkul Exp $ ')[3]; | |||||||||||
| 5 | |||||||||||||
| 6 | =head1 NAME | ||||||||||||
| 7 | |||||||||||||
| 8 | Net::RRP::Response - the base class for the Net::RRP::Response::* classes | ||||||||||||
| 9 | |||||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||||
| 11 | |||||||||||||
| 12 | use Net::RRP::Response; | ||||||||||||
| 13 | my $response = new Net::RRP::Response (); | ||||||||||||
| 14 | |||||||||||||
| 15 | |||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||
| 17 | |||||||||||||
| 18 | This is a base class of all Response::* classes. Child class must overwrite a getCode method and | ||||||||||||
| 19 | setup own constrains for attributes at setAttribute method. Child classes must named | ||||||||||||
| 20 | Net::RRP::Response::nNNN, where NNN is a response number. | ||||||||||||
| 21 | |||||||||||||
| 22 | =cut | ||||||||||||
| 23 | |||||||||||||
| 24 | =head2 new | ||||||||||||
| 25 | |||||||||||||
| 26 | The constructor. You can setup attributes and description. Example: | ||||||||||||
| 27 | |||||||||||||
| 28 | use Net::RRP::Response; | ||||||||||||
| 29 | my $response = new Net::RRP::Response (); | ||||||||||||
| 30 | my $otherResponse = new Net::RRP::Response ( attributes => { qq => 'tt'}, | ||||||||||||
| 31 | description => 'this is a response description' ); | ||||||||||||
| 32 | |||||||||||||
| 33 | =cut | ||||||||||||
| 34 | |||||||||||||
| 35 | sub new | ||||||||||||
| 36 | 0 | ▶ | { | ||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 37 | 0 | my $class = shift; | |||||||||||
| 38 | 0 | ▶ | my %options = @_ ? @_ : ( attributes => {}, | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 39 | description => '' ); | ||||||||||||
| 40 | 0 | bless { %options }, $class; | |||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | =head2 newFromException | ||||||||||||
| 44 | |||||||||||||
| 45 | Construct new response object from exception infomation; | ||||||||||||
| 46 | |||||||||||||
| 47 | my $response = newFromException Net::RRP::Response ( new Net::RRP::Exception ( "description", $code ) ); | ||||||||||||
| 48 | |||||||||||||
| 49 | =cut | ||||||||||||
| 50 | |||||||||||||
| 51 | sub newFromException | ||||||||||||
| 52 | 0 | ▶ | { | ||||||||||
|
Subroutine
newFromException: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 53 | 0 | my ( $class, $exception ) = @_; | |||||||||||
| 54 | 0 | my $code = $exception->value; | |||||||||||
| 55 | 0 | my $packageName = "Net\:\:RRP\:\:Response\:\:n$code"; | |||||||||||
| 56 | 0 | ▶ | eval "use $packageName;"; die $@ if $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | 0 | ▶ | $packageName->new ( description => $exception->text || ' ' ); | ||||||||||
|
Condition0%0/2
$exception->text || ' '
MC/DC0%0/1
$exception->text || ' '
$exception->text
Truth table0%0/2
A
A= $exception->text
| |||||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | =head2 getCode | ||||||||||||
| 61 | |||||||||||||
| 62 | This method return a code (number) of response. Must be overwrited at child classes. Example: | ||||||||||||
| 63 | |||||||||||||
| 64 | my $responseNumber = $response->getCode; | ||||||||||||
| 65 | |||||||||||||
| 66 | =cut | ||||||||||||
| 67 | |||||||||||||
| 68 | sub getCode | ||||||||||||
| 69 | 0 | ▶ | { | ||||||||||
|
Subroutine
getCode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 70 | 0 | die "Must be implemented at child class"; | |||||||||||
| 71 | } | ||||||||||||
| 72 | |||||||||||||
| 73 | =head2 getDescription | ||||||||||||
| 74 | |||||||||||||
| 75 | Get response description. Example: | ||||||||||||
| 76 | |||||||||||||
| 77 | my $description = $response->getDescription(); | ||||||||||||
| 78 | |||||||||||||
| 79 | =cut | ||||||||||||
| 80 | |||||||||||||
| 81 | sub getDescription | ||||||||||||
| 82 | 0 | ▶ | { | ||||||||||
|
Subroutine
getDescription: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 83 | 0 | my $this = shift; | |||||||||||
| 84 | 0 | $this->{description}; | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | =head2 setDescription | ||||||||||||
| 88 | |||||||||||||
| 89 | Set response description. Example: | ||||||||||||
| 90 | |||||||||||||
| 91 | $response->setDescription ( 'this is a response description' ); | ||||||||||||
| 92 | |||||||||||||
| 93 | =cut | ||||||||||||
| 94 | |||||||||||||
| 95 | sub setDescription | ||||||||||||
| 96 | 0 | ▶ | { | ||||||||||
|
Subroutine
setDescription: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 97 | 0 | my ( $this, $description ) = @_; | |||||||||||
| 98 | 0 | my $old = $this->{description}; | |||||||||||
| 99 | 0 | $this->{description} = $description; | |||||||||||
| 100 | 0 | $old; | |||||||||||
| 101 | } | ||||||||||||
| 102 | |||||||||||||
| 103 | =head2 getAttribute | ||||||||||||
| 104 | |||||||||||||
| 105 | Return a named response attribute. Example: | ||||||||||||
| 106 | |||||||||||||
| 107 | my $attribute = $response->getAttribute ( 'name' ); | ||||||||||||
| 108 | |||||||||||||
| 109 | =cut | ||||||||||||
| 110 | |||||||||||||
| 111 | sub getAttribute | ||||||||||||
| 112 | 0 | ▶ | { | ||||||||||
|
Subroutine
getAttribute: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 113 | 0 | my ( $this, $optionName ) = @_; | |||||||||||
| 114 | 0 | $this->{attributes}->{$optionName} | |||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | =head2 setAttribute | ||||||||||||
| 118 | |||||||||||||
| 119 | Setup a named attribute. Example: | ||||||||||||
| 120 | |||||||||||||
| 121 | $response->setAttribute ( 'name' => 'value' ); | ||||||||||||
| 122 | |||||||||||||
| 123 | =cut | ||||||||||||
| 124 | |||||||||||||
| 125 | sub setAttribute | ||||||||||||
| 126 | 0 | ▶ | { | ||||||||||
|
Subroutine
setAttribute: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 127 | 0 | my ( $this, $optionName, $optionValue ) = @_; | |||||||||||
| 128 | 0 | my $old = $this->{attributes}->{$optionName}; | |||||||||||
| 129 | 0 | $this->{attributes}->{$optionName} = $optionValue; | |||||||||||
| 130 | 0 | $old; | |||||||||||
| 131 | } | ||||||||||||
| 132 | |||||||||||||
| 133 | =head2 getAttributes | ||||||||||||
| 134 | |||||||||||||
| 135 | Get response attributes hash ref. Example: | ||||||||||||
| 136 | |||||||||||||
| 137 | my $attributes = $response->getAttributes; | ||||||||||||
| 138 | map { print "$_ = " . $attributes->{$_} } keys %$attributes; | ||||||||||||
| 139 | |||||||||||||
| 140 | =cut | ||||||||||||
| 141 | |||||||||||||
| 142 | sub getAttributes | ||||||||||||
| 143 | 0 | ▶ | { | ||||||||||
|
Subroutine
getAttributes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 144 | 0 | my $this = shift; | |||||||||||
| 145 | $this->{attributes} | ||||||||||||
| 146 | 0 | } | |||||||||||
| 147 | |||||||||||||
| 148 | 1 | 1; | |||||||||||
| 149 | |||||||||||||
| 150 | =head1 AUTHOR AND COPYRIGHT | ||||||||||||
| 151 | |||||||||||||
| 152 | Net::RRP::Response (C) Michael Kulakov, Zenon N.S.P. 2000 | ||||||||||||
| 153 | 125124, 19, 1-st Jamskogo polja st, | ||||||||||||
| 154 | Moscow, Russian Federation | ||||||||||||
| 155 | |||||||||||||
| 156 | mkul@cpan.org | ||||||||||||
| 157 | |||||||||||||
| 158 | All rights reserved. | ||||||||||||
| 159 | |||||||||||||
| 160 | You may distribute this package under the terms of either the GNU | ||||||||||||
| 161 | General Public License or the Artistic License, as specified in the | ||||||||||||
| 162 | Perl README file. | ||||||||||||
| 163 | |||||||||||||
| 164 | =head1 SEE ALSO | ||||||||||||
| 165 | |||||||||||||
| 166 | L<Net::RRP::Entity(3)>, L<Net::RRP::Request(3)>, L<Net::RRP::Codec(3)>, L<Net::RRP::Exception(3)>, RFC 2832 | ||||||||||||
| 167 | |||||||||||||
| 168 | =cut | ||||||||||||
| 169 | |||||||||||||
| 170 | __END__ | ||||||||||||