X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FDispatcher.pm;h=855226a111915cf83a632b753d8c5dc96a9a638d;hb=e7bb8d339abdd9c9da0b8ac62f619f2e0e33cc89;hp=05101b93520cb969b3fe36a0c58e0b79a8a081ba;hpb=855ed93153e2b0c0e88d9bb8f23822c914393048;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 05101b9..855226a 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -17,7 +17,9 @@ use overload '""' => sub { return ref shift }, fallback => 1; __PACKAGE__->mk_accessors( qw/tree dispatch_types registered_dispatch_types - method_action_class action_container_class/ + method_action_class action_container_class + preload_dispatch_types postload_dispatch_types + / ); # Preload these action types @@ -38,6 +40,40 @@ See L. =head1 METHODS +=cut + +sub new { + my $self = shift; + my $class = ref($self) || $self; + + my $obj = $class->SUPER::new( @_ ); + + # set the default pre- and and postloads + $obj->preload_dispatch_types( \@PRELOAD ); + $obj->postload_dispatch_types( \@POSTLOAD ); + return $obj; +} + +=head2 $self->preload_dispatch_types + +An arrayref of pre-loaded dispatchtype classes + +Entries are considered to be available as C +To use a custom class outside the regular C namespace, prefix +it with a C<+>, like so: + + +My::Dispatch::Type + +=head2 $self->postload_dispatch_types + +An arrayref of post-loaded dispatchtype classes + +Entries are considered to be available as C +To use a custom class outside the regular C namespace, prefix +it with a C<+>, like so: + + +My::Dispatch::Type + =head2 $self->detach( $c, $command [, \@arguments ] ) =cut @@ -194,9 +230,10 @@ sub prepare_action { } # If not, move the last part path to args - unshift @args, pop @path; + my $arg = pop(@path); + $arg =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; + unshift @args, $arg; } - s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg for @args; $c->log->debug( 'Path is "' . $c->req->match . '"' ) if ( $c->debug && $c->req->match ); @@ -354,8 +391,8 @@ sub setup_actions { $self->action_container_class('Catalyst::ActionContainer'); # Preload action types - for my $type (@PRELOAD) { - my $class = "Catalyst::DispatchType::$type"; + for my $type ( @{$self->preload_dispatch_types} ) { + my $class = ($type =~ /^\+(.*)$/) ? $1 : "Catalyst::DispatchType::${type}"; eval "require $class"; Catalyst::Exception->throw( message => qq/Couldn't load "$class"/ ) if $@; @@ -373,8 +410,8 @@ sub setup_actions { } # Postload action types - for my $type (@POSTLOAD) { - my $class = "Catalyst::DispatchType::$type"; + for my $type ( @{$self->postload_dispatch_types} ) { + my $class = ($type =~ /^\+(.*)$/) ? $1 : "Catalyst::DispatchType::${type}"; eval "require $class"; Catalyst::Exception->throw( message => qq/Couldn't load "$class"/ ) if $@;