Skip to content
create a Type::Tiny library of simpleTypes in .xsd files.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
lib/TypeLibrary
scripts
t
.gitignore
.travis.yml
CONTRIBUTING.md
Changes
README.mkdn
dist.ini

README.mkdn

Build Status Kwalitee status GitHub issues

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 _simpleType_s 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)
    };

Development

The distribution is contained in a Git repository, so simply clone the repository

$ git clone http://github.com/reneeb/TypeLibrary-FromXSD.git

and change into the newly-created directory.

$ cd TypeLibrary-FromXSD

The project uses Dist::Zilla to build the distribution, hence this will need to be installed before continuing:

$ cpanm Dist::Zilla

To install the required prequisite packages, run the following set of commands:

$ dzil authordeps --missing | cpanm
$ dzil listdeps --author --missing | cpanm

The distribution can be tested like so:

$ dzil test

To run the full set of tests (including author and release-process tests), add the --author and --release options:

$ dzil test --author --release

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)
You can’t perform that action at this time.