Skip to content

Instantly share code, notes, and snippets.

@typester
Created February 17, 2009 05:44
Show Gist options
  • Save typester/65594 to your computer and use it in GitHub Desktop.
Save typester/65594 to your computer and use it in GitHub Desktop.
package MyApp;
use Ark 'Core';
MyApp->config({
# Catalyst like global config
# 'Controller::Root' => { namespace => '' },
});
1;
package MyApp::Controller::Root;
use Ark 'Controller';
has '+namespace' => default => '';
no Ark;
# default 404 handler
sub default :Path :Args {
my ($self, $req) = @_;
response(
status => 404,
body => '404 Not Found',
);
}
# index
sub index :Path :Args(0) {
my ($self, $req) = @_;
response( body => 'index' );
}
# local
sub local :Local :Args(0) {
my ($self, $req) = @_;
response( body => 'local' );
}
# with args
sub arg :Local :Args(1) {
my ($self, $req, $arg) = @_;
response( body => 'arg: ' . $arg);
}
# regexp
sub regex :Regex('^regex/(.*?)/(.*?)') {
my ($self, $req, $match1, $match2) = @_;
response( body => 'regex: ' . $match1 . ', ' . $match2 );
}
# chained
sub user :Chained('/') :PathPart('') :CaptureArgs(1) {
my ($self, $req, $user) = @_;
$req->stash->{user} = $user;
}
sub user_hello :Chained('user') :PathPart('hello') :Args(0) {
my ($self, $req) = @_;
response( body => 'Hello ' . $req->stash->{user} );
}
1;
#!/usr/bin/env perl
use strict;
use warnings;
use lib 'lib';
use HTTP::Engine;
use MyApp;
my $app = MyApp->new;;
$app->setup;
my $engine = HTTP::Engine->new(
interface => {
module => 'ServerSimple',
args => {
host => '0.0.0.0',
port => 4423,
},
request_handler => $app->handler,
},
);
$engine->run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment