NAME

TypeLibrary::FromXSD - create a Type::Tiny library of simpleTypes in .xsd files.

VERSION

version 0.05

SYNOPSIS

  use TypeLibrary::FromXSD;
  
  my $generator = TypeLibrary::FromXSD->new(
    xsd    => '/path/to/file.xsd',
    output => '/path/to/Library.pm',
  );
  
  $generator->run;

DESCRIPTION

This module helps to create a library for types (using Type::Tiny) based on a XML schema. It searches for simpleTypes in the .xsd file and creates a type for it.

ATTRIBUTES

  • types

  • xsd

  • output

  • namespace

  • version_add

METHODS

run

SUPPORTED TYPES

Date And DateTime

  <xs:simpleType name="ISODate">
    <xs:restriction base="xs:date"/>
  </xs:simpleType>
  <xs:simpleType name="ISODateTime">
    <xs:restriction base="xs:dateTime"/>
  </xs:simpleType>

create those types:

  declare ISODate =>
      as Str,
      where {
          ($_ =~ m{\A-?[0-9]{4,}-[0-9]{2}-[0-9]{2}(?:Z|[-+]?[0-2][0-9]:[0-5][0-9])?\z}) &&
          (validate_date( $_ )) # if an extra validation is passed
      };

Strings

  <xs:simpleType name="BEIIdentifier">
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}"/>
    </xs:restriction>
  </xs:simpleType>

=>

  declare BEIIdentifier =>
     as Str,
     where{
         ($_ =~ m![A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}!)
     };

Enumerations

  <xs:simpleType name="AddressType2Code">
    <xs:restriction base="xs:string">
      <xs:enumeration value="ADDR"/>
      <xs:enumeration value="PBOX"/>
      <xs:enumeration value="HOME"/>
      <xs:enumeration value="BIZZ"/>
      <xs:enumeration value="MLTO"/>
      <xs:enumeration value="DLVY"/>
    </xs:restriction>
  </xs:simpleType>

=>

  declare AddressType2Code => as enum ["ADDR","PBOX","HOME","BIZZ","MLTO","DLVY"];

Numbers

  <xs:simpleType name="CurrencyAndAmount_SimpleType">
    <xs:restriction base="xs:decimal">
      <xs:minInclusive value="0"/>
      <xs:fractionDigits value="5"/>
      <xs:totalDigits value="18"/>
    </xs:restriction>
  </xs:simpleType>

=>

  declare CurrencyAndAmount_SimpleType =>
      as Num,
      where {
          ($_ <= 0) &&
          (length( (split /\./, $_)[1] ) == 5) &&
          (tr/0123456789// == 18)
      };

AUTHOR

Renee Baecker <github@renee-baecker.de>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2013 by Renee Baecker.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)