ASP4x-Router
view release on metacpan or search on metacpan
META.yml
t/010-basic/010-compile.t
t/010-basic/020-rest-crud.t
t/010-basic/030-non-routed.t
t/conf/asp4-config.json
t/conf/httpd.conf
t/conf/routes.json
t/handlers/dev/boat/create.pm
t/handlers/dev/create.pm
t/handlers/dev/delete.pm
t/handlers/dev/edit.pm
t/htdocs/foo/foo.asp
t/htdocs/no-routing/another.asp
t/htdocs/no-routing/index.asp
t/htdocs/pages/create.asp
t/htdocs/pages/edit.asp
t/htdocs/pages/list.asp
t/htdocs/pages/view.asp
lib/ASP4x/Router.pm view on Meta::CPAN
"method": "POST"
},
{
"name": "View",
"path": "/main/:type/{id:\\d+}",
"target": "/pages/view.asp",
"method": "*"
},
{
"name": "EditPage",
"path": "/main/:type/{id:\\d+}/edit",
"target": "/pages/edit.asp",
"method": "GET"
},
{
"name": "Edit",
"path": "/main/:type/{id:\\d+}/edit",
"target": "/handlers/dev.edit",
"method": "POST"
},
{
"name": "List",
"path": "/main/:type/list/{page:\\d*}",
"target": "/pages/list.asp",
"method": "*",
"defaults": { "page": 1 }
},
{
lib/ASP4x/Router.pm view on Meta::CPAN
# Get the router:
my $router = $Config->web->router;
# Get the uri:
my $uri = $router->uri_for('EditPage', { type => 'truck', id => 123 });
%>
<a href="<%= $Server->HTMLEncode( $uri ) %>">Edit this Truck</a>
Comes out like this:
<a href="/main/truck/123/edit/">Edit this Truck</a>
=head1 DESCRIPTION
For a gentle introduction to URL Routing in general, see L<Router::Generic>, since
C<ASP4x::Router> uses L<Router::Generic> to handle all the routing logic.
Long story short - URL Routing can help decouple the information architecture from
the actual layout of files on disk.
=head2 How does it work?
t/010-basic/020-rest-crud.t view on Meta::CPAN
# View via GET
$res = $api->ua->get("/main/truck/1/");
is( $res->content => "View truck id 1\n", "GET '/main/truck/1/' correct");
# View via POST
$res = $api->ua->post("/main/truck/1/");
is( $res->content => "View truck id 1\n", "POST '/main/truck/1/' correct");
# EditPage
$res = $api->ua->get("/main/truck/1/edit/");
is( $res->content => "EditPage truck id 1\n", "GET '/main/truck/1/edit/' correct");
# Edit handler
$res = $api->ua->post("/main/truck/1/edit/");
is( $res->content => "Edit truck id 1", "POST '/main/truck/1/edit/' correct");
# Delete handler
$res = $api->ua->post("/main/truck/1/delete/");
is( $res->content => "Delete truck id 1", "POST '/main/truck/1/delete/' correct");
is(
'/main/truck/create/' =>
$api->context->config->web->router->uri_for('CreatePage', { type => 'truck' }),
"Got router and uri_for(...) just fine."
t/conf/asp4-config.json view on Meta::CPAN
"method": "POST"
},
{
"name": "View",
"path": "/main/:type/{id:\\d+}",
"target": "/pages/view.asp",
"method": "*"
},
{
"name": "EditPage",
"path": "/main/:type/{id:\\d+}/edit",
"target": "/pages/edit.asp",
"method": "GET"
},
{
"name": "Edit",
"path": "/main/:type/{id:\\d+}/edit",
"target": "/handlers/dev.edit",
"method": "POST"
},
{
"name": "List",
"path": "/main/:type/list/{page:\\d*}",
"target": "/pages/list.asp",
"method": "*",
"defaults": { "page": 1 }
},
{
t/handlers/dev/edit.pm view on Meta::CPAN
package dev::edit;
use strict;
use warnings 'all';
use base 'ASP4::FormHandler';
use vars __PACKAGE__->VARS;
sub run
{
my ($s, $context) = @_;
( run in 0.375 second using v1.01-cache-2.11-cpan-de7293f3b23 )