diff options
| author | franck cuny <franck@lumberjaph.net> | 2010-07-16 16:10:41 +0200 |
|---|---|---|
| committer | franck cuny <franck@lumberjaph.net> | 2010-07-16 16:10:41 +0200 |
| commit | e97449eaa8bd3a408763057f9ca2253d93e2a3d0 (patch) | |
| tree | 4fd0dc6ed899efe361e314adfc913b9aa6b0a1a4 /lib/Net/HTTP/API/Role/Format.pm | |
| parent | check if auth_method is declared (diff) | |
| download | net-http-api-e97449eaa8bd3a408763057f9ca2253d93e2a3d0.tar.gz | |
rename from mx::net::api to net::http::api
Diffstat (limited to 'lib/Net/HTTP/API/Role/Format.pm')
| -rw-r--r-- | lib/Net/HTTP/API/Role/Format.pm | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/Net/HTTP/API/Role/Format.pm b/lib/Net/HTTP/API/Role/Format.pm new file mode 100644 index 0000000..1d8c10f --- /dev/null +++ b/lib/Net/HTTP/API/Role/Format.pm @@ -0,0 +1,65 @@ +package Net::HTTP::API::Role::Format; + +# ABSTRACT: Set appropriate format to request header + +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_api_option('api_format'); + } +); + +has api_format_mode => ( + is => 'rw', + isa => 'FormatMode', + lazy => 1, + default => sub { + my $self = shift; + my $mode = $self->meta->get_api_option('api_format_mode') || 'append'; + $mode; + } +); + +1; + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +=head2 METHODS + +=over 4 + +=item B<content_type> + +=back + +=head2 ATTRIBUTES + +=over 4 + +=item B<api_format> + +=item B<api_format_mode> + +=back |
