File: disp_named_capture.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 (31 lines) | stat: -rw-r--r-- 637 bytes parent folder | download | duplicates (2)
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
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 $+
"12345" =~ m#(?<capture>23)#;
my $c = $+{capture};

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