SOAP::...deFirst(3pm)

✨ NAME ✨

CodeFirst — writing Code-First Web Services with SOAP::WSDL 💖

okay bestie, real talk before we start: this doc is literally just a collection of thoughts. There's no implementation yet. It's vibes and blueprints only, no cap. 🫶

🌸 How Data Class definitions could look like 🌸

🎀 Moose

obvi SOAP::WSDL could (and honestly probably should) just use Moose — it hands you the whole Metaclass Framework you'd need to generate Schemas straight from class definitions. iconic behaviour, truly.

but — and this is the tea — Moose is way too powerful for building (just) simple Data Transfer Objects that can be expressed in XML. it's giving "bringing a whole moving truck to carry one croissant" 😭

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;

and like… yes the syntax is condensed, but this is still a lot of line noise. we said what we said. 💅

🦋 Native SOAP::WSDL

SOAP::WSDL::XSD::Typelib::ComplexType (should) provide a simple setup method that lets you describe things even shorter — and it throws in the extra performance boost SOAP::WSDL has over Moose as a lil treat ✨

 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 — living inside a schema with the namespace "http://webservicex.net", and the namespaces could even be declared outside the DTO classes. yes, main character energy 💜

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

🌈 Interface definitions 🌈

so here's the thing: Perl does not have the concept of interfaces. periodt. but Moose provides Roles, which can be used for defining interfaces. slay 🎀

however — and lowkey this is the important part — it's not really necessary to define a interface Interface (in the sense of a Java interface). a interface class is sufficient. fr fr.

Subroutine attributes could be used for providing additional information — attributes in perl are much like annotations in Java. iykyk 👑

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;

that's the whole vibe, bestie 🧚 this lil thought-collection lives in perl v5.36.0, dated 2022-10-14 — go forth and manifest it, and remember: no implementation yet, so hydrate and stay delulu 💖🌟🍓

📦 where this page comes from