File: 033-postback-w-hateoas.psgi

package info (click to toggle)
libweb-machine-perl 0.17-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 940 kB
  • sloc: perl: 5,481; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download | duplicates (5)
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
#!perl

use strict;
use warnings;
use FindBin;

use Web::Machine;

BEGIN {
    eval {
        require( "$FindBin::Bin/030-postback.psgi" ) &&
        require( "$FindBin::Bin/031-postback-w-json.psgi" ) &&
        require( "$FindBin::Bin/032-postback-w-auth.psgi" )
    }
}

{
    package YAPC::NA::2012::Example033::Resource;
    use strict;
    use warnings;
    use JSON::XS qw[ encode_json ];
    use Web::Machine::Util qw[ create_header ];

    use base 'YAPC::NA::2012::Example032::Resource';

    sub content_types_provided {
        my $self  = shift;
        my $types = $self->SUPER::content_types_provided;
        push @$types => { 'application/json' => 'to_json' };
        $types;
    }

    sub to_json {
        my $self = shift;
        $self->response->header(
            'Link' => create_header(
                'LinkHeader' => [ '/', ('content-type' => 'text/html') ]
            )
        );
        encode_json([ $self->get_messages ]);
    }

}

Web::Machine->new( resource => 'YAPC::NA::2012::Example033::Resource' )->to_app;