| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package TypeLibrary::FromXSD::Element; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Create a single type decleration from a simpleType xsd element |
|
4
|
|
|
|
|
|
|
|
|
5
|
27
|
|
|
27
|
|
938929
|
use Moo; |
|
|
27
|
|
|
|
|
629712
|
|
|
|
27
|
|
|
|
|
223
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 0.03; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has name => (is => 'ro', required => 1); |
|
10
|
|
|
|
|
|
|
has base => (is => 'ro', required => 1); |
|
11
|
|
|
|
|
|
|
has orig_base => (is => 'ro' ); |
|
12
|
|
|
|
|
|
|
has enum => (is => 'ro', predicate => 1); |
|
13
|
|
|
|
|
|
|
has restrictions => (is => 'ro', predicate => 1); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub type { |
|
16
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
17
|
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
return sprintf "declare %s =>\n as %s%s;", |
|
19
|
|
|
|
|
|
|
$self->name, |
|
20
|
|
|
|
|
|
|
$self->_basetype, |
|
21
|
|
|
|
|
|
|
$self->_where, |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _basetype { |
|
25
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
return $self->base if !$self->has_enum; |
|
28
|
0
|
|
|
|
|
|
return sprintf "enum [%s]", join ",", map{ $_ =~ s/'/\'/g; "'$_'" } @{ $self->enum }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _where { |
|
32
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
return '' if !$self->restrictions; |
|
35
|
0
|
|
|
|
|
|
return sprintf ",\n where {\n %s\n }", |
|
36
|
0
|
|
|
|
|
|
join " && \n ", map{ "($_)" }@{ $self->restrictions }; |
|
|
0
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub BUILDARGS { |
|
40
|
0
|
|
|
0
|
0
|
|
my ($class, @args) = @_; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
0
|
0
|
|
|
|
return {@args} if @args > 1 && @args % 2 == 0; |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $node = shift @args; |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $extra_validations; |
|
47
|
0
|
0
|
|
|
|
|
if ( @args > 1 ) { |
|
48
|
0
|
|
|
|
|
|
my %args = @args; |
|
49
|
0
|
|
|
|
|
|
$extra_validations = delete $args{validate}; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my %real_args; |
|
53
|
0
|
0
|
|
|
|
|
if ( $node ) { |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
0
|
0
|
|
|
|
return {} if !ref $node || !$node->isa('XML::LibXML::Element'); |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$real_args{name} = $node->findvalue('@name'); |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my ($restrictions_node) = $node->findnodes('xs:restriction'); |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $base = $restrictions_node->findvalue('@base'); |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my %base_map = ( |
|
64
|
|
|
|
|
|
|
'xs:string' => 'Str', |
|
65
|
|
|
|
|
|
|
'xs:decimal' => 'Num', |
|
66
|
|
|
|
|
|
|
'xs:date' => 'Str', |
|
67
|
|
|
|
|
|
|
'xs:dateTime' => 'Str', |
|
68
|
|
|
|
|
|
|
); |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
0
|
|
|
|
$real_args{base} = $base_map{$base} || 'Str'; |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my @restrictions = $restrictions_node->childNodes; |
|
73
|
0
|
|
|
|
|
|
for my $restriction ( @restrictions ) { |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $node_name = $restriction->nodeName; |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
if ( $node_name eq 'xs:enumeration' ) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
push @{ $real_args{enum} }, $restriction->findvalue('@value'); |
|
|
0
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
elsif ( $node_name eq 'xs:minLength' ) { |
|
81
|
0
|
|
|
|
|
|
push @{ $real_args{restrictions} }, 'length($_) >= ' . $restriction->findvalue('@value'); |
|
|
0
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
elsif ( $node_name eq 'xs:maxLength' ) { |
|
84
|
0
|
|
|
|
|
|
push @{ $real_args{restrictions} }, 'length($_) <= ' . $restriction->findvalue('@value'); |
|
|
0
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
elsif ( $node_name eq 'xs:pattern' ) { |
|
87
|
0
|
|
|
|
|
|
my $pattern = $restriction->findvalue('@value'); |
|
88
|
0
|
|
|
|
|
|
$pattern =~ s/!/\!/g; |
|
89
|
0
|
|
|
|
|
|
push @{ $real_args{restrictions} }, sprintf '$_ =~ m!%s!', $pattern; |
|
|
0
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
elsif ( $node_name eq 'xs:minInclusive' ) { |
|
92
|
0
|
|
|
|
|
|
push @{ $real_args{restrictions} }, '$_ >= ' . $restriction->findvalue('@value'); |
|
|
0
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
elsif ( $node_name eq 'xs:maxInclusive' ) { |
|
95
|
0
|
|
|
|
|
|
push @{ $real_args{restrictions} }, '$_ <= ' . $restriction->findvalue('@value'); |
|
|
0
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
elsif ( $node_name eq 'xs:fractionDigits' ) { |
|
98
|
0
|
|
|
|
|
|
push @{ $real_args{restrictions} }, 'length( (split /\./, $_)[1] ) == ' . $restriction->findvalue('@value'); |
|
|
0
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
elsif ( $node_name eq 'xs:totalDigits' ) { |
|
101
|
0
|
|
|
|
|
|
push @{ $real_args{restrictions} }, 'tr/0123456789// == ' . $restriction->findvalue('@value'); |
|
|
0
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$base =~ s/^xs://; |
|
106
|
0
|
0
|
|
|
|
|
if ( $base eq 'date' ) { |
|
|
|
0
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
push @{ $real_args{restrictions} }, '$_ =~ m{\A-?[0-9]{4,}-[0-9]{2}-[0-9]{2}(?:Z|[-+]?[0-2][0-9]:[0-5][0-9])?\z}'; |
|
|
0
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
elsif ( $base eq 'dateTime' ) { |
|
110
|
0
|
|
|
|
|
|
push @{ $real_args{restrictions} }, |
|
|
0
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
'$_ =~ m{\A-?[0-9]{4,}-[0-9]{2}-[0-9]{2}T[0-2][0-9]:[0-5][0-9]:[0-5][0-9](?:Z|[-+]?[0-2][0-9]:[0-5][0-9])?\z}'; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
0
|
0
|
0
|
|
|
|
if ( $base =~ m{\Adate(Time)?\z} and $extra_validations and $extra_validations->{$base} ) { |
|
|
|
|
0
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
push @{ $real_args{restrictions} }, $extra_validations->{$base} . '($_)'; |
|
|
0
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
$real_args{orig_base} = $base; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
return \%real_args; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |