[Catalyst-commits] r10602 - in
Catalyst-Runtime/5.80/branches/index_default_fuckage:
lib/Catalyst lib/Catalyst/DispatchType t/aggregate t/lib
t/lib/TestAppIndexDefault t/lib/TestAppIndexDefault/Controller
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Sat Jun 20 05:11:54 GMT 2009
Author: caelum
Date: 2009-06-20 05:11:53 +0000 (Sat, 20 Jun 2009)
New Revision: 10602
Added:
Catalyst-Runtime/5.80/branches/index_default_fuckage/t/aggregate/live_component_controller_action_index_or_default.t
Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault.pm
Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault/
Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault/Controller/
Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault/Controller/DefaultAndPath.pm
Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault/Controller/IndexChained.pm
Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault/Controller/IndexPrivate.pm
Removed:
Catalyst-Runtime/5.80/branches/index_default_fuckage/t/aggregate/live_component_controller_action_named_index.t
Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexActionName.pm
Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexActionName/
Modified:
Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/Action.pm
Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/DispatchType/Path.pm
Log:
nicer action sorting for Path
Modified: Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/Action.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/Action.pm 2009-06-20 00:19:18 UTC (rev 10601)
+++ Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/Action.pm 2009-06-20 05:11:53 UTC (rev 10602)
@@ -18,8 +18,9 @@
=cut
use Moose;
-
+use Scalar::Util 'looks_like_number';
with 'MooseX::Emulate::Class::Accessor::Fast';
+use namespace::clean -except => 'meta';
has class => (is => 'rw');
has namespace => (is => 'rw');
@@ -28,8 +29,6 @@
has name => (is => 'rw');
has code => (is => 'rw');
-no Moose;
-
use overload (
# Stringify to reverse for debug output etc.
@@ -38,6 +37,10 @@
# Codulate to execute to invoke the encapsulated action coderef
'&{}' => sub { my $self = shift; sub { $self->execute(@_); }; },
+ # Which action takes precedence
+ 'cmp' => 'compare',
+ '<=>' => 'compare',
+
# Make general $stuff still work
fallback => 1,
@@ -70,6 +73,22 @@
return scalar( @{ $c->req->args } ) == $args;
}
+sub sort_order {
+ my $self = shift;
+
+ my ($args) = @{ $self->attributes->{Args} || [] };
+
+ return $args if looks_like_number($args);
+
+ return ~0;
+}
+
+sub compare {
+ my ($a1, $a2) = @_;
+
+ return $a1->sort_order <=> $a2->sort_order;
+}
+
__PACKAGE__->meta->make_immutable;
1;
Modified: Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/DispatchType/Path.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/DispatchType/Path.pm 2009-06-20 00:19:18 UTC (rev 10601)
+++ Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/DispatchType/Path.pm 2009-06-20 05:11:53 UTC (rev 10602)
@@ -6,7 +6,6 @@
use Text::SimpleTable;
use Catalyst::Utils;
use URI;
-use Scalar::Util ();
has _paths => (
is => 'rw',
@@ -62,16 +61,6 @@
if ( keys %{ $self->_paths } );
}
-sub _action_args_sort_order {
- my ( $self, $action ) = @_;
-
- my ($args) = @{ $action->attributes->{Args} || [] };
-
- return $args if Scalar::Util::looks_like_number($args);
-
- return ~0;
-}
-
=head2 $self->match( $c, $path )
For each action registered to this exact path, offers the action a chance to
@@ -85,12 +74,7 @@
$path = '/' if !defined $path || !length $path;
- # sort from least args to most
- my @actions = sort { $self->_action_args_sort_order($a) <=>
- $self->_action_args_sort_order($b) }
- @{ $self->_paths->{$path} || [] };
-
- foreach my $action ( @actions ) {
+ foreach my $action ( @{ $self->_paths->{$path} || [] } ) {
next unless $action->match($c);
$c->req->action($path);
$c->req->match($path);
@@ -133,6 +117,8 @@
unshift( @{ $self->_paths->{$path} ||= [] }, $action);
+ $self->_paths->{$path} = [ sort @{ $self->_paths->{$path} } ];
+
return 1;
}
Added: Catalyst-Runtime/5.80/branches/index_default_fuckage/t/aggregate/live_component_controller_action_index_or_default.t
===================================================================
--- Catalyst-Runtime/5.80/branches/index_default_fuckage/t/aggregate/live_component_controller_action_index_or_default.t (rev 0)
+++ Catalyst-Runtime/5.80/branches/index_default_fuckage/t/aggregate/live_component_controller_action_index_or_default.t 2009-06-20 05:11:53 UTC (rev 10602)
@@ -0,0 +1,32 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+
+our $iters;
+
+BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
+
+use Test::More tests => 3*$iters;
+
+use Catalyst::Test 'TestAppIndexDefault';
+
+if ( $ENV{CAT_BENCHMARK} ) {
+ require Benchmark;
+ Benchmark::timethis( $iters, \&run_tests );
+}
+else {
+ for ( 1 .. $iters ) {
+ run_tests();
+ }
+}
+
+sub run_tests {
+ is(get('/indexchained'), 'index_chained', ':Chained overrides index');
+ is(get('/indexprivate'), 'index_private', 'index : Private still works');
+ is(get('/defaultandpath/path_one_arg'), 'path_one_arg',
+ 'Path overrides default');
+}
Deleted: Catalyst-Runtime/5.80/branches/index_default_fuckage/t/aggregate/live_component_controller_action_named_index.t
===================================================================
--- Catalyst-Runtime/5.80/branches/index_default_fuckage/t/aggregate/live_component_controller_action_named_index.t 2009-06-20 00:19:18 UTC (rev 10601)
+++ Catalyst-Runtime/5.80/branches/index_default_fuckage/t/aggregate/live_component_controller_action_named_index.t 2009-06-20 05:11:53 UTC (rev 10602)
@@ -1,29 +0,0 @@
-#!perl
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib "$FindBin::Bin/../lib";
-
-our $iters;
-
-BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
-
-use Test::More tests => 1*$iters;
-
-use Catalyst::Test 'TestAppIndexActionName';
-
-if ( $ENV{CAT_BENCHMARK} ) {
- require Benchmark;
- Benchmark::timethis( $iters, \&run_tests );
-}
-else {
- for ( 1 .. $iters ) {
- run_tests();
- }
-}
-
-sub run_tests {
- is(get('/indexchained'), 'index_chained', ':Chained overrides index');
-}
Deleted: Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexActionName.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexActionName.pm 2009-06-20 00:19:18 UTC (rev 10601)
+++ Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexActionName.pm 2009-06-20 05:11:53 UTC (rev 10602)
@@ -1,8 +0,0 @@
-package TestAppIndexActionName;
-use strict;
-use warnings;
-use Catalyst;
-
-__PACKAGE__->setup;
-
-1;
Added: Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault/Controller/DefaultAndPath.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault/Controller/DefaultAndPath.pm (rev 0)
+++ Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault/Controller/DefaultAndPath.pm 2009-06-20 05:11:53 UTC (rev 10602)
@@ -0,0 +1,15 @@
+package TestAppIndexDefault::Controller::DefaultAndPath;
+
+use base 'Catalyst::Controller';
+
+sub default : Private {
+ my ($self, $c) = @_;
+ $c->res->body('default');
+}
+
+sub path_one_arg : Path('/') Args(1) {
+ my ($self, $c) = @_;
+ $c->res->body('path_one_arg');
+}
+
+1;
Added: Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault/Controller/IndexChained.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault/Controller/IndexChained.pm (rev 0)
+++ Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault/Controller/IndexChained.pm 2009-06-20 05:11:53 UTC (rev 10602)
@@ -0,0 +1,12 @@
+package TestAppIndexDefault::Controller::IndexChained;
+
+use base 'Catalyst::Controller';
+
+sub index : Chained('/') PathPart('indexchained') CaptureArgs(0) {}
+
+sub index_endpoint : Chained('index') PathPart('') Args(0) {
+ my ($self, $c) = @_;
+ $c->res->body('index_chained');
+}
+
+1;
Added: Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault/Controller/IndexPrivate.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault/Controller/IndexPrivate.pm (rev 0)
+++ Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault/Controller/IndexPrivate.pm 2009-06-20 05:11:53 UTC (rev 10602)
@@ -0,0 +1,10 @@
+package TestAppIndexDefault::Controller::IndexPrivate;
+
+use base 'Catalyst::Controller';
+
+sub index : Private {
+ my ($self, $c) = @_;
+ $c->res->body('index_private');
+}
+
+1;
Copied: Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault.pm (from rev 10600, Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexActionName.pm)
===================================================================
--- Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault.pm (rev 0)
+++ Catalyst-Runtime/5.80/branches/index_default_fuckage/t/lib/TestAppIndexDefault.pm 2009-06-20 05:11:53 UTC (rev 10602)
@@ -0,0 +1,8 @@
+package TestAppIndexDefault;
+use strict;
+use warnings;
+use Catalyst;
+
+__PACKAGE__->setup;
+
+1;
More information about the Catalyst-commits
mailing list