File: middleware-stash.t

package info (click to toggle)
libcatalyst-perl 5.90132-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,016 kB
  • sloc: perl: 11,061; makefile: 7
file content (78 lines) | stat: -rw-r--r-- 1,687 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use warnings;
use strict;

{

  package MyMiddleware;
  $INC{'MyMiddleware'} = __FILE__;

  our $INNER_VAR_EXPOSED;

  use base 'Plack::Middleware';

  sub call {
    my ($self, $env) = @_;

    my $res = $self->app->($env);

    return $self->response_cb($res, sub{
      my $inner = shift;

      $INNER_VAR_EXPOSED = $env->{inner_var_from_catalyst};

      return;
    });

  }

  package MyAppChild::Controller::User;
  $INC{'MyAppChild/Controller/User.pm'} = __FILE__;

  use base 'Catalyst::Controller';
  use Test::More;

  sub stash :Local {
    my ($self, $c) = @_;
    $c->stash->{inner} = "inner";
    $c->res->body( "inner: ${\$c->stash->{inner}}, outer: ${\$c->stash->{outer}}");

    $c->req->env->{inner_var_from_catalyst} = 'station';

    is_deeply [sort {$a cmp $b} keys(%{$c->stash})], ['inner','outer'], 'both keys in stash';
  }

  package MyAppChild;
  $INC{'MyAppChild.pm'} = __FILE__;

  use Catalyst;
  MyAppChild->setup;

  package MyAppParent::Controller::User;
  $INC{'MyAppParent/Controller/User.pm'} = __FILE__;

  use base 'Catalyst::Controller';
  use Test::More;

  sub stash :Local {
    my ($self, $c) = @_;
    $c->stash->{outer} = "outer";
    $c->res->from_psgi_response( MyAppChild->to_app->($c->req->env) );

    is_deeply [sort keys(%{$c->stash})], ['inner','outer'];
  }

  package MyAppParent;
  use Catalyst;
  MyAppParent->config(psgi_middleware=>['+MyMiddleware']);
  MyAppParent->setup;

}

use Test::More;
use Catalyst::Test 'MyAppParent';

my $res = request '/user/stash';
is $res->content, 'inner: inner, outer: outer', 'got expected response';
is $MyMiddleware::INNER_VAR_EXPOSED, 'station', 'env does not get trampled';

done_testing;