TypeLibrary::FromXSD - create a Type::Tiny library of simpleTypes in .xsd files.
version 0.03
use TypeLibrary::FromXSD; my $generator = TypeLibrary::FromXSD->new( xsd => '/path/to/file.xsd', output => '/path/to/Library.pm', ); $generator->run;
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.
Type::Tiny
<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 };
<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}!) };
<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"];
<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) };
Renee Baecker <github@renee-baecker.de>
This software is Copyright (c) 2013 by Renee Baecker.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install TypeLibrary::FromXSD, copy and paste the appropriate command in to your terminal.
cpanm
cpanm TypeLibrary::FromXSD
CPAN shell
perl -MCPAN -e shell install TypeLibrary::FromXSD
For more information on module installation, please visit the detailed CPAN module installation guide.