NAME
Terse::Controller - controllers made simple.
VERSION
Version 0.25
SYNOPSIS
package Stocks;
use base 'Terse::Controller';
sub login :any {
return 1;
}
sub auth_prevent :any(auth) {
return 0;
}
sub auth :get :post {
return $_[1]->delayed_response(sub { ... });;
}
sub purchase :get :delayed { # delayed attribute is the same as the above
... #1
}
sub purchase_virtual :get(purchase) :params(virtual => 1) {
... #2
}
sub purchase_post :post(purchase) {
... # 3
}
sub purchase_virtual_post :post(purchase) :params(virtual => 1) {
... # 4
}
sub other :get :path(foo/(.*)/bar) :captured(1) {
... # 5
}
sub group_chat :websocket {
my ($self, $context) = @_;
return (
connect => sub {
$_[0]->send('welcome');
},
retrieve => sub {
my ($websocket, $msg) = @_;
# $msg = '{"confrim_sha":"XXX", "message": "Howdy world."}';
if ($self->plugin->validate->user_message_sha($context, $websocket->graft('retrieved',$msg))) {
$websocket->send($websocket->retrieved->confirm_sha);
for my $open (%{ $self->websockets }) {
$self->websockets->$open->send($websocket->retrieved->message);
}
}
},
error => sub {
},
disconnect => sub {
}
);
}
1;
.... psgi ...
use Terse;
use Stocks;
our $api = Stocks->new();
sub {
my ($env) = (shift);
Terse->run(
plack_env => $env,
application => $api,
);
};
....
plackup Stocks.psgi
GET http://localhost:5000/?req=purchase #1
POST http://localhost:5000/ {"req":"purchase"} #3
GET http://localhost:5000/?req=purchase&virtual=1 #2
POST http://localhost:5000/ {"req":"purchase", "virtual":1} #4
GET http://localhost:5000/foo/555/bar #5
CONNECT ws://localhost:5000/?req=group_chat;
AUTHOR
LNATION, <email at lnation.org>