File: from-config.t

package info (click to toggle)
libdancer2-perl 0.204002%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,384 kB
  • ctags: 660
  • sloc: perl: 8,047; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,138 bytes parent folder | download
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
61
62
63
64
65
66
67
68
69
70
use strict;
use warnings;

use Test::More tests => 5;

{
package Dancer2::Plugin::FromConfig;

use Dancer2::Plugin;

BEGIN {
has one => (
    is => 'ro',
    from_config => 1,
);

has three => (
    is => 'ro',
    from_config => 'two.three',
);

has four => (
    is => 'ro',
    from_config => 1,
    default => sub { 'quatre' },
);

has five => (
    is => 'ro',
    from_config => sub { 'cinq' },
);

has six => (
    is => 'ro',
    from_config => sub { 'six' },
    default => sub { 'AH!' },
    plugin_keyword => 1,
);

plugin_keywords qw/ one three four five /;

}
}

{
    package MyApp;

    use Dancer2;

    use Dancer2::Plugin::FromConfig;

    set plugins => {
        FromConfig => {
            one => 'un',
            two => {
                three => 'trois',
            }
        }
    };


    Test::More::is one() => 'un', 'from config';
    Test::More::is three() => 'trois', 'from config, nested';
    Test::More::is four() => 'quatre', 'nothing in config, default value';
    Test::More::is five() => 'cinq', 'from_config a coderef';
    Test::More::is six() => 'AH!', 'from_config a coderef, no override';
}