File: extend.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 (53 lines) | stat: -rw-r--r-- 1,043 bytes parent folder | download | duplicates (5)
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
# define a sample DSL extension that will be used in the rest of these test
# This extends Dancer2::Core::DSL but provides an extra keyword
#
# Each test below creates a new package so it can load Dancer2
BEGIN {

    package Dancer2::Test::ExtendedDSL;

    use Moo;
    extends 'Dancer2::Core::DSL';

    sub BUILD {
        my ( $self ) = @_;
        $self->register(foo => 1);
    }

    sub foo {
        return $_[1];
    }
}

package main;

use Test::More tests => 5;

package test1;
use Test::More;

use Dancer2 dsl => 'Dancer2::Test::ExtendedDSL';

ok(defined &foo, 'use line dsl can foo');
is(foo('bar'), 'bar', 'use line Foo returns bar');

package test2;
use Test::More;

ok(!defined &foo, 'intermediate package has no polluted namespace');

package test3;
use Test::More;
use FindBin;
use File::Spec;

BEGIN {
    $ENV{DANCER_CONFDIR} = File::Spec->catdir($FindBin::Bin, 'extend_config');
}

use Dancer2;

ok(defined &foo, 'config specified DSL can foo');
is(foo('baz'), 'baz', 'config specified Foo returns baz');

done_testing;