view release on metacpan or search on metacpan
--- #YAML:1.0
name: ASP4x-Router
version: 0.022
abstract: URL Routing for your ASP4 web application.
author:
- John Drago <jdrago_999@yahoo.com>
license: perl
distribution_type: module
test_requires:
Test::More: 0
requires:
Carp: 0
ASP4: 1.080
Router::Generic: 0.016
recommends:
Apache2::RequestRec: 0
no_index:
directory:
inc/Module/Install/Metadata.pm view on Meta::CPAN
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
my @scalar_keys = qw{
name
module_name
abstract
author
version
distribution_type
tests
installdirs
};
my @tuple_keys = qw{
configure_requires
build_requires
requires
recommends
bundles
inc/Module/Install/Metadata.pm view on Meta::CPAN
while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
$self->feature( $name, @$mods );
}
return $self->{values}{features}
? @{ $self->{values}{features} }
: ();
}
sub no_index {
my $self = shift;
my $type = shift;
push @{ $self->{values}{no_index}{$type} }, @_ if $type;
return $self->{values}{no_index};
}
sub read {
my $self = shift;
$self->include_deps( 'YAML::Tiny', 0 );
require YAML::Tiny;
my $data = YAML::Tiny::LoadFile('META.yml');
lib/ASP4x/Router.pm view on Meta::CPAN
}
...
]
...
"routes": [
{
"include_routes": "@ServerRoot@/conf/routes.json"
},
{
"name": "CreatePage",
"path": "/main/:type/create",
"target": "/pages/create.asp",
"method": "GET"
},
{
"name": "Create",
"path": "/main/:type/create",
"target": "/handlers/dev.create",
"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 }
},
{
"name": "Delete",
"path": "/main/:type/{id:\\d+}/delete",
"target": "/handlers/dev.delete",
"method": "POST"
}
]
...
}
...
% In your ASP scripts and Handlers:
<%
# 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
t/010-basic/020-rest-crud.t view on Meta::CPAN
$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."
);
EXTERNAL_ROUTES: {
ok( my $res = $api->ua->get('/foo/foo/'), "GET /foo/foo/" );
ok( $res->is_success, "/foo/foo/ was successful" );
like $res->content => qr(You have reached foo.asp), "content looks right";
};
t/conf/asp4-config.json view on Meta::CPAN
"uri_match": "/.*",
"disable_session": true
}
],
"routes": [
{
"include_routes": "@ServerRoot@/conf/routes.json"
},
{
"name": "CreatePage",
"path": "/main/:type/create",
"target": "/pages/create.asp",
"method": "GET"
},
{
"name": "Create",
"path": "/main/:type/create",
"target": [ "/handlers/dev.[:type:].create", "/handlers/dev.create" ],
"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 }
},
{
"name": "Delete",
"path": "/main/:type/{id:\\d+}/delete",
"target": "/handlers/dev.delete",
"method": "POST"
}
]
},
"data_connections": {
"session": {
"manager": "ASP4::SessionStateManager::NonPersisted",
"cookie_name": "session-id",
"cookie_domain": "*",
t/handlers/dev/create.pm view on Meta::CPAN
use strict;
use warnings 'all';
use base 'ASP4::FormHandler';
use vars __PACKAGE__->VARS;
sub run
{
my ($s, $context) = @_;
$Response->Write("Create $Form->{type}");
}# end run()
1;# return true:
t/handlers/dev/delete.pm view on Meta::CPAN
use strict;
use warnings 'all';
use base 'ASP4::FormHandler';
use vars __PACKAGE__->VARS;
sub run
{
my ($s, $context) = @_;
$Response->Write("Delete $Form->{type} id $Form->{id}");
}# end run()
1;# return true:
t/handlers/dev/edit.pm view on Meta::CPAN
use strict;
use warnings 'all';
use base 'ASP4::FormHandler';
use vars __PACKAGE__->VARS;
sub run
{
my ($s, $context) = @_;
$Response->Write("Edit $Form->{type} id $Form->{id}");
}# end run()
1;# return true:
t/htdocs/pages/create.asp view on Meta::CPAN
CreatePage <%= $Form->{type} %>
t/htdocs/pages/edit.asp view on Meta::CPAN
EditPage <%= $Form->{type} %> id <%= $Form->{id} %>
t/htdocs/pages/list.asp view on Meta::CPAN
List <%= $Form->{type} %> page <%= $Form->{page} %>
t/htdocs/pages/view.asp view on Meta::CPAN
View <%= $Form->{type} %> id <%= $Form->{id} %>