File: Serialize.pm

package info (click to toggle)
libcatalyst-action-serialize-data-serializer-perl 1.08-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 248 kB
  • ctags: 190
  • sloc: perl: 2,409; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,382 bytes parent folder | download | duplicates (3)
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
46
47
48
49
50
51
52
53
54
package Test::Catalyst::Action::REST::Controller::Serialize;

use Moose;
use namespace::autoclean;

BEGIN { extends 'Catalyst::Controller' }

__PACKAGE__->config(
    'default'   => 'text/x-yaml',
    'stash_key' => 'rest',
    'map'       => {
        'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
    },
);

sub test :Local :ActionClass('Serialize') {
    my ( $self, $c ) = @_;
    $c->stash->{'rest'} = {
        lou => 'is my cat',
    };
}

sub test_second :Local :ActionClass('Serialize') {
    my ( $self, $c ) = @_;
    # 'serialize_content_type' is configured in the test config in t/conf
    $c->stash->{'serialize_content_type'} = $c->req->params->{'serialize_content_type'};
    $c->stash->{'rest'} = {
        lou => 'is my cat',
    };
}

# For testing saying 'here is an explicitly empty body, do not serialize'
sub empty : Chained('/') PathPart('serialize') CaptureArgs(0) {
    my ($self, $c) = @_;
    $c->stash( rest => { foo => 'bar' } );
}

# Normal case
sub empty_serialized :Chained('empty') Args(0) ActionClass('Serialize') {
}

# Blank body
sub empty_not_serialized_blank :Chained('empty') Args(0) ActionClass('Serialize') {
    my ($self, $c) = @_;
    $c->res->body('');
}

# Explicitly set a view
sub explicit_view :Chained('empty') Args(0) ActionClass('Serialize') {
    my ($self, $c) = @_;
    $c->stash->{current_view} = '';
}

1;