Dancer2
view release on metacpan or search on metacpan
lib/Dancer2/Cookbook.pod view on Meta::CPAN
=head3 App-specific feature
Serializers are engines. They affect a Dancer Application, which means
that once you've set a serializer, B<all> routes within that package
will be serialized and deserialized. This is how the feature works.
As suggested above, if you would like to have both, you need to create
another application which will not be serialized.
A common usage for this is an API providing serialized endpoints (and
receiving serialized requests) and providing rendered pages.
# MyApp.pm
package MyApp;
use Dancer2;
# another useful feature:
set auto_page => 1;
get '/' => sub { template 'index' => {...} };
t/dsl/path.t view on Meta::CPAN
$plack_req->path_info,
'D2 path_info matches Plack path_info',
);
::is( $dancer_req->path, '/', 'D2 path is /' );
::is( $plack_req->path, '/', 'Plack path is /' );
return $dancer_req->script_name;
};
get '/endpoint' => sub {
my $dancer_req = request;
my $env = $dancer_req->env;
my $plack_req = Plack::Request->new($env);
::is(
$env->{'PATH_INFO'},
'/endpoint',
'PATH_INFO /endpoint',
);
::is(
$dancer_req->path_info,
$env->{'PATH_INFO'},
'D2 path_info matches $env',
);
::is(
$dancer_req->path_info,
$plack_req->path_info,
'D2 path_info matches Plack path_info',
);
::is( $dancer_req->path, '/endpoint', 'D2 path is /' );
::is( $plack_req->path, '/endpoint', 'Plack path is /' );
return $dancer_req->script_name;
};
}
subtest '/' => sub {
my $test = Plack::Test->create( App->to_app );
my $res = $test->request( GET '/' );
ok( $res->is_success, 'Result successful' );
is( $res->content, '', 'script_name is empty' );
};
subtest '/endpoint' => sub {
my $test = Plack::Test->create( App->to_app );
my $res = $test->request( GET '/endpoint' );
ok( $res->is_success, 'Result successful' );
is( $res->content, '', 'script_name is empty' );
};
subtest '/mounted/' => sub {
my $app = builder {
mount '/' => sub { [200,[],['OK']] };
mount '/mounted' => App->to_app;
};
my $test = Plack::Test->create($app);
my $res = $test->request( GET '/mounted/' );
ok( $res->is_success, 'Result successful' );
is( $res->content, '/mounted', 'script_name is /mounted' );
};
subtest '/mounted/endpoint' => sub {
my $app = builder {
mount '/' => sub { [200,[],['OK']] };
mount '/mounted' => App->to_app;
};
my $test = Plack::Test->create($app);
my $res = $test->request( GET '/mounted/endpoint' );
ok( $res->is_success, 'Result successful' );
is( $res->content, '/mounted', 'script_name is /mounted' );
};
# Tests behaviour when SCRIPT_NAME is also the beginning of PATH_INFO
# See the discussion in #1288.
subtest '/endpoint/endpoint' => sub {
my $app = builder {
mount '/' => sub { [200,[],['OK']] };
mount '/endpoint' => App->to_app;
};
my $test = Plack::Test->create($app);
my $res = $test->request( GET '/endpoint/endpoint' );
ok( $res->is_success, 'Result successful' );
is( $res->content, '/endpoint', 'script_name is /endpoint' );
};
( run in 0.302 second using v1.01-cache-2.11-cpan-b61123c0432 )