Martin Kutter > SOAP-WSDL-2.00.10 > lib/SOAP/WSDL/Manual/CodeFirst.pod


Annotate this POD


New  16
Open  24
View/Report Bugs
Source   Latest Release: SOAP-WSDL-3.003

Writing Code-First Web Services with SOAP::WSDL ^

Note: This document is just a collection of thought. There's no implementation yet.

How Data Class definitions could look like


Of course SOAP::WSDL could (and probably should) just use Moose - it provides the full Metaclass Framework needed for generating Schemas from class definitions.

However, Moose is way too powerful for building (just) simple Data Transfer Objects which can be expressed in XML.

With Moose, a class could look like this:

 package MyElements::GenerateBarCode;
 use Moose;

 has 'xmlns' =>
     is => 'ro',
     default => '';

 has 'xmlname' =>
     is => 'ro',
     default => 'GenerateBarCode';

 has 'BarCodeParam' =>
      is => 'rw',
      type => 'MyTypes::BarCodeData';

 has 'BarCodeText' =>
      is => 'rw',
      type => 'String';

This is - despite the condensed syntax - a lot of line noise.


SOAP::WSDL::XSD::Typelib::ComplexType (should) provide a simple setup method allowing a even shorter description (and offering the additional performance boost SOAP::WSDL has over Moose):

 package MyElements::GenerateBarCode;
 use strice; use warnings;
 use SOAP::WSDL::XSD::Typelib::Element;
 use SOAP::WSDL::XSD::Typelib::ComplexType;

 _namespace '';    # might be better in the SOAP server interface
 _name 'GenerateBarCode';
         BarCodeParam => 'MyTypes::BarCodeData',
         BarCodeText => 'string';

This would result in the following XML Schema (inside a schema with the namespace "" - the namespaces could even be declared outside the DTO classes.

 <complexType name="GenerateBarCode">
           <element name="BarCodeParam" type="tns:BarCodeData"/>
           <element name="BarCodeText" type="xsd:string"/>

Interface definitions

Perl does not have the concept of interfaces. However, Moose provides Roles, which can be used for defining interfaces.

However, it's not really necessary to define a interface Interface (in the sense of a Jave interface) - a interface class is sufficient.

Subroutine attributes could be used for providing additional information - attributes in perl are much like annotations in Java

A interface could look like this:

 package MyServer::BarCode;
 use strict; use warnings;
 use SOAP::WSDL::Server::CodeFirst;

 sub generateBarCode :WebMethod(name=<GenerateBarCode>
     body=<MyElements::GenerateBarcode>) {
     my ($self, $body, $header) = @_;
     my $result = MyElements::GenerateBarcodeResponse->new();
     return $result;
syntax highlighting: