From: Guillermo Roditi Date: Mon, 23 Jun 2008 20:58:14 +0000 (+0000) Subject: DispatchType stripped of CAF, SUPER and substituted instances of $self->{*} with... X-Git-Tag: 5.8000_03~132 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=3c0186f29e8864c86aca75f03f8d8ac1afd5507d DispatchType stripped of CAF, SUPER and substituted instances of $self->{*} with attributes. r16970@martha (orig r7493): groditi | 2008-03-14 18:01:52 -0400 --- diff --git a/lib/Catalyst/DispatchType.pm b/lib/Catalyst/DispatchType.pm index f8476eb..99ce561 100644 --- a/lib/Catalyst/DispatchType.pm +++ b/lib/Catalyst/DispatchType.pm @@ -1,7 +1,6 @@ package Catalyst::DispatchType; -use strict; -use base 'Class::Accessor::Fast'; +use Moose; =head1 NAME @@ -13,7 +12,7 @@ See L. =head1 DESCRIPTION -This is an abstract base class for Dispatch Types. +This is an abstract base class for Dispatch Types. =head1 METHODS @@ -38,7 +37,7 @@ sub match { die "Abstract method!" } =head2 $self->register( $c, $action ) abstract method, to be implemented by dispatchtypes. Takes a -context object and a L object. +context object and a L object. Should return true if it registers something, or false otherwise. diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index 02f4c21..bc12721 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -1,11 +1,33 @@ package Catalyst::DispatchType::Chained; -use strict; -use base qw/Catalyst::DispatchType/; +use Moose; use Text::SimpleTable; use Catalyst::ActionChain; use URI; +extends 'Catalyst::DispatchType'; + +has _endpoints => ( + isa => 'rw', + isa => 'ArrayRef', + required => 1, + default => sub{ [] }, + ); + +has _actions => ( + isa => 'rw', + isa => 'HashRef', + required => 1, + default => sub{ {} }, + ); + +has _children_of => ( + isa => 'rw', + isa => 'HashRef', + required => 1, + default => sub{ {} }, + ); + # please don't perltidy this. hairy code within. =head1 NAME @@ -41,7 +63,7 @@ Debug output for Path Part dispatch points sub list { my ( $self, $c ) = @_; - return unless $self->{endpoints}; + return unless $self->_endpoints; my $paths = Text::SimpleTable->new( [ 35, 'Path Spec' ], [ 36, 'Private' ] @@ -49,7 +71,7 @@ sub list { ENDPOINT: foreach my $endpoint ( sort { $a->reverse cmp $b->reverse } - @{ $self->{endpoints} } + @{ $self->_endpoints } ) { my $args = $endpoint->attributes->{Args}->[0]; my @parts = (defined($args) ? (("*") x $args) : '...'); @@ -65,7 +87,7 @@ sub list { if (defined $pp->[0] && length $pp->[0]); } $parent = $curr->attributes->{Chained}->[0]; - $curr = $self->{actions}{$parent}; + $curr = $self->_actions->{$parent}; unshift(@parents, $curr) if $curr; } next ENDPOINT unless $parent eq '/'; # skip dangling action @@ -125,7 +147,7 @@ Recursive search for a matching chain. sub recurse_match { my ( $self, $c, $parent, $path_parts ) = @_; - my $children = $self->{children_of}{$parent}; + my $children = $self->_children_of->{$parent}; return () unless $children; my $best_action; my @captures; @@ -175,7 +197,7 @@ sub recurse_match { # No best action currently # OR This one matches with fewer parts left than the current best action, # And therefore is a better match - # OR No parts and this expects 0 + # OR No parts and this expects 0 # The current best action might also be Args(0), # but we couldn't chose between then anyway so we'll take the last seen @@ -232,7 +254,7 @@ sub register { $action->attributes->{Chained} = [ $parent ]; - my $children = ($self->{children_of}{$parent} ||= {}); + my $children = $self->_children_of->{$parent}; my @path_part = @{ $action->attributes->{PathPart} || [] }; @@ -256,10 +278,10 @@ sub register { unshift(@{ $children->{$part} ||= [] }, $action); - ($self->{actions} ||= {})->{'/'.$action->reverse} = $action; + $self->_actions->{'/'.$action->reverse} = $action; unless ($action->attributes->{CaptureArgs}) { - unshift(@{ $self->{endpoints} ||= [] }, $action); + unshift(@{ $self->_endpoints }, $action); } return 1; @@ -294,7 +316,7 @@ sub uri_for_action { if (defined($pp->[0]) && length($pp->[0])); } $parent = $curr->attributes->{Chained}->[0]; - $curr = $self->{actions}{$parent}; + $curr = $self->_actions->{$parent}; } return undef unless $parent eq '/'; # fail for dangling action @@ -302,7 +324,7 @@ sub uri_for_action { return undef if @captures; # fail for too many captures return join('/', '', @parts); - + } =head1 USAGE @@ -463,7 +485,7 @@ this debugging output: '-----------------------+------------------------------' ... -Here's a more detailed specification of the attributes belonging to +Here's a more detailed specification of the attributes belonging to C<:Chained>: =head2 Attributes diff --git a/lib/Catalyst/DispatchType/Default.pm b/lib/Catalyst/DispatchType/Default.pm index fc734dd..94f5b50 100644 --- a/lib/Catalyst/DispatchType/Default.pm +++ b/lib/Catalyst/DispatchType/Default.pm @@ -1,7 +1,7 @@ package Catalyst::DispatchType::Default; -use strict; -use base qw/Catalyst::DispatchType/; +use Moose; +extends 'Catalyst::DispatchType'; =head1 NAME diff --git a/lib/Catalyst/DispatchType/Index.pm b/lib/Catalyst/DispatchType/Index.pm index f99e41c..8ffda14 100644 --- a/lib/Catalyst/DispatchType/Index.pm +++ b/lib/Catalyst/DispatchType/Index.pm @@ -1,7 +1,7 @@ package Catalyst::DispatchType::Index; -use strict; -use base qw/Catalyst::DispatchType/; +use Moose; +extends 'Catalyst::DispatchType'; =head1 NAME diff --git a/lib/Catalyst/DispatchType/Path.pm b/lib/Catalyst/DispatchType/Path.pm index d832dce..925b4ac 100644 --- a/lib/Catalyst/DispatchType/Path.pm +++ b/lib/Catalyst/DispatchType/Path.pm @@ -1,10 +1,18 @@ package Catalyst::DispatchType::Path; -use strict; -use base qw/Catalyst::DispatchType/; +use Moose; use Text::SimpleTable; use URI; +extends 'Catalyst::DispatchType'; + +has _paths => ( + is => 'rw', + isa => 'HashRef', + required => 1, + default => sub {{}} + ); + =head1 NAME Catalyst::DispatchType::Path - Path DispatchType @@ -25,15 +33,17 @@ Debug output for Path dispatch points sub list { my ( $self, $c ) = @_; - my $paths = Text::SimpleTable->new( [ 35, 'Path' ], [ 36, 'Private' ] ); - foreach my $path ( sort keys %{ $self->{paths} } ) { + my %paths = %{ $self->_paths }; + my @keys = sort keys %paths; + return unless @keys; + my $paths_table = Text::SimpleTable->new( [ 35, 'Path' ], [ 36, 'Private' ] ); + foreach my $path ( @keys ) { my $display_path = $path eq '/' ? $path : "/$path"; - foreach my $action ( @{ $self->{paths}->{$path} } ) { - $paths->row( $display_path, "/$action" ); + foreach my $action ( @{ $paths{$path} } ) { + $paths_table->row( $display_path, "/$action" ); } } - $c->log->debug( "Loaded Path actions:\n" . $paths->draw . "\n" ) - if ( keys %{ $self->{paths} } ); + $c->log->debug( "Loaded Path actions:\n" . $paths_table->draw . "\n" ); } =head2 $self->match( $c, $path ) @@ -49,7 +59,7 @@ sub match { $path ||= '/'; - foreach my $action ( @{ $self->{paths}->{$path} || [] } ) { + foreach my $action ( @{ $self->_paths->{$path} || [] } ) { next unless $action->match($c); $c->req->action($path); $c->req->match($path); @@ -90,7 +100,7 @@ sub register_path { $path = '/' unless length $path; $path = URI->new($path)->canonical; - unshift( @{ $self->{paths}{$path} ||= [] }, $action); + unshift( @{ $self->_paths->{$path} ||= [] }, $action); return 1; } diff --git a/lib/Catalyst/DispatchType/Regex.pm b/lib/Catalyst/DispatchType/Regex.pm index 80b9f2f..af9a11a 100644 --- a/lib/Catalyst/DispatchType/Regex.pm +++ b/lib/Catalyst/DispatchType/Regex.pm @@ -1,10 +1,12 @@ package Catalyst::DispatchType::Regex; -use strict; -use base qw/Catalyst::DispatchType::Path/; +use Moose; +extends 'Catalyst::DispatchType::Path'; use Text::SimpleTable; use Text::Balanced (); +has _compiled => (is => 'rw', isa => 'ArrayRef', required => 1, default => sub{[]}); + =head1 NAME Catalyst::DispatchType::Regex - Regex DispatchType @@ -25,13 +27,14 @@ Output a table of all regex actions, and their private equivalent. sub list { my ( $self, $c ) = @_; + my @regexes = @{ $self->_compiled }; + return unless @regexes; my $re = Text::SimpleTable->new( [ 35, 'Regex' ], [ 36, 'Private' ] ); - for my $regex ( @{ $self->{compiled} } ) { + for my $regex ( @regexes ) { my $action = $regex->{action}; $re->row( $regex->{path}, "/$action" ); } - $c->log->debug( "Loaded Regex actions:\n" . $re->draw . "\n" ) - if ( @{ $self->{compiled} } ); + $c->log->debug( "Loaded Regex actions:\n" . $re->draw . "\n" ); } =head2 $self->match( $c, $path ) @@ -43,14 +46,14 @@ altering $c. =cut -sub match { +override match => sub { my ( $self, $c, $path ) = @_; - return if $self->SUPER::match( $c, $path ); + return if super(); # Check path against plain text first - foreach my $compiled ( @{ $self->{compiled} || [] } ) { + foreach my $compiled ( @{ $self->_compiled } ) { if ( my @captures = ( $path =~ $compiled->{re} ) ) { next unless $compiled->{action}->match($c); $c->req->action( $compiled->{path} ); @@ -90,7 +93,7 @@ sub register { =head2 $self->register_regex($c, $re, $action) -Register an individual regex on the action. Usually called from the +Register an individual regex on the action. Usually called from the register method. =cut @@ -98,7 +101,7 @@ register method. sub register_regex { my ( $self, $c, $re, $action ) = @_; push( - @{ $self->{compiled} }, # and compiled regex for us + @{ $self->_compiled }, # and compiled regex for us { re => qr#$re#, action => $action,