1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
package Open311::Endpoint::Service::Attribute;
use Moo;
use MooX::HandlesVia;
use Types::Standard ':all';
use namespace::clean;
# from http://wiki.open311.org/GeoReport_v2#GET_Service_Definition
# A unique identifier for the attribute
has code => (
is => 'ro',
isa => Str,
);
# true denotes that user input is needed
# false means the attribute is only used to present information to the user within the description field
#
# NB: unsure what false means for the rest of the options here, e.g. should remainder of fields by Maybe[] ?
has variable => (
is => 'ro',
isa => Bool,
default => sub { 1 },
);
# Denotes the type of field used for user input.
has datatype => (
is => 'ro',
isa => Enum[qw/ string number datetime text singlevaluelist multivaluelist /],
);
has required => (
is => 'ro',
isa => Bool,
);
# A description of the datatype which helps the user provide their input
has datatype_description => (
is => 'ro',
isa => Str,
);
# A description of the attribute field with instructions for the user to find
# and identify the requested information
has description => (
is => 'ro',
isa => Str,
);
# NB: we don't model the "Order" field here, as that's really for the Service
# object to return
# only relevant for singlevaluelist or multivaluelist
has values => (
is => 'ro',
isa => HashRef,
default => sub { {} },
handles_via => 'Hash',
handles => {
get_value => 'get',
get_values => 'keys',
has_values => 'count',
values_kv => 'kv',
}
);
sub schema_definition {
my $self = shift;
my @values = map +{ type => '//str', value => $_ }, $self->get_values;
my %schema_types = (
string => '//str',
number => '//num',
datetime => '//str', # TODO
text => '//str',
singlevaluelist => { type => '//any', of => [@values] },
multivaluelist => { type => '//arr', of => [@values] },
);
return $schema_types{ $self->datatype };
}
1;
|