WSDL-Generator

 view release on metacpan or  search on metacpan

lib/WSDL/Generator/Schema.pm  view on Meta::CPAN

=pod

=head1 NAME

WSDL::Generator::Schema - Generate wsdl schema for WSDL::Generator

=head1 SYNOPSIS

  use WSDL::Generator::Schema;
  my $schema = WSDL::Generator::Schema->new('mytargetNamespace');
  $schema->add($struct);
  $schema->add($struct2);
  print $schema->get->to_string;

=cut
package WSDL::Generator::Schema;

use strict;
use warnings::register;
use Carp;
use base	qw(WSDL::Generator::Base);

our $VERSION = '0.01';


=pod

=head1 CONSTRUCTOR

=head2 new($namespace)

$namespace is optional.
Returns WSDL::Generator::Schema object

=cut
sub new {
	my ($class, $namespace) = @_;
	my $self = { 'schema_namesp' => $namespace,
	             'counter'       => 0 };
	return bless $self => $class;
}

=pod

=head1 METHODS

=head2 add($struct)

Generate a wsdl schema for the structure sent

=cut
sub add : method {
	my ($self, $struct, $name) = @_;
	push @{$self->{schema}}, $self->make_types($self->dumper($struct), $name);
}

=pod

=head2 get($namespace)

$namespace is optional (it must be specified here or in new method).
Returns the Schema wsdl array of lines

=cut
sub get : method {
	my ($self, $namespace) = @_;
	$self->{schema_namesp} = $namespace if (defined $namespace);
	unless ($self->{schema}) {
		carp 'No schema defined';
		return 0;
	}
	my $schema = $self->get_wsdl_element( { wsdl_type => 'TYPES',
														%$self,
				                                     } );
	return $schema;
}


#
# Create wsdl types declations
#
sub make_types {
	my $self   = shift;
	my $struct = shift;
	my $name   = shift || 'myelement'.$self->{counter}++;
	my @wsdl   = ();
	if ($struct->{type} eq 'SCALAR' ) {
		push @wsdl, @{$self->get_wsdl_element( { wsdl_type => 'ELEMENT',
  		                                       	 name      => $name,
			                                   	 type      => 'string',
		                                     } )};
	}
	elsif ($struct->{type} eq 'HASHREF' ) {
		my @sub_wsdl = ();
		foreach my $key ( keys %{$struct->{value}} ) {
			if ($struct->{value}->{$key}->{type} eq 'SCALAR') {
				push @sub_wsdl, @{$self->get_wsdl_element( { wsdl_type => 'ELEMENT',
				                                        	 type      => 'string',
				                                        	 name      => $key,
				                                        	 min_occur => $struct->{value}->{$key}->{min_occur} } )};

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.601 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )