This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
332
|
Appendix B: SOAP::Lite Programming Reference
SOAP::Data
The SOAP::Data class provides the means by which to explicitly manipulate and con-
trol all aspects of the way in which Perl data gets expressed as SOAP data entities.
Most of the methods are accessors, which like those in
SOAP::Lite are designed to
return the current value if no new one is passed, while returning the object reference
otherwise (allowing for chained method calls). Note that most accessors (except
value) accept a new value for the data object as a second argument.
new(optional key/value pairs) $obj = SOAP::Data->new(name => 'idx', value => 5);
This is the class constructor. Almost all of the attributes related to the class may
be passed to the constructor as key/value pairs. This method isn’t often used
directly because
SOAP::Data objects are generally created for temporary use. It is
available for those situations that require it.
name(new name, optional value) $obj->name('index');
Gets or sets the current value of the name, as the object regards it. The name is
what the serializer will use for the tag when generating the XML for this object.
It is what will become the accessor for the data element. Optionally, the object’s
value may be updated if passed as a second argument.
type(new type, optional value) $obj->type('int');
Gets or sets the type associated with the current value in the object. This is use-
ful for those cases where the
SOAP::Data object is used to explicitly specify the
type of data that would otherwise be interpreted as a different type completely
(such as perceiving the string
123 as an integer, instead). Allows the setting of the
object’s value, if passed as a second argument to the method.
uri(new uri, optional value) $obj->uri('http://www.perl.com/SOAP');
Gets or sets the URI that will be used as the namespace for the resulting XML
entity, if one is desired. This doesn’t set the label for the namespace. If one isn’t
provided by means of the
prefix method, one is generated automatically when
needed. Also allows the setting of the object’s value, if passed as a second argu-
ment to the method.
prefix(new prefix, optional value) $obj->prefix('perl');
Provides the prefix, or label, for use when associating the data object with a spe-
cific namespace. Also allows the setting of the object’s value, if passed as a sec-
ond argument to the method.
attr(hash reference of attributes, optional value) $obj->attr({ attr1 => 'value' });
Allows for the setting of arbitrary attributes on the data object. Keep in mind the
requirement that any attributes not natively known to SOAP must be
namespace-qualified. Also allows the setting of the object’s value, if passed as a
second argument to the method.
value(new value) $obj->value(10);
Fetches the current value encapsulated by the object, or explicitly sets it.

Get Programming Web Services with Perl now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.