Permalink
Browse files

added put and delete methods.

  • Loading branch information...
1 parent d955799 commit bd3a48378eb6bc9a1a3f7ce7966e14bf2457f64a @dann committed Oct 12, 2010
Showing with 15 additions and 2 deletions.
  1. +15 −2 lib/Pinatra.pm
View
@@ -20,7 +20,7 @@ sub import {
*{"${caller}::pina"} = \&pina;
# HTTP methods
- my @http_methods = qw/get post/;
+ my @http_methods = qw/get post put del/;
for my $http_method (@http_methods) {
*{"${caller}\::$http_method"} = sub { goto \&$http_method };
}
@@ -41,7 +41,7 @@ sub _stub {
}
{
- my @Declarations = qw(get post);
+ my @Declarations = qw(get post put del);
for my $keyword (@Declarations) {
no strict 'refs';
*$keyword = _stub $keyword;
@@ -55,7 +55,10 @@ sub pina (&) {
no warnings 'redefine';
local *get = sub { do_get(@_) };
local *post = sub { do_post(@_) };
+ local *put = sub { do_put(@_) };
+ local *del = sub { do_del(@_) };
$block->();
+
return sub { dispatch(shift) }
}
}
@@ -76,6 +79,16 @@ sub do_post {
route( $pattern, $code, 'POST' );
}
+sub do_put {
+ my ( $pattern, $code ) = @_;
+ route( $pattern, $code, 'PUT' );
+}
+
+sub do_del {
+ my ( $pattern, $code ) = @_;
+ route( $pattern, $code, 'DELETE' );
+}
+
# render
sub html {
return [ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ], [shift] ];

0 comments on commit bd3a483

Please sign in to comment.