about summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-06-02 11:37:31 +0200
committerfranck cuny <franck@lumberjaph.net>2010-06-02 11:37:31 +0200
commita2634d1eb978366d85a9b55153a90bd001950933 (patch)
tree5c37a434e0c6ce272bbedde1439f9523f582bfdb
parenttests (diff)
downloadnet-http-api-a2634d1eb978366d85a9b55153a90bd001950933.tar.gz
role to handle format informations
-rw-r--r--lib/MooseX/Net/API/Role/Format.pm41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/MooseX/Net/API/Role/Format.pm b/lib/MooseX/Net/API/Role/Format.pm
new file mode 100644
index 0000000..32dbc98
--- /dev/null
+++ b/lib/MooseX/Net/API/Role/Format.pm
@@ -0,0 +1,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;