SOAP-Data-Builder

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

SOAP-Data-Builder version 0.01
==============================

This Module provides a quick and easy way to build complex SOAP data
and header structures for use with SOAP::Lite.

It primarily provides a wrapper around SOAP::Serializer and SOAP::Data
(or SOAP::Header) enabling you to generate complex XML within your SOAP
request or response.

Developed by Aaron Trevena at Surrey Technologies, Ltd. 

INSTALLATION

To install this module type the following:

   perl Makefile.PL
   make

lib/SOAP/Data/Builder.pm  view on Meta::CPAN

=head1 NAME

  SOAP::Data::Builder - A wrapper simplifying SOAP::Data and SOAP::Serialiser

=head1 DESCRIPTION

  This Module provides a quick and easy way to build complex SOAP data
  and header structures for use with SOAP::Lite.

  It primarily provides a wrapper around SOAP::Serializer and SOAP::Data
  (or SOAP::Header) enabling you to generate complex XML within your SOAP
  request or response.

=head1 VERSION

1.0

=head1 SYNOPSIS

  use SOAP::Lite ( +trace => 'all', maptype => {} );

lib/SOAP/Data/Builder.pm  view on Meta::CPAN

returns whether the object currently uses readable when serialising

=cut

sub readable {
 return shift->{options}{readable} || 0;
}

=head2 to_soap_data()

  returns the contents of the object as a list of SOAP::Data and/or SOAP::Header objects

  NOTE: make sure you call this in array context!

=cut

sub to_soap_data {
    my $self = shift;
    my @data = ();
    foreach my $elem ( $self->elems ) {
	push(@data,$self->get_as_data($elem,1));

lib/SOAP/Data/Builder.pm  view on Meta::CPAN

optional parameters are : parent, value, attributes, header, isMethod

parent should be an element 'add_elem(parent=>$parent_element, .. );'

or the full name of an element 'add_elem(parent=>'name/of/parent', .. );'

value should be a string,

attributes should be a hashref : { 'ns:foo'=> bar, .. }

header should be 1 or 0 specifying whether the element should be built using SOAP::Data or SOAP::Header

returns the added element

my $bar_elem = $builder->add_elem(name=>'bar', value=>$foo->{bar}, parent=>$foo);

would produce SOAP::Data representing an XML fragment like '<foo><bar>..</bar></foo>'

=cut

sub add_elem {

lib/SOAP/Data/Builder.pm  view on Meta::CPAN

    }
  }
  my @data = ();

  if (ref $values[0]) {
    $data[0] = \SOAP::Data->value( @values );
  } else {
    @data = @values;
  }
  if ($elem->{header}) {
    $data[0] = SOAP::Header->name($elem->{name} => $data[0])->attr($elem->attributes());
  } else {
      if ($elem->{isMethod}) {
	  @data = ( SOAP::Data->name($elem->{name} )->attr($elem->attributes()) => SOAP::Data->value( @values ) );
      } elsif ($elem->{type}) {
	  $data[0] = SOAP::Data->name($elem->{name} => $data[0])->attr($elem->attributes())->type($elem->{type});
      } else {
	  $data[0] = SOAP::Data->name($elem->{name} => $data[0])->attr($elem->attributes());
      }
  }
  return @data;

lib/SOAP/Data/Builder/Element.pm  view on Meta::CPAN

my $element = SOAP::Data::Builder::Element->new( name=> 'anExample', VALUE=> 'foo', attributes => { 'ns1:foo' => 'bar'});

optional parameters are : value, attributes, header, isMethod

parent should be an element fetched using get_elem

value should be a string, to add child nodes use add_elem(parent=>get_elem('name/of/parent'), .. )

attributes should be a hashref : { 'ns:foo'=> bar, .. }

header should be 1 or 0 specifying whether the element should be built using SOAP::Data or SOAP::Header

=cut

sub new {
    my ($class,%args) = @_;
    my $self = {};
    bless ($self,ref $class || $class);
    foreach my $key (keys %args) {
      $self->{$key} = $args{$key} || 0;
    }

lib/SOAP/Data/Builder/Element.pm  view on Meta::CPAN


  my @data = ();

  if (ref $values[0]) {
    $data[0] = \SOAP::Data->value( @values );
  } else {
    @data = @values;
  }

  if ($self->{header}) {
    $data[0] = SOAP::Header->name($self->{name} => $data[0])->attr($self->{attributes});
  } else {
    if ($self->{isMethod}) {
      @data = ( SOAP::Data->name($self->{name} )->attr($self->{attributes}) => SOAP::Data->value( @values ) );
    } else {
      $data[0] = SOAP::Data->name($self->{name} => $data[0])->attr($self->{attributes});
    }
  }

  return @data;
}



( run in 0.253 second using v1.01-cache-2.11-cpan-454fe037f31 )