| 1 |
# define a sample DSL extension that will be used in the rest of these test |
| 2 |
# This extends Dancer2::Core::DSL but provides an extra keyword |
| 3 |
# |
| 4 |
# Each test below creates a new package so it can load Dancer2 |
| 5 |
BEGIN { |
| 6 |
|
| 7 |
package Dancer2::Test::ExtendedDSL; |
| 8 |
|
| 9 |
use Moo; |
| 10 |
extends 'Dancer2::Core::DSL'; |
| 11 |
|
| 12 |
sub BUILD { |
| 13 |
my ( $self ) = @_; |
| 14 |
$self->register(foo => 1); |
| 15 |
} |
| 16 |
|
| 17 |
sub foo { |
| 18 |
return $_[1]; |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
package main; |
| 23 |
|
| 24 |
use Test::More tests => 5; |
| 25 |
|
| 26 |
package test1; |
| 27 |
use Test::More; |
| 28 |
|
| 29 |
use Dancer2 dsl => 'Dancer2::Test::ExtendedDSL'; |
| 30 |
|
| 31 |
ok(defined &foo, 'use line dsl can foo'); |
| 32 |
is(foo('bar'), 'bar', 'use line Foo returns bar'); |
| 33 |
|
| 34 |
package test2; |
| 35 |
use Test::More; |
| 36 |
|
| 37 |
ok(!defined &foo, 'intermediate package has no polluted namespace'); |
| 38 |
|
| 39 |
package test3; |
| 40 |
use Test::More; |
| 41 |
use FindBin; |
| 42 |
use Path::Tiny qw< path >; |
| 43 |
|
| 44 |
BEGIN { |
| 45 |
$ENV{DANCER_CONFDIR} = path( $FindBin::Bin, 'extend_config' )->stringify; |
| 46 |
} |
| 47 |
|
| 48 |
use Dancer2; |
| 49 |
|
| 50 |
ok(defined &foo, 'config specified DSL can foo'); |
| 51 |
is(foo('baz'), 'baz', 'config specified Foo returns baz'); |
| 52 |
|
| 53 |
done_testing; |