| 1 | package POE::Filter::XML::RPC::Response; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 2 | ▶ | use base('POE::Filter::XML::Node'); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 2 | our $VERSION = '0.04'; | |||||||||||||
| 9 | |||||||||||||||
| 10 | sub new() | ||||||||||||||
| 11 | 0 | ▶ | { | ||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 12 | 0 | my ($class, $arg) = @_; | |||||||||||||
| 13 | |||||||||||||||
| 14 | 0 | my $node = $class->SUPER::new('methodResponse'); | |||||||||||||
| 15 | |||||||||||||||
| 16 | 0 | bless($node, $class); | |||||||||||||
| 17 | |||||||||||||||
| 18 | 0 | ▶ | if($arg->isa('POE::Filter::XML::RPC::Fault')) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 19 | { | ||||||||||||||
| 20 | 0 | $node->fault($arg); | |||||||||||||
| 21 | |||||||||||||||
| 22 | } elsif($arg->isa('POE::Filter::XML::RPC::Value')) { | ||||||||||||||
| 23 | |||||||||||||||
| 24 | 0 | $node->return_value($arg); | |||||||||||||
| 25 | } | ||||||||||||||
| 26 | |||||||||||||||
| 27 | 0 | return $node; | |||||||||||||
| 28 | |||||||||||||||
| 29 | } | ||||||||||||||
| 30 | |||||||||||||||
| 31 | sub fault() | ||||||||||||||
| 32 | 0 | ▶ | { | ||||||||||||
|
Subroutine
fault: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||
| 33 | 0 | my ($self, $arg) = @_; | |||||||||||||
| 34 | |||||||||||||||
| 35 | 0 | my $fault = ($self->findnodes('child::fault'))[0]; | |||||||||||||
| 36 | |||||||||||||||
| 37 | 0 | ▶ | if(defined($arg)) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | { | ||||||||||||||
| 39 | 0 | ▶ | if(!defined($fault)) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 40 | { | ||||||||||||||
| 41 | 0 | ▶ | if($self->exists('child::params')) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 42 | { | ||||||||||||||
| 43 | 0 | $self->removeChild($self->firstChild()); | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | 0 | $self->appendChild($arg); | |||||||||||||
| 46 | |||||||||||||||
| 47 | } else { | ||||||||||||||
| 48 | |||||||||||||||
| 49 | 0 | $self->removeChild($fault); | |||||||||||||
| 50 | 0 | $self->appendChild($arg); | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | 0 | return $arg; | |||||||||||||
| 54 | |||||||||||||||
| 55 | } else { | ||||||||||||||
| 56 | |||||||||||||||
| 57 | 0 | ▶ | return undef if not defined $fault; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 58 | 0 | return bless($fault, 'POE::Filter::XML::RPC::Fault'); | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | |||||||||||||||
| 61 | } | ||||||||||||||
| 62 | |||||||||||||||
| 63 | sub return_value() | ||||||||||||||
| 64 | 0 | ▶ | { | ||||||||||||
|
Subroutine
return_value: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||
| 65 | 0 | my ($self, $arg) = @_; | |||||||||||||
| 66 | |||||||||||||||
| 67 | 0 | ▶ | if(defined($arg)) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 68 | { | ||||||||||||||
| 69 | 0 | ▶ | if(!$self->exists('child::params')) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 70 | { | ||||||||||||||
| 71 | 0 | ▶ | if($self->exists('child::fault')) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 72 | { | ||||||||||||||
| 73 | 0 | $self->removeChild($self->firstChild()); | |||||||||||||
| 74 | } | ||||||||||||||
| 75 | 0 | $self->appendChild('params')->appendChild('param')->appendChild($arg); | |||||||||||||
| 76 | |||||||||||||||
| 77 | } else { | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 0 | ($self->findnodes('child::params/child::param'))[0]->appendChild($arg); | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | |||||||||||||||
| 82 | 0 | return $arg; | |||||||||||||
| 83 | |||||||||||||||
| 84 | } else { | ||||||||||||||
| 85 | |||||||||||||||
| 86 | 0 | ▶ | if(my $value = ($self->findnodes('child::params/child::param/child::value'))[0]) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 87 | { | ||||||||||||||
| 88 | 0 | return bless($value, 'POE::Filter::XML::RPC::Value'); | |||||||||||||
| 89 | } | ||||||||||||||
| 90 | |||||||||||||||
| 91 | 0 | return undef; | |||||||||||||
| 92 | } | ||||||||||||||
| 93 | } | ||||||||||||||
| 94 | |||||||||||||||
| 95 | =pod | ||||||||||||||
| 96 | |||||||||||||||
| 97 | =head1 NAME | ||||||||||||||
| 98 | |||||||||||||||
| 99 | POE::Filter::XML::RPC::Response - An abstracted XMLRPC response | ||||||||||||||
| 100 | |||||||||||||||
| 101 | =head1 SYNOPSIS | ||||||||||||||
| 102 | |||||||||||||||
| 103 | use 5.010; | ||||||||||||||
| 104 | use POE::Filter::XML::RPC::Response; | ||||||||||||||
| 105 | use POE::Filter::XML::RPC::Value; | ||||||||||||||
| 106 | |||||||||||||||
| 107 | my $response = POE::Filter::XML::RPC::Response->new | ||||||||||||||
| 108 | ( | ||||||||||||||
| 109 | POE::Filter::XML::RPC::Value->new('Okay!'); | ||||||||||||||
| 110 | ) | ||||||||||||||
| 111 | |||||||||||||||
| 112 | say $response->return_value()->value() # Okay! | ||||||||||||||
| 113 | |||||||||||||||
| 114 | =head1 DESCRIPTION | ||||||||||||||
| 115 | |||||||||||||||
| 116 | POE::Filter::XML::RPC::Reponse provides a simple class for generating XMLRPC | ||||||||||||||
| 117 | responses. | ||||||||||||||
| 118 | |||||||||||||||
| 119 | =head1 PUBLIC METHODS | ||||||||||||||
| 120 | |||||||||||||||
| 121 | =over 4 | ||||||||||||||
| 122 | |||||||||||||||
| 123 | =item new() | ||||||||||||||
| 124 | |||||||||||||||
| 125 | new() takes a single argument that can either be a POE::Filter::XML::RPC::Value | ||||||||||||||
| 126 | object or it can be a POE::Filter::XML::RPC::Fault object. | ||||||||||||||
| 127 | |||||||||||||||
| 128 | =item fault() | ||||||||||||||
| 129 | |||||||||||||||
| 130 | If the response contains a Fault object, it will be returned. May also take a | ||||||||||||||
| 131 | single argument of another Fault object. In that case, any previous Fault | ||||||||||||||
| 132 | object will be replaced with the provided. Also, if the response contained a | ||||||||||||||
| 133 | valid return Value, it will be replaced by the Fault. | ||||||||||||||
| 134 | |||||||||||||||
| 135 | =item return_value() | ||||||||||||||
| 136 | |||||||||||||||
| 137 | If the response contains a return Value, it will be returned. May also take a | ||||||||||||||
| 138 | single argument of another Value object. In that case, any previous Value | ||||||||||||||
| 139 | object will be replaced with the provided. Also, if the response contained a | ||||||||||||||
| 140 | Fault, it will be replaced by the Value. | ||||||||||||||
| 141 | |||||||||||||||
| 142 | =back | ||||||||||||||
| 143 | |||||||||||||||
| 144 | =head1 NOTES | ||||||||||||||
| 145 | |||||||||||||||
| 146 | Response is actually a subclass of POE::Filter::XML::Node and so all of its | ||||||||||||||
| 147 | methods, including XML::LibXML::Element's, are available for use. This could | ||||||||||||||
| 148 | ultimately be useful to avoid marshalling all of the data out of the Node and | ||||||||||||||
| 149 | instead apply an XPATH expression to target specifically what is desired deep | ||||||||||||||
| 150 | within a nested structure. | ||||||||||||||
| 151 | |||||||||||||||
| 152 | =head1 AUTHOR | ||||||||||||||
| 153 | |||||||||||||||
| 154 | Copyright 2009 Nicholas Perez. | ||||||||||||||
| 155 | Licensed and distributed under the GPL. | ||||||||||||||
| 156 | |||||||||||||||
| 157 | =cut | ||||||||||||||
| 158 | |||||||||||||||
| 159 | 2 | 1; | |||||||||||||