File: disp_named_capture.t

package info (click to toggle)
libdancer2-perl 0.207000%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,460 kB
  • sloc: perl: 8,069; makefile: 7
file content (35 lines) | stat: -rw-r--r-- 719 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
use warnings;
use strict;

use Plack::Test;
use HTTP::Request;
use Test::More tests => 2;

{
    package app;
    use Dancer2;
    get '/1' => sub {
        return '1';
    };
    get '/2' => sub {
        return '2';
    };
}

my $test = Plack::Test->create( app->to_app );
my $request  = HTTP::Request->new( GET => 'http://localhost/1' );
my $response = $test->request( $request );
is( $response->content, 1 );

# "Dummy" regex to populate global $+
# eval'd as named captures are not available until 5.10
my $c;
eval <<'NAMED';
"12345" =~ m#(?<capture>23)#;
$c = $+{capture};
NAMED

$request  = HTTP::Request->new( GET => 'http://localhost/2' );
$response = $test->request( $request );
is( $response->content, 2 );