X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FWeb%2FSimple.pm;h=960fc016c1efae41cfca1cd56c27a003227561a3;hb=4ed4fb42c2a30a541a4eae477c7ad35a81b39c30;hp=c899c3a1e8989ca236264e64520064520a9d5826;hpb=24175cb5e9ca7488610ff95014989e20bee55334;p=catagits%2FWeb-Simple.git diff --git a/lib/Web/Simple.pm b/lib/Web/Simple.pm index c899c3a..960fc01 100644 --- a/lib/Web/Simple.pm +++ b/lib/Web/Simple.pm @@ -4,7 +4,7 @@ use strict; use warnings FATAL => 'all'; use 5.008; -our $VERSION = '0.002'; +our $VERSION = '0.004'; sub setup_all_strictures { strict->import; @@ -23,7 +23,7 @@ sub setup_dispatch_strictures { sub import { setup_dispatch_strictures(); my ($class, $app_package) = @_; - $class->_export_into($app_package); + $class->_export_into($app_package||caller); } sub _export_into { @@ -31,7 +31,7 @@ sub _export_into { { no strict 'refs'; *{"${app_package}::dispatch"} = sub (&) { - $app_package->_setup_dispatcher([ $_[0]->() ]); + $app_package->_setup_dispatcher($_[0]); }; *{"${app_package}::response_filter"} = sub (&) { $app_package->_construct_response_filter($_[0]); @@ -39,13 +39,10 @@ sub _export_into { *{"${app_package}::redispatch_to"} = sub { $app_package->_construct_redispatch($_[0]); }; - *{"${app_package}::subdispatch"} = sub ($) { - $app_package->_construct_subdispatch($_[0]); - }; *{"${app_package}::default_config"} = sub { $app_package->_setup_default_config(@_); }; - *{"${app_package}::ENV"} = sub () { -1 }; + *{"${app_package}::PSGI_ENV"} = sub () { -1 }; *{"${app_package}::self"} = \${"${app_package}::self"}; require Web::Simple::Application; unshift(@{"${app_package}::ISA"}, 'Web::Simple::Application'); @@ -184,23 +181,23 @@ is encountered in other code. # matches: GET /user/1.htm?show_details=1 # GET /user/1.htm sub (GET + /user/* + ?show_details~ + .htm|.html|.xhtml) { - shift; my ($user_id, $show_details) = @_; + my ($self, $user_id, $show_details) = @_; ... }, # matches: POST /user?username=frew # POST /user?username=mst&first_name=matt&last_name=trout sub (POST + /user + ?username=&*) { - shift; my ($username, $misc_params) = @_; + my ($self, $username, $misc_params) = @_; ... }, # matches: DELETE /user/1/friend/2 sub (DELETE + /user/*/friend/*) { - shift; my ($user_id, $friend_id) = @_; + my ($self, $user_id, $friend_id) = @_; ... }, # matches: PUT /user/1?first_name=Matt&last_name=Trout sub (PUT + /user/* + ?first_name~&last_name~) { - shift; my ($user_id, $first_name, $last_name) = @_; + my ($self, $user_id, $first_name, $last_name) = @_; ... }, sub (/user/*/...) { @@ -214,7 +211,7 @@ is encountered in other code. }, # matches: DELETE /user/1/role/1 sub (DELETE + /role/*) { - my $role_id = shift; + my $role_id = $_[1]; ... }, ]; @@ -495,10 +492,10 @@ from subroutine prototypes, so this is equivalent to To gain the benefit of using some middleware, specifically Plack::Middleware::Session access to the ENV hash is needed. This is provided in arguments to the dispatched handler. You can access this hash with the -exported +ENV constant. +exported +PSGI_ENV constant. sub (GET + /foo + ?some_param=) { - my($self, $some_param, $env) = @_[0, 1, +ENV]; + my($self, $some_param, $env) = @_[0, 1, +PSGI_ENV]; =head1 EXPORTED SUBROUTINES