File: 103-input.t

package info (click to toggle)
libpath-dispatcher-declarative-perl 0.03-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 228 kB
  • ctags: 128
  • sloc: perl: 2,249; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,155 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 1;

my @calls;

do {
    package MyFramework::Dispatcher;
    use Path::Dispatcher::Declarative -base;

    on qr/a(rg)s/ => sub {
        push @calls, {
            from => "framework",
            args => [@_],
            it   => $_,
            one  => $1,
            two  => $2,
        };
    };

    package MyApp::Dispatcher;
    # this hack is here because "use" expects there to be a file for the module
    BEGIN { MyFramework::Dispatcher->import("-base") }

    on qr/ar(g)s/ => sub {
        push @calls, {
            from => "app",
            args => [@_],
            it   => $_,
            one  => $1,
            two  => $2,
        };
        next_rule;
    };

    redispatch_to(MyFramework::Dispatcher->dispatcher);
};

MyApp::Dispatcher->run('args', 1..3);
is_deeply([splice @calls], [
    {
        from => 'app',
        one  => 'g',
        two  => undef,
        it   => 'args',
        args => [1, 2, 3],
    },
    {
        from => 'framework',
        one  => 'rg',
        two  => undef,
        it   => 'args',
        args => [1, 2, 3],
    },
]);