Debian Codegraph @

t/issues/gh-1226/lib/Dancer2/Plugin/Test/AccessDSL.pm

raw
1 package Dancer2::Plugin::Test::AccessDSL;
2 use strict;
3 use warnings;
4 use Dancer2::Plugin;
5
6 plugin_keywords('change_response_status');
7
8 sub change_response_status {
9 my $self = shift;
10 my $caller = caller(1);
11 ::is( $self->app->name, 'OtherApp', 'Appname is OtherApp' );
12 ::is( $caller, 'App::Extra', 'The caller class is App::Extra' );
13
14 ::ok(
15 ::exception(sub{ $self->app->dsl }),
16 'Cannot call DSL via app (bc appname is app)',
17 );
18
19 ::ok(
20 ::exception( sub { $self->app->name->dsl } ),
21 'Cannot call DSL via appname (bc it is not the consumer class)',
22 );
23
24 ::ok(
25 ::exception( sub { OtherApp->status(400) } ),
26 'Cannot call DSL via appname string (bc it is not the consumer class)',
27 );
28
29 ::is(
30 ::exception( sub { App::Extra::status(400) } ),
31 undef,
32 'Was able to successfully call the DSL (via consumer class)',
33 );
34
35 ::is(
36 $self->app->response->status(),
37 400,
38 'Status was set correctly',
39 );
40
41 ::is(
42 ::exception( sub { $self->dsl->status(200) } ),
43 undef,
44 'Was able to successfully call the DSL (via plugin->dsl)',
45 );
46
47 ::is(
48 $self->app->response->status(),
49 200,
50 'Status was set correctly',
51 );
52 }
53
54 1;