Debian Codegraph @

t/issues/gh-1230/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
12 ::is( $self->app->name, 'OtherApp', 'Appname is OtherApp' );
13
14 ::is(
15 $caller,
16 'Dancer2::Plugin::Test::AccessPluginDSL',
17 'The caller class is the first plugin (AccessPluginDSL)',
18 );
19
20 ::ok(
21 ::exception(sub{ $self->app->dsl }),
22 'Cannot call DSL via app (bc appname is app)',
23 );
24
25 ::ok(
26 ::exception( sub { $self->app->name->dsl } ),
27 'Cannot call DSL via appname (bc it is not the consumer class)',
28 );
29
30 ::ok(
31 ::exception( sub { OtherApp->status(400) } ),
32 'Cannot call DSL via appname string (bc it is not the consumer class)',
33 );
34
35 ::is(
36 ::exception( sub { App::Extra::status(400) } ),
37 undef,
38 'Was able to successfully call the DSL (via consumer class)',
39 );
40
41 ::is(
42 $self->app->response->status(),
43 400,
44 'Status was set correctly',
45 );
46
47 ::is(
48 ::exception( sub { $self->dsl->status(200) } ),
49 undef,
50 'Was able to successfully call the DSL (via plugin->dsl)',
51 );
52
53 ::is(
54 $self->app->response->status(),
55 200,
56 'Status was set correctly',
57 );
58 }
59
60 1;