WSDL-Generator

 view release on metacpan or  search on metacpan

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


=head1 NAME

WSDL::Generator - Generate wsdl file automagically

=head1 SYNOPSIS

  use WSDL::Generator;
  my $wsdl = WSDL::Generator->new($init);
  Foo->a_method($param);
  print $wsdl->get('Foo');

=head1 DESCRIPTION

You know folks out there who use another language than Perl (huh?) and you want to release a SOAP server for them

  1/ that's very kind of you
  2/ you need to generate a wsdl file
  3/ this module can help
Because Perl is dynamically typed, it is a fantastic language to write SOAP clients,
but that makes perl not-so-easy to use as SOAP server queried by statically typed languages
such as Delphi, Java, C++, VB...
These languages need a WSDL file to communicate with your server.
The WSDL file contains all the data structure definition necessary to interact with the server.
It contains also the namespace and URL as well.

=cut
package WSDL::Generator;

use strict;
use warnings::register;
use Carp;
use Class::Hook;
use WSDL::Generator::Schema;
use WSDL::Generator::Binding;
use base    qw(WSDL::Generator::Base);
use 5.6.0;

our $VERSION = '0.04';

=pod

=head1 CONSTRUCTOR

=head2 new($init)

  $init = {   'schema_namesp' => 'http://www.acmetravel.com/AcmeTravelServices.xsd',
              'services'      => 'AcmeTravel',
              'service_name'  => 'BookFlight',
              'target_namesp' => 'http://www.acmetravel.com/SOAP/',
              'documentation' => 'Service to book tickets online',
              'location'      => 'http://www.acmetravel.com/SOAP/BookFlight' };
Install a spy which captures all the methods and subs calls to other classes

=cut
sub new {
    my $class = shift;
    my $param = shift || {};
    my $self = { calls   => {},
                 %$param };
    bless $self => $class;
    Class::Hook->before(\&_before, $self);
    Class::Hook->after(\&_after, $self);
    Class::Hook->activate();
    return $self;
}

=pod

=head1 METHODS

=head2 get($class)

Returns the WSDL code for a specific class

=cut
sub get : method {
    my $self  = shift;
    my $class = shift;
    unless (exists $self->{calls}{$class} and $self->{calls}{$class}) {
        carp "Class $class not called";
        return undef;
    }
    my $schema  = WSDL::Generator::Schema->new( $self->{schema_namesp} );
    my $binding = WSDL::Generator::Binding->new( { service_name => $self->{service_name},
                                                   services     => $self->{services} } );
    foreach my $method ( keys %{$self->{calls}{$class}} ) {
        my $before = $self->{calls}{$class}->{$method}->{before};
        my $after  = $self->{calls}{$class}->{$method}->{after};
        $schema->add($before, $method.'Request');
        $schema->add($after, $method.'Response');
        $binding->add_request($method);
        $binding->add_response($method);
    }
    $self->{schema}      = $schema->get;
    $self->{message}     = $binding->get_message;
    $self->{porttype}    = $binding->get_porttype;
    $self->{binding}     = $binding->get_binding;
    $self->{service}     = $self->get_wsdl_element( { wsdl_type => 'SERVICE',
                                            %$self,
                                             } );
    $self->{definitions} = $self->get_wsdl_element( { wsdl_type => 'DEFINITIONS',
                                            %$self,
                                             } );
    my $wsdl = $self->get_wsdl_element( { wsdl_type => 'WSDL',
                                            %$self,
                                            } );
    Class::Hook->deactivate();
    return $wsdl->to_string;
}


=pod

=head2 get_all()

Returns all classes available for a WSDL generation

=cut
sub get_all : method {
    my $self = shift;

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

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