Permalink
Browse files

Finish off the RequestMethod dispatcher, try a new Dispatcher event API.

  • Loading branch information...
1 parent c2b67be commit 14d46aa0b40f951d665c0c0225cdc5f142f6b44a @ubu ubu committed Mar 28, 2012
Showing with 15 additions and 18 deletions.
  1. +10 −1 lib/Magpie/Dispatcher/RequestMethod.pm
  2. +3 −6 lib/Magpie/Event.pm
  3. +2 −11 lib/Magpie/Resource.pm
@@ -1,8 +1,17 @@
package Magpie::Dispatcher::RequestMethod;
#ABSTRACT: INCOMPLETE - Placeholder for future Dispatcher Role
use Moose::Role;
+use Magpie::Constants;
+sub events { (qw(method_not_allowed), HTTP_METHODS) };
-sub load_queue {}
+sub load_queue {
+ my $self = shift;
+ my $method = $self->plack_request->method;
+ if ( scalar grep { $_ eq $method } HTTP_METHODS ) {
+ return $method;
+ }
+ return 'method_not_allowed';
+}
1;
View
@@ -185,7 +185,7 @@ sub load_handler {
my $handler = $self->current_handler;
my $handler_args = $self->current_handler_args || {};
#warn "load: current handler: $handler " . $self->has_error ." \n";
-
+
unless ( defined $self->fetch_handler( $handler ) ) {
# we only make it here if the app class was passed
# to the pipeline as the *name* of a class, rather
@@ -209,7 +209,7 @@ sub load_handler {
if ( $handler->isa('Plack::Middleware') ) {
Class::MOP::load_class( 'Magpie::Transformer::Middleware' );
- my $munged_args = {
+ my $munged_args = {
middleware_args => $handler_args,
middleware_class => $handler,
};
@@ -219,7 +219,7 @@ sub load_handler {
$self->current_handler_args($handler_args);
}
-
+
my $constructor = defined($handler_args->{traits}) ? 'new_with_traits' : 'new';
try {
@@ -447,9 +447,6 @@ sub init_queue {
my $pkg = $self->meta->name;
my @event_names = ();
-# if ( $self->has_dispatcher ) {
-# # XXX: pluggable dispatcher here
-# }
if ( $self->can('load_queue') ) {
@event_names = $self->load_queue($ctxt);
}
View
@@ -4,19 +4,10 @@ package Magpie::Resource;
use Moose;
extends 'Magpie::Component';
+with 'Magpie::Dispatcher::RequestMethod';
use Magpie::Constants;
-__PACKAGE__->register_events( qw(method_not_allowed), HTTP_METHODS );
-
-# XXX: Move to a real Dispactcher
-sub load_queue {
- my $self = shift;
- my $method = $self->plack_request->method;
- if ( scalar grep { $_ eq $method } HTTP_METHODS ) {
- return $method;
- }
- return 'method_not_allowed';
-}
+__PACKAGE__->register_events(Magpie::Dispatcher::RequestMethod::events());
has '+_trait_namespace' => ( default => 'Magpie::Plugin::Resource' );

0 comments on commit 14d46aa

Please sign in to comment.