[Catalyst-commits] r7948 - in Catalyst-Runtime/5.80/trunk: . lib/Catalyst lib/Catalyst/DispatchType

groditi at dev.catalyst.perl.org groditi at dev.catalyst.perl.org
Mon Jun 23 21:58:14 BST 2008


Author: groditi
Date: 2008-06-23 21:58:14 +0100 (Mon, 23 Jun 2008)
New Revision: 7948

Modified:
   Catalyst-Runtime/5.80/trunk/
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Chained.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Default.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Index.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Path.pm
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Regex.pm
Log:
 r16970 at martha (orig r7493):  groditi | 2008-03-14 18:01:52 -0400
 DispatchType stripped of CAF, SUPER and substituted instances of $self->{*} with attributes. 



Property changes on: Catalyst-Runtime/5.80/trunk
___________________________________________________________________
Name: svk:merge
   - 1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst/trunk/Catalyst-Runtime:9763
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/trunk:7576
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/moose:7477
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-ChildOf:4443
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-Runtime-jrockway:5857
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-component-setup:4320
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-docs:4325
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/current/Catalyst-Runtime:5142
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst:4483
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst-Runtime:6165
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime:8339
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime-jrockway:8342
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime:6511
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime-current:10442
   + 1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst/trunk/Catalyst-Runtime:9763
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/trunk:7576
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/moose:7493
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-ChildOf:4443
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-Runtime-jrockway:5857
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-component-setup:4320
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-docs:4325
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/current/Catalyst-Runtime:5142
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst:4483
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst-Runtime:6165
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime:8339
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime-jrockway:8342
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime:6511
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime-current:10442

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Chained.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Chained.pm	2008-06-23 20:58:04 UTC (rev 7947)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Chained.pm	2008-06-23 20:58:14 UTC (rev 7948)
@@ -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 @@
 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 @@
 
     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 @@
                     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 @@
 
 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 @@
                 #    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 @@
 
     $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 @@
 
     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 @@
                 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 @@
     return undef if @captures; # fail for too many captures
 
     return join('/', '', @parts);
-   
+
 }
 
 =head1 USAGE
@@ -463,7 +485,7 @@
   '-----------------------+------------------------------'
   ...
 
-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

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Default.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Default.pm	2008-06-23 20:58:04 UTC (rev 7947)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Default.pm	2008-06-23 20:58:14 UTC (rev 7948)
@@ -1,7 +1,7 @@
 package Catalyst::DispatchType::Default;
 
-use strict;
-use base qw/Catalyst::DispatchType/;
+use Moose;
+extends 'Catalyst::DispatchType';
 
 =head1 NAME
 

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Index.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Index.pm	2008-06-23 20:58:04 UTC (rev 7947)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Index.pm	2008-06-23 20:58:14 UTC (rev 7948)
@@ -1,7 +1,7 @@
 package Catalyst::DispatchType::Index;
 
-use strict;
-use base qw/Catalyst::DispatchType/;
+use Moose;
+extends 'Catalyst::DispatchType';
 
 =head1 NAME
 

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Path.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Path.pm	2008-06-23 20:58:04 UTC (rev 7947)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Path.pm	2008-06-23 20:58:14 UTC (rev 7948)
@@ -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 @@
 
 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 @@
 
     $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 @@
     $path = '/' unless length $path;
     $path = URI->new($path)->canonical;
 
-    unshift( @{ $self->{paths}{$path} ||= [] }, $action);
+    unshift( @{ $self->_paths->{$path} ||= [] }, $action);
 
     return 1;
 }

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Regex.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Regex.pm	2008-06-23 20:58:04 UTC (rev 7947)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Regex.pm	2008-06-23 20:58:14 UTC (rev 7948)
@@ -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 @@
 
 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 @@
 
 =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 @@
 
 =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 @@
 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,

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType.pm	2008-06-23 20:58:04 UTC (rev 7947)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType.pm	2008-06-23 20:58:14 UTC (rev 7948)
@@ -1,7 +1,6 @@
 package Catalyst::DispatchType;
 
-use strict;
-use base 'Class::Accessor::Fast';
+use Moose;
 
 =head1 NAME
 
@@ -13,7 +12,7 @@
 
 =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 @@
 =head2 $self->register( $c, $action )
 
 abstract method, to be implemented by dispatchtypes. Takes a
-context object and a L<Catalyst::Action> object. 
+context object and a L<Catalyst::Action> object.
 
 Should return true if it registers something, or false otherwise.
 




More information about the Catalyst-commits mailing list