| 1 |
# plugin_import.t |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More; |
| 6 |
use Plack::Test; |
| 7 |
use HTTP::Request::Common; |
| 8 |
use Ref::Util qw<is_coderef>; |
| 9 |
|
| 10 |
{ |
| 11 |
use Dancer2; |
| 12 |
use lib 't/lib'; |
| 13 |
use Dancer2::Plugin::PluginWithImport; |
| 14 |
|
| 15 |
get '/test' => sub { |
| 16 |
dancer_plugin_with_import_keyword; |
| 17 |
}; |
| 18 |
} |
| 19 |
|
| 20 |
my $app = __PACKAGE__->to_app; |
| 21 |
ok( is_coderef($app), 'Got app' ); |
| 22 |
|
| 23 |
test_psgi $app, sub { |
| 24 |
my $cb = shift; |
| 25 |
|
| 26 |
is( |
| 27 |
$cb->( GET '/test' )->content, |
| 28 |
'dancer_plugin_with_import_keyword', |
| 29 |
'the plugin exported its keyword', |
| 30 |
); |
| 31 |
}; |
| 32 |
|
| 33 |
is_deeply( |
| 34 |
Dancer2::Plugin::PluginWithImport->stuff, |
| 35 |
{ 'Dancer2::Plugin::PluginWithImport' => 'imported' }, |
| 36 |
"the original import method of the plugin is still there" |
| 37 |
); |
| 38 |
|
| 39 |
subtest 'import flags' => sub { |
| 40 |
eval " |
| 41 |
package Dancer2::Plugin::Some::Plugin1; |
| 42 |
use Dancer2::Plugin ':no_dsl'; |
| 43 |
|
| 44 |
register 'foo' => sub { request }; |
| 45 |
"; |
| 46 |
like $@, qr{Bareword "request" not allowed while "strict subs"}, |
| 47 |
"with :no_dsl, the Dancer's dsl is not imported."; |
| 48 |
|
| 49 |
eval " |
| 50 |
package Dancer2::Plugin::Some::Plugin2; |
| 51 |
use Dancer2::Plugin; |
| 52 |
|
| 53 |
register 'foo' => sub { request }; |
| 54 |
"; |
| 55 |
is $@, '', "without any import flag, the DSL is imported"; |
| 56 |
|
| 57 |
|
| 58 |
}; |
| 59 |
|
| 60 |
done_testing; |