File: plugin_import.t

package info (click to toggle)
libdancer2-perl 0.400001%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,580 kB
  • sloc: perl: 8,461; makefile: 9
file content (60 lines) | stat: -rw-r--r-- 1,267 bytes parent folder | download | duplicates (4)
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
# plugin_import.t

use strict;
use warnings;
use Test::More;
use Plack::Test;
use HTTP::Request::Common;
use Ref::Util qw<is_coderef>;

{
    use Dancer2;
    use lib 't/lib';
    use Dancer2::Plugin::PluginWithImport;

    get '/test' => sub {
        dancer_plugin_with_import_keyword;
    };
}

my $app = __PACKAGE__->to_app;
ok( is_coderef($app), 'Got app' );

test_psgi $app, sub {
    my $cb = shift;

    is(
        $cb->( GET '/test' )->content,
        'dancer_plugin_with_import_keyword',
        'the plugin exported its keyword',
    );
};

is_deeply(
    Dancer2::Plugin::PluginWithImport->stuff,
    { 'Dancer2::Plugin::PluginWithImport' => 'imported' },
    "the original import method of the plugin is still there"
);

subtest 'import flags' => sub {
    eval "
        package Dancer2::Plugin::Some::Plugin1;
        use Dancer2::Plugin ':no_dsl';

        register 'foo' => sub { request };
    ";
    like $@, qr{Bareword "request" not allowed while "strict subs"},
      "with :no_dsl, the Dancer's dsl is not imported.";

    eval "
        package Dancer2::Plugin::Some::Plugin2;
        use Dancer2::Plugin;

        register 'foo' => sub { request };
    ";
    is $@, '', "without any import flag, the DSL is imported";


};

done_testing;