1package Test::Catalyst::Action::REST::Controller::REST; 2 3use Moose; 4use namespace::autoclean; 5 6BEGIN { extends 'Catalyst::Controller::REST' } 7 8__PACKAGE__->config( 9 'map' => { 10 'text/html' => 'YAML::HTML', 11 'text/x-yaml' => 'YAML', 12}); 13 14sub test : Local { 15 my ( $self, $c ) = @_; 16 $self->status_ok( $c, 17 entity => { test => 'worked', data => $c->req->data } ); 18} 19 20sub test_status_created : Local { 21 my ( $self, $c ) = @_; 22 $self->status_created( 23 $c, 24 location => '/rest', 25 entity => { status => 'created' } 26 ); 27} 28 29sub test_status_multiple_choices : Local { 30 my ( $self, $c ) = @_; 31 $self->status_multiple_choices( 32 $c, 33 location => '/rest/choice1', 34 entity => { choices => [qw(/rest/choice1 /rest/choice2)] } 35 ); 36} 37 38sub test_status_found : Local { 39 my ( $self, $c ) = @_; 40 $self->status_found( 41 $c, 42 location => '/rest', 43 entity => { status => 'found' }, 44 ); 45} 46 47sub test_status_accepted : Local { 48 my ( $self, $c ) = @_; 49 $self->status_accepted( 50 $c, 51 location => '/rest', 52 entity => { status => "queued", } 53 ); 54} 55 56sub test_status_no_content : Local { 57 my ( $self, $c ) = @_; 58 $self->status_no_content($c); 59} 60 61sub test_status_bad_request : Local { 62 my ( $self, $c ) = @_; 63 $self->status_bad_request( $c, 64 message => "Cannot do what you have asked!", ); 65} 66 67sub test_status_forbidden : Local { 68 my ( $self, $c ) = @_; 69 $self->status_forbidden ( $c, 70 message => "access denied", ); 71} 72 73sub test_status_not_found : Local { 74 my ( $self, $c ) = @_; 75 $self->status_not_found( $c, 76 message => "Cannot find what you were looking for!", ); 77} 78 79sub test_status_gone : Local { 80 my ( $self, $c ) = @_; 81 $self->status_gone( $c, 82 message => "Document have been deleted by foo", ); 83} 84 85sub test_status_see_other : Local { 86 my ( $self, $c ) = @_; 87 $self->status_see_other( 88 $c, 89 location => '/rest', 90 entity => { somethin => 'happenin' } 91 ); 92} 93 94sub opts : Local ActionClass('REST') {} 95 96sub opts_GET { 97 my ( $self, $c ) = @_; 98 $self->status_ok( $c, entity => { opts => 'worked' } ); 99} 100 101sub opts_not_implemented { 102 my ( $self, $c ) = @_; 103 $c->res->status(405); 104 $c->res->header('Allow' => [qw(GET HEAD)]); 105 $c->res->body('Not implemented'); 106} 107 1081; 109