blob: 32dbc98bf0ad36b7e3e866c5ee55b7651d05649d (
plain) (
blame)
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
|
package MooseX::Net::API::Role::Format;
use Moose::Role;
use Moose::Util::TypeConstraints;
sub content_type {
{ json => {value => 'application/json', module => 'JSON',},
yaml => {value => 'text/x-yaml', module => 'YAML'},
xml => {value => 'text/xml', module => 'XML::Simple'},
};
}
subtype Format => as 'Str' => where {
my $format = shift;
grep {/^$format$/} keys %{content_type()};
};
enum 'FormatMode' => qw(content-type append);
has api_format => (
is => 'rw',
isa => 'Format',
lazy => 1,
default => sub {
my $self = shift;
$self->meta->get_option('api_format');
}
);
has api_format_mode => (
is => 'rw',
isa => 'FormatMode',
lazy => 1,
default => sub {
my $self = shift;
my $mode = $self->meta->get_option('api_format_mode');
$mode || 'append';
}
);
1;
|