SOAP::Data::ComplexType 0.041 review

Download
by rbytes.net on

SOAP::Data::ComplexType is an abstract class for creating and handling complex SOAP::Data objects. SYNOPSIS package My:

License: Perl Artistic License
File size: 13K
Developer: Eric Rybski
0 stars award from rbytes.net

SOAP::Data::ComplexType is an abstract class for creating and handling complex SOAP::Data objects.

SYNOPSIS

package My::SOAP::Data::ComplexType::Foo;
use strict;
use warnings;
use SOAP::Data::ComplexType;
use vars qw(@ISA);
@ISA = qw(SOAP::Data::ComplexType);

use constant OBJ_URI => 'http://foo.bar.baz';
use constant OBJ_TYPE => 'ns1:myFoo';
use constant OBJ_FIELDS => {
field1 => ['string', undef, undef],
field2 => ['int', undef, undef],
field3 => ['xsd:dateTime', undef, undef]
};

sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $data = shift;
my $obj_fields = shift;
$obj_fields = defined $obj_fields && ref($obj_fields) eq 'HASH' ? {%{+OBJ_FIELDS}, %{$obj_fields}} : OBJ_FIELDS;
my $self = $class->SUPER::new($data, $obj_fields);
return bless($self, $class);
}

package My::SOAP::Data::ComplexType::Bar;
use strict;
use warnings;
use SOAP::Data::ComplexType;
use vars qw(@ISA);
@ISA = qw(SOAP::Data::ComplexType);

use constant OBJ_URI => 'http://bar.baz.uri';
use constant OBJ_TYPE => 'ns1:myBar';
use constant OBJ_FIELDS => {
val1 => ['string', undef, undef],
val2 => [
[
My::SOAP::Data::ComplexType::Foo::OBJ_TYPE,
My::SOAP::Data::ComplexType::Foo::OBJ_FIELDS
],
My::SOAP::Data::ComplexType::Foo::OBJ_URI, undef
]
};

sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $data = shift;
my $obj_fields = shift;
$obj_fields = defined $obj_fields && ref($obj_fields) eq 'HASH' ? {%{+OBJ_FIELDS}, %{$obj_fields}} : OBJ_FIELDS;
my $self = $class->SUPER::new($data, $obj_fields);
return bless($self, $class);
}

########################################################################
package main;

my $request_obj = My::SOAP::Data::ComplexType::Bar->new({
val1 => 'sometext',
val2 => {
field1 => 'moretext',
field2 => 12345,
field3 => '2005-10-26T12:00:00.000Z'
}
});
print $request_obj->as_xml_data;

use SOAP::Lite;
my $result = SOAP::Lite
->uri($uri)
->proxy($proxy)
->somemethod(SOAP::Data->value($request_obj->as_soap_data))
->result;

#assuming the method returns an object of type Foo...
if (ref($result) eq 'Foo') {
my $result_obj = My::SOAP::Data::ComplexType::Foo->new($result);
print "$_=".$result_obj->$_."n" foreach keys %{+My::SOAP::Data::ComplexType::Foo::OBJ_FIELDS};
}

ABSTRACT

SOAP::Data::ComplexType defines a structured interface to implement classes that represent infinitely complex SOAP::Data objects. Object instances can dynamically generate complex SOAP::Data structures or pure XML as needed. Fields of an object may be easily accessed by making a method call with name of the field as the method, and field values can be changed after object construction by using the same method with one parameter.

Blessed objects returned by a SOAP::Lite method's SOAP::SOM->result may be used to reconstitute the object back into an equivalent ComplexType, thus solving shortcomings of SOAP::Lite's handling of complex types and allowing users to access their objects in a much more abstract and intuive way. This is also exceptionally useful for applications that need use SOAP result objects in future SOAP calls.

DESCRIPTION

This module is intended to make it much easier to create complex SOAP::Data objects in an object-oriented class-structure, as users of SOAP::Lite must currently craft SOAP data structures manually. It uses SOAP::Data::Builder internally to store and generate object data.
I hope this module will greatly improve productivity of any SOAP::Lite programmer, especially those that deal with many complex datatypes or work with SOAP apps that implement inheritance.

Requirements:
Perl

SOAP::Data::ComplexType 0.041 search tags