NAME
Terse::Controller - controllers made simple.
VERSION
Version 0.26
SYNOPSIS
package
Stocks;
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
AUTHOR
LNATION, <email at lnation.org>