File: 200-payload.t

package info (click to toggle)
libpath-dispatcher-perl 1.05-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 404 kB
  • ctags: 194
  • sloc: perl: 2,186; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 696 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
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Path::Dispatcher;

my $dispatcher = Path::Dispatcher->new(
    rules => [
        Path::Dispatcher::Rule::Regex->new(
            regex   => qr/^(\w+)$/,
            payload => 'all the money',
        ),
    ],
);

my $dispatch = $dispatcher->dispatch('hello');
ok($dispatch->has_matches);

my $match = $dispatch->first_match;
ok($match->rule->isa('Path::Dispatcher::Rule::Regex'));
ok($match->rule->payload, 'all the money');
ok($match->payload, 'all the money');

like(exception {
    $dispatch->run
}, qr/Payload is not a coderef/);

like(exception {
    $dispatcher->run('bye')
}, qr/Payload is not a coderef/);

done_testing;