Skip to content

Instantly share code, notes, and snippets.

@xuxiaodong
Forked from yanick/dancer.snippets
Created July 2, 2013 08:57
Show Gist options
  • Save xuxiaodong/5907751 to your computer and use it in GitHub Desktop.
Save xuxiaodong/5907751 to your computer and use it in GitHub Desktop.
extends perl
## ROUTE DEFINITIONS
snippet get "GET route" !b
get '/${1}' => sub {
${2:${VISUAL:...;}}
};
endsnippet
snippet put "PUT route" !b
put '/${1}' => sub {
${2:${VISUAL:...;}}
};
endsnippet
snippet post "POST route" !b
post '/${1}' => sub {
${2:${VISUAL:...;}}
};
endsnippet
snippet options "OPTIONS route" !b
options '/${1}' => sub {
${2:${VISUAL:...;}}
};
endsnippet
snippet del "DEL route" !b
del '/${1}' => sub {
${2:${VISUAL:...;}}
};
endsnippet
snippet patch "PATCH route" !b
patch '/${1}' => sub {
${2:${VISUAL:...;}}
};
endsnippet
## ROUTE ACTIONS
snippet template "process template" !b
${1:return} template ${2:$template}, ${3:{ %tokens } };
endsnippet
snippet redirect "external redirect" !
redirect ${1:$url};
endsnippet
snippet forward "forward" !b
forward ${1:$url}, ${2: { %params } }, ${3: { method => ${4:'POST'} } };
endsnippet
snippet halt "halt route" !b
halt ${1:$content};
endsnippet
snippet pass "pass to the next matching" !
pass
endsnippet
snippet splat "access route captures" !
my ( ${1:@values} ) = splat;
endsnippet
snippet params "route parameters" !
params
endsnippet
snippet param "route parameter" !
${1:my $param} = param ${2:'param'};
endsnippet
snippet send_error "return HTTP error" !b
send_error ${1:message}, ${2:code};
endsnippet
snippet send_file "send a file" !b
send_file ${1:$filename};
endsnippet
snippet upload "access to file upload" !b
${1:my $file} = upload(${2:name});
endsnippet
snippet session "access session info" !
session ${1:key} => ${2:value};
endsnippet
snippet uri_for "uri for path" !b
uri_for(${1:$path});
endsnippet
## SERIALISATION
snippet from_dumper "deserialise from Data::Dumper" !
from_dumper ${1:$struct};
endsnippet
snippet from_json "deserialise from JSON" !
from_json ${1:$struct}, ${2:%options};
endsnippet
snippet from_yaml "deserialise from YAML" !
from_yaml ${1:$struct};
endsnippet
snippet from_xml "deserialise from XML" !
from_xml ${1:$struct}, ${2:%options};
endsnippet
snippet to_dumper "serialise to Data::Dumper" !
to_dumper ${1:$struct};
endsnippet
snippet to_json "serialise from JSON" !
to_json ${1:$struct}, ${2:%options};
endsnippet
snippet to_yaml "serialise from YAML" !
to_yaml ${1:$struct};
endsnippet
snippet to_xml "serialise from XML" !
to_xml ${1:$struct}, ${2:%options};
endsnippet
## REQUEST & RESPONSE
snippet request "request object" !
request
endsnippet
snippet resposne "response object" !
response
endsnippet
snippet cookies "cookies" !b
cookies->{${1:name}}
endsnippet
snippet cookie "cookie" !b
cookie ${1:name} => ${2:value};
endsnippet
snippet set_cookie "set/update cookie" !b
set_cookie ${1:name} => ${2:value};
endsnippet
snippet content_type "content_type" !b
content_type '${1:text/html}';
endsnippet
snippet headers "headers" !b
headers $1;
endsnippet
snippet header "header" !b
header ${1:key} => ${2:value};
endsnippet
snippet push_header "push_header" !b
push_header ${1:key} => ${2:value};
endsnippet
snippet status "set response status code" !b
status ${1:500};
endsnippet
## LOGGING
snippet debug "debug message" !b
debug ${1:${VISUAL:message}};
endsnippet
snippet error "error message" !b
error ${1:${VISUAL:message}};
endsnippet
snippet info "info message" !b
info ${1:${VISUAL:message}};
endsnippet
snippet warning "warning message" !b
warning ${1:${VISUAL:message}};
endsnippet
## APPLICATION
snippet prefix "route prefix" !
prefix ${1:'/path'};
endsnippet
snippet hook "hook" !b
hook ${1} => sub {
${2:${VISUAL:...;}}
};
endsnippet
snippet config "config" !b
config->{${1:name}}
endsnippet
snippet set "define a setting" !b
set ${1:key} => ${2:value};
endsnippet
snippet setting "return a setting" !b
setting ${1:key};
endsnippet
snippet dance "dance" !b
dance;
endsnippet
snippet start "start application" !b
start;
endsnippet
snippet dancer_version "dancer_version" !
dancer_version;
endsnippet
snippet dirname "dirname" !
dirname(${2:$path})
endsnippet
snippet engine "engine" !
engine '${2:template}'
endsnippet
snippet false "false" !
false
endsnippet
snippet false "true" !
true
endsnippet
# UTILS
snippet path "create dir path" !
path( ${1: @path } )
endsnippet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment