File: CodeFirst.pod

package info (click to toggle)
libsoap-wsdl-perl 2.00.10-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,820 kB
  • ctags: 626
  • sloc: perl: 8,432; xml: 1,769; java: 19; makefile: 15
file content (93 lines) | stat: -rw-r--r-- 2,747 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
=pod

=head1 NAME

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

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

=head2 How Data Class definitions could look like

=head3 Moose

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 => 'http://webservicex.net';

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

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

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

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

=head3 Native SOAP::WSDL

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 'http://webservicex.net';    # might be better in the SOAP server interface
 _name 'GenerateBarCode';
 _elements
         BarCodeParam => 'MyTypes::BarCodeData',
         BarCodeText => 'string';

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

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

=head2 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 Java 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>
     return=<MyElements::GenerateBarcodeResponse>
     body=<MyElements::GenerateBarcode>) {
     my ($self, $body, $header) = @_;
     my $result = MyElements::GenerateBarcodeResponse->new();
     return $result;
 };
 1;