Skip to content

Commit

Permalink
eval named capture regex so tests pass on perl 5.8
Browse files Browse the repository at this point in the history
Named captures are only supported for perl 5.10+; with perl 5.8.9
throwing an error about the syntax of the named capture group
(only version tested). eval the regex as a string of code to "hide"
the named capture on perl < 5.10.
  • Loading branch information
veryrusty authored and xsawyerx committed Oct 16, 2016
1 parent ddfe254 commit 3cb8d86
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions t/disp_named_capture.t
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
package app;
use Dancer2;
get '/1' => sub {
return '1';
};
get '/2' => sub {
return '2';
};
package main;
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)#;
my $c = $+{capture};
$c = $+{capture};
NAMED

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

0 comments on commit 3cb8d86

Please sign in to comment.