| 1 | package Net::RRP::Request; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Net::RRP::Exception::MissingCommandOption; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Net::RRP::Exception::MissingRequiredEntity; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | $Net::RRP::Request::VERSION = (split " ", '# $Id: Request.pm,v 1.4 2000/09/11 15:34:14 mkul Exp $ ')[3]; | |||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Net::RRP::Request - rrp request abstraction class | ||||||||||
| 11 | |||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||
| 13 | |||||||||||
| 14 | use Net::RRP::Request; | ||||||||||
| 15 | my $request = new Net::RRP::Request; | ||||||||||
| 16 | |||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||
| 18 | |||||||||||
| 19 | This is a base class for all Request::* classes. | ||||||||||
| 20 | |||||||||||
| 21 | =cut | ||||||||||
| 22 | |||||||||||
| 23 | =head2 new | ||||||||||
| 24 | |||||||||||
| 25 | The constructor. You can pass entity && options attributes to this method. Example: | ||||||||||
| 26 | |||||||||||
| 27 | my $request = new Net::RRP::Request ( entity => new Net::RRP::Entity ( .... ), | ||||||||||
| 28 | options => { key => 'value' } ); | ||||||||||
| 29 | my $request1 = new Net::RRP::Request ( ); | ||||||||||
| 30 | |||||||||||
| 31 | =cut | ||||||||||
| 32 | |||||||||||
| 33 | sub new | ||||||||||
| 34 | 0 | ▶ | { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 35 | 0 | my ( $class, %params ) = @_; | |||||||||
| 36 | 0 | bless { %params }, $class; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | =head2 getName | ||||||||||
| 40 | |||||||||||
| 41 | Return a *real* name of this request. You must overwrite this method at child class. Example: | ||||||||||
| 42 | |||||||||||
| 43 | my $requestName = $request->getName(); | ||||||||||
| 44 | print STDERR "EntityName is $requestName\n"; | ||||||||||
| 45 | |||||||||||
| 46 | =cut | ||||||||||
| 47 | |||||||||||
| 48 | sub getName | ||||||||||
| 49 | 0 | ▶ | { | ||||||||
|
Subroutine
getName: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 50 | 0 | die "Must be implemented at child class"; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | =head2 setEntity | ||||||||||
| 54 | |||||||||||
| 55 | Setup the rrp entity for this request. Example: | ||||||||||
| 56 | |||||||||||
| 57 | $request->setEntity ( new Net::RRP::Entity ( ... ) ); | ||||||||||
| 58 | |||||||||||
| 59 | =cut | ||||||||||
| 60 | |||||||||||
| 61 | sub setEntity | ||||||||||
| 62 | 0 | ▶ | { | ||||||||
|
Subroutine
setEntity: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 63 | 0 | my ( $this, $entity ) = @_; | |||||||||
| 64 | 0 | my $old = $this->{entity}; | |||||||||
| 65 | 0 | $this->{entity} = $entity; | |||||||||
| 66 | 0 | $old; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | =head2 getEntity | ||||||||||
| 70 | |||||||||||
| 71 | Return a entity of this request. Example: | ||||||||||
| 72 | |||||||||||
| 73 | my $entity = $request->getEntity(); | ||||||||||
| 74 | |||||||||||
| 75 | Can throw Net::RRP::Exception::MissingRequiredEntity exception | ||||||||||
| 76 | |||||||||||
| 77 | =cut | ||||||||||
| 78 | |||||||||||
| 79 | sub getEntity | ||||||||||
| 80 | 0 | ▶ | { | ||||||||
|
Subroutine
getEntity: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 81 | 0 | my $this = shift; | |||||||||
| 82 | 0 | ▶ | $this->{entity} || throw Net::RRP::Exception::MissingRequiredEntity(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | =head2 getOption | ||||||||||
| 86 | |||||||||||
| 87 | Return a request option by $optionName. Example: | ||||||||||
| 88 | |||||||||||
| 89 | print $request->getOption ( $optionName ); | ||||||||||
| 90 | print $request->getOption ( 'ttt' ); # no '-' here | ||||||||||
| 91 | |||||||||||
| 92 | Can throw Net::RRP::Exception::MissingCommandOption() exception. | ||||||||||
| 93 | |||||||||||
| 94 | =cut | ||||||||||
| 95 | |||||||||||
| 96 | sub getOption | ||||||||||
| 97 | 0 | ▶ | { | ||||||||
|
Subroutine
getOption: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 98 | 0 | my ( $this, $optionName ) = @_; | |||||||||
| 99 | 0 | ▶ | $this->{options}->{ lc ( $optionName ) } || throw Net::RRP::Exception::MissingCommandOption(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | =head2 setOption | ||||||||||
| 103 | |||||||||||
| 104 | Set $optionName rrp request option to the $optionValue. Example: | ||||||||||
| 105 | |||||||||||
| 106 | $request->setOption ( $optionName => $optionValue ); | ||||||||||
| 107 | $request->setOption ( tt => 'qq' ); | ||||||||||
| 108 | |||||||||||
| 109 | =cut | ||||||||||
| 110 | |||||||||||
| 111 | sub setOption | ||||||||||
| 112 | 0 | ▶ | { | ||||||||
|
Subroutine
setOption: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 113 | 0 | my ( $this, $optionName, $optionValue ) = @_; | |||||||||
| 114 | 0 | $optionName = lc ( $optionName ); | |||||||||
| 115 | 0 | my $old = $this->{options}->{$optionName}; | |||||||||
| 116 | 0 | $this->{options}->{$optionName} = $optionValue; | |||||||||
| 117 | 0 | $old; | |||||||||
| 118 | } | ||||||||||
| 119 | |||||||||||
| 120 | =head2 getOptions | ||||||||||
| 121 | |||||||||||
| 122 | Return a hash ref to the request options. Example: | ||||||||||
| 123 | |||||||||||
| 124 | my $options = $request->gtOptions(); | ||||||||||
| 125 | map { print "$_ = " . $options->{$_} } keys %$options; | ||||||||||
| 126 | |||||||||||
| 127 | =cut | ||||||||||
| 128 | |||||||||||
| 129 | sub getOptions | ||||||||||
| 130 | 0 | ▶ | { | ||||||||
|
Subroutine
getOptions: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 131 | 0 | my $this = shift; | |||||||||
| 132 | $this->{options} | ||||||||||
| 133 | 0 | } | |||||||||
| 134 | |||||||||||
| 135 | =head2 isSuccessResponse | ||||||||||
| 136 | |||||||||||
| 137 | Return a true if response is successfull. | ||||||||||
| 138 | |||||||||||
| 139 | my $protocol = new Net::RRP::Protocol ( .... ); | ||||||||||
| 140 | my $request = new Net::RRP::Request::Add ( .... ); | ||||||||||
| 141 | $protocol->sendRequest ( $request ); | ||||||||||
| 142 | my $response = $protocol->getResponse (); | ||||||||||
| 143 | die "error" unless $request->isSuccessResponse ( $response ); | ||||||||||
| 144 | |||||||||||
| 145 | =cut | ||||||||||
| 146 | |||||||||||
| 147 | sub isSuccessResponse | ||||||||||
| 148 | 0 | ▶ | { | ||||||||
|
Subroutine
isSuccessResponse: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 149 | 0 | my ( $this, $response ) = @_; | |||||||||
| 150 | 0 | ▶ | return 0 unless $response; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 151 | 0 | return { 200 => 1, 220 => 1 }->{ $response->getCode() }; | |||||||||
| 152 | } | ||||||||||
| 153 | |||||||||||
| 154 | 1 | 1; | |||||||||
| 155 | |||||||||||
| 156 | |||||||||||
| 157 | =head1 AUTHOR AND COPYRIGHT | ||||||||||
| 158 | |||||||||||
| 159 | Net::RRP::Request (C) Michael Kulakov, Zenon N.S.P. 2000 | ||||||||||
| 160 | 125124, 19, 1-st Jamskogo polja st, | ||||||||||
| 161 | Moscow, Russian Federation | ||||||||||
| 162 | |||||||||||
| 163 | mkul@cpan.org | ||||||||||
| 164 | |||||||||||
| 165 | All rights reserved. | ||||||||||
| 166 | |||||||||||
| 167 | You may distribute this package under the terms of either the GNU | ||||||||||
| 168 | General Public License or the Artistic License, as specified in the | ||||||||||
| 169 | Perl README file. | ||||||||||
| 170 | |||||||||||
| 171 | =head1 SEE ALSO | ||||||||||
| 172 | |||||||||||
| 173 | L<Net::RRP::Entity(3)>, L<Net::RRP::Response(3)>, L<Net::RRP::Codec(3)>, RFC 2832, | ||||||||||
| 174 | L<Net::RRP::Exception::MissingCommandOption(3)>, L<Net::RRP::Exception::MissingRequiredEntity(3)> | ||||||||||
| 175 | |||||||||||
| 176 | =cut | ||||||||||
| 177 | |||||||||||
| 178 | __END__ | ||||||||||