[Catalyst-commits] r10661 - in Catalyst-Runtime/5.80/trunk: . lib
lib/Catalyst t/aggregate t/lib/TestApp/Controller/Action
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Thu Jun 25 09:49:36 GMT 2009
Author: caelum
Date: 2009-06-25 09:49:35 +0000 (Thu, 25 Jun 2009)
New Revision: 10661
Modified:
Catalyst-Runtime/5.80/trunk/
Catalyst-Runtime/5.80/trunk/Changes
Catalyst-Runtime/5.80/trunk/Makefile.PL
Catalyst-Runtime/5.80/trunk/TODO
Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
Catalyst-Runtime/5.80/trunk/lib/Catalyst/Controller.pm
Catalyst-Runtime/5.80/trunk/lib/Catalyst/Dispatcher.pm
Catalyst-Runtime/5.80/trunk/lib/Catalyst/Utils.pm
Catalyst-Runtime/5.80/trunk/t/aggregate/live_component_controller_action_action.t
Catalyst-Runtime/5.80/trunk/t/aggregate/live_component_controller_action_path.t
Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Action/Action.pm
Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Action/Path.pm
Log:
r5367 at hlagh (orig r10459): t0m | 2009-06-06 05:56:50 -0700
Branch for mo namespace handling refactor
r5368 at hlagh (orig r10460): mo | 2009-06-06 06:33:53 -0700
refactor of namespace handling
r5369 at hlagh (orig r10461): mo | 2009-06-06 06:34:42 -0700
TODO fix
r5371 at hlagh (orig r10466): mo | 2009-06-07 04:14:23 -0700
controller actions without attributes which are defined via config
r5372 at hlagh (orig r10467): mo | 2009-06-07 04:49:58 -0700
removed commented code
r5373 at hlagh (orig r10468): mo | 2009-06-07 05:28:53 -0700
Added support for ~ prefix to plugins and action classes
r5374 at hlagh (orig r10469): mo | 2009-06-07 05:36:55 -0700
Changes patches
r5686 at hlagh (orig r10655): caelum | 2009-06-24 19:22:27 -0700
cleanup TODO
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/branches/compres:7999
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/branches/context_go:8001
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/trunk:8533
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/Catalyst-Test-Updates:8363
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/add_captures_to_visit:9546
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/index_default_fuckage:10646
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/moose:7911
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
8a9521aa-ff93-41d6-9f87-b05cafcdab40:/local/cat/Catalyst-Runtime/5.80/trunk:8157
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/branches/compres:7999
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/branches/context_go:8001
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/trunk:8533
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/Catalyst-Test-Updates:8363
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/add_captures_to_visit:9546
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/index_default_fuckage:10646
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/moose:7911
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/namespace_handling_refactor:10655
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
8a9521aa-ff93-41d6-9f87-b05cafcdab40:/local/cat/Catalyst-Runtime/5.80/trunk:8157
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/Changes
===================================================================
--- Catalyst-Runtime/5.80/trunk/Changes 2009-06-25 09:45:03 UTC (rev 10660)
+++ Catalyst-Runtime/5.80/trunk/Changes 2009-06-25 09:49:35 UTC (rev 10661)
@@ -11,6 +11,12 @@
ensuring child classes don't inherit their parent's config,
except works correctly with closures.
+ New features:
+ - Use ~ as prefix for plugins or action classes which are located in
+ MyApp::Plugin / MyApp::Action (mo)
+ - Controller methods without attributes are now considered actions if
+ they are specified in config->{action(s)} (mo)
+
5.80005 2009-06-06 14:40:00
Behaviour changes:
Modified: Catalyst-Runtime/5.80/trunk/Makefile.PL
===================================================================
--- Catalyst-Runtime/5.80/trunk/Makefile.PL 2009-06-25 09:45:03 UTC (rev 10660)
+++ Catalyst-Runtime/5.80/trunk/Makefile.PL 2009-06-25 09:49:35 UTC (rev 10661)
@@ -34,6 +34,7 @@
requires 'URI' => '1.35';
requires 'Text::Balanced'; # core in 5.8.x but mentioned for completeness
requires 'MRO::Compat';
+requires 'String::RewritePrefix' => '0.004'; # Catalyst::Utils::resolve_namespace
recommends 'B::Hooks::OP::Check::StashChange';
Modified: Catalyst-Runtime/5.80/trunk/TODO
===================================================================
--- Catalyst-Runtime/5.80/trunk/TODO 2009-06-25 09:45:03 UTC (rev 10660)
+++ Catalyst-Runtime/5.80/trunk/TODO 2009-06-25 09:49:35 UTC (rev 10661)
@@ -22,4 +22,15 @@
See also: Catalyst::Plugin::Log::Dispatch and
http://github.com/willert/catalyst-plugin-log4perl-simple/tree
+TODO for brach namespace_handling_refactor:
+- refactor code in
+ * Catalyst::Dispatcher::get_containers # No Idea
+ * Catalyst::Dispatcher::dispatch_type # DONE
+
+ * Catalyst::Controller::_parse_ActionClass_attr # DONE
+ * Catalyst::Dispatcher::_load_dispatch_types # DONE
+ * Catalyst::setup_plugins # DONE
+ to use the same namespacing method
+
+- Ok, so can you add tests for ->config(actions => { foo => { ActionClass => '+Bar' }});
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Controller.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Controller.pm 2009-06-25 09:45:03 UTC (rev 10660)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Controller.pm 2009-06-25 09:49:35 UTC (rev 10661)
@@ -178,13 +178,28 @@
sub get_action_methods {
my $self = shift;
my $meta = find_meta($self);
- confess("Metaclass for " . ref($meta) ." for " . $meta->name
- . " cannot support register_actions.")
- unless $meta->can('get_nearest_methods_with_attributes');
+ confess("Metaclass for "
+ . ref($meta) . " for "
+ . $meta->name
+ . " cannot support register_actions." )
+ unless $meta->can('get_nearest_methods_with_attributes');
my @methods = $meta->get_nearest_methods_with_attributes;
+
+ # actions specified via config are also action_methods
+ push(
+ @methods,
+ map {
+ $meta->get_method($_)
+ || confess( 'Action "'
+ . $_
+ . '" is not available from controller '
+ . ( ref $self ) )
+ } keys %{ $self->_controller_actions }
+ ) if ( ref $self );
return @methods;
}
+
sub register_actions {
my ( $self, $c ) = @_;
$self->register_action_methods( $c, $self->get_action_methods );
@@ -199,7 +214,6 @@
foreach my $method (@methods) {
my $name = $method->name;
my $attributes = $method->attributes;
- next unless $attributes;
my $attrs = $self->_parse_attrs( $c, $name, @{ $attributes } );
if ( $attrs->{Private} && ( keys %$attrs > 1 ) ) {
$c->log->debug( 'Bad action definition "'
@@ -376,9 +390,8 @@
sub _parse_ActionClass_attr {
my ( $self, $c, $name, $value ) = @_;
- unless ( $value =~ s/^\+// ) {
- $value = join('::', $self->_action_class, $value );
- }
+ my $appname = $self->_application;
+ $value = Catalyst::Utils::resolve_namespace($appname . '::Action', $self->_action_class, $value);
return ( 'ActionClass', $value );
}
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Dispatcher.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Dispatcher.pm 2009-06-25 09:45:03 UTC (rev 10660)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Dispatcher.pm 2009-06-25 09:49:35 UTC (rev 10661)
@@ -654,12 +654,11 @@
my ( $self, @types ) = @_;
my @loaded;
-
# Preload action types
for my $type (@types) {
- my $class =
- ( $type =~ /^\+(.*)$/ ) ? $1 : "Catalyst::DispatchType::${type}";
-
+ # first param is undef because we cannot get the appclass
+ my $class = Catalyst::Utils::resolve_namespace(undef, 'Catalyst::DispatchType', $type);
+
eval { Class::MOP::load_class($class) };
Catalyst::Exception->throw( message => qq/Couldn't load "$class"/ )
if $@;
@@ -681,11 +680,10 @@
sub dispatch_type {
my ($self, $name) = @_;
+
+ # first param is undef because we cannot get the appclass
+ $name = Catalyst::Utils::resolve_namespace(undef, 'Catalyst::DispatchType', $name);
- unless ($name =~ s/^\+//) {
- $name = "Catalyst::DispatchType::" . $name;
- }
-
for (@{ $self->_dispatch_types }) {
return $_ if ref($_) eq $name;
}
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Utils.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Utils.pm 2009-06-25 09:45:03 UTC (rev 10660)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Utils.pm 2009-06-25 09:49:35 UTC (rev 10661)
@@ -9,6 +9,8 @@
use Carp qw/croak/;
use Cwd;
+use String::RewritePrefix;
+
use namespace::clean;
=head1 NAME
@@ -377,6 +379,28 @@
return $_term_width = $width;
}
+
+=head2 resolve_namespace
+
+Method which adds the namespace for plugins and actions.
+
+ __PACKAGE__->setup(qw(MyPlugin));
+
+ # will load Catalyst::Plugin::MyPlugin
+
+=cut
+
+
+sub resolve_namespace {
+ my $appnamespace = shift;
+ my $namespace = shift;
+ my @classes = @_;
+ return String::RewritePrefix->rewrite(
+ { '' => $namespace.'::', '+' => '', '~' => $appnamespace . '::' }, @classes,
+ );
+}
+
+
=head1 AUTHORS
Catalyst Contributors, see Catalyst.pm
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm 2009-06-25 09:45:03 UTC (rev 10660)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm 2009-06-25 09:49:35 UTC (rev 10661)
@@ -2509,9 +2509,9 @@
$class->_plugins( {} ) unless $class->_plugins;
$plugins ||= [];
+
+ my @plugins = Catalyst::Utils::resolve_namespace($class . '::Plugin', 'Catalyst::Plugin', @$plugins);
- my @plugins = map { s/\A\+// ? $_ : "Catalyst::Plugin::$_" } @$plugins;
-
for my $plugin ( reverse @plugins ) {
Class::MOP::load_class($plugin);
my $meta = find_meta($plugin);
Modified: Catalyst-Runtime/5.80/trunk/t/aggregate/live_component_controller_action_action.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/aggregate/live_component_controller_action_action.t 2009-06-25 09:45:03 UTC (rev 10660)
+++ Catalyst-Runtime/5.80/trunk/t/aggregate/live_component_controller_action_action.t 2009-06-25 09:49:35 UTC (rev 10661)
@@ -10,7 +10,7 @@
BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
-use Test::More tests => 28 * $iters;
+use Test::More tests => 42 * $iters;
use Catalyst::Test 'TestApp';
if ( $ENV{CAT_BENCHMARK} ) {
@@ -106,5 +106,46 @@
'Content is a serialized Catalyst::Request'
);
}
+
+ {
+ ok( my $response = request('http://localhost/action_action_five'),
+ 'Request' );
+ ok( $response->is_success, 'Response Successful 2xx' );
+ is( $response->content_type, 'text/plain', 'Response Content-Type' );
+ is( $response->header('X-Catalyst-Action'),
+ 'action_action_five', 'Test Action' );
+ is(
+ $response->header('X-Test-Class'),
+ 'TestApp::Controller::Action::Action',
+ 'Test Class'
+ );
+ is( $response->header('X-Action'), 'works' );
+ like(
+ $response->content,
+ qr/^bless\( .* 'Catalyst::Request' \)$/s,
+ 'Content is a serialized Catalyst::Request'
+ );
+ }
+
+ {
+ ok( my $response = request('http://localhost/action_action_six'),
+ 'Request' );
+ ok( $response->is_success, 'Response Successful 2xx' );
+ is( $response->content_type, 'text/plain', 'Response Content-Type' );
+ is( $response->header('X-Catalyst-Action'),
+ 'action_action_six', 'Test Action' );
+ is(
+ $response->header('X-Test-Class'),
+ 'TestApp::Controller::Action::Action',
+ 'Test Class'
+ );
+ is( $response->header('X-TestAppActionTestMyAction'), 'MyAction works' );
+ like(
+ $response->content,
+ qr/^bless\( .* 'Catalyst::Request' \)$/s,
+ 'Content is a serialized Catalyst::Request'
+ );
+ }
+
}
Modified: Catalyst-Runtime/5.80/trunk/t/aggregate/live_component_controller_action_path.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/aggregate/live_component_controller_action_path.t 2009-06-25 09:45:03 UTC (rev 10660)
+++ Catalyst-Runtime/5.80/trunk/t/aggregate/live_component_controller_action_path.t 2009-06-25 09:49:35 UTC (rev 10661)
@@ -10,7 +10,7 @@
BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
-use Test::More tests => 36*$iters;
+use Test::More tests => 42*$iters;
use Catalyst::Test 'TestApp';
if ( $ENV{CAT_BENCHMARK} ) {
@@ -142,4 +142,22 @@
'Content is a serialized Catalyst::Request'
);
}
+
+ {
+ ok( my $response = request('http://localhost/action/path/six'), 'Request' );
+ ok( $response->is_success, 'Response Successful 2xx' );
+ is( $response->content_type, 'text/plain', 'Response Content-Type' );
+ is( $response->header('X-Catalyst-Action'),
+ 'action/path/six', 'Test Action' );
+ is(
+ $response->header('X-Test-Class'),
+ 'TestApp::Controller::Action::Path',
+ 'Test Class'
+ );
+ like(
+ $response->content,
+ qr/^bless\( .* 'Catalyst::Request' \)$/s,
+ 'Content is a serialized Catalyst::Request'
+ );
+ }
}
Modified: Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Action/Action.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Action/Action.pm 2009-06-25 09:45:03 UTC (rev 10660)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Action/Action.pm 2009-06-25 09:49:35 UTC (rev 10661)
@@ -3,6 +3,8 @@
use strict;
use base 'TestApp::Controller::Action';
+__PACKAGE__->config( actions => { action_action_five => { ActionClass => '+Catalyst::Action::TestBefore' } } );
+
sub action_action_one : Global : ActionClass('TestBefore') {
my ( $self, $c ) = @_;
$c->res->header( 'X-Action', $c->stash->{test} );
@@ -25,4 +27,15 @@
$c->forward('TestApp::View::Dump::Request');
}
+sub action_action_five : Global {
+ my ( $self, $c ) = @_;
+ $c->res->header( 'X-Action', $c->stash->{test} );
+ $c->forward('TestApp::View::Dump::Request');
+}
+
+sub action_action_six : Global : ActionClass('~TestMyAction') {
+ my ( $self, $c ) = @_;
+ $c->forward('TestApp::View::Dump::Request');
+}
+
1;
Modified: Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Action/Path.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Action/Path.pm 2009-06-25 09:45:03 UTC (rev 10660)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Action/Path.pm 2009-06-25 09:49:35 UTC (rev 10661)
@@ -7,6 +7,7 @@
actions => {
'one' => { 'Path' => [ 'a path with spaces' ] },
'two' => { 'Path' => "åäö" },
+ 'six' => { 'Local' => undef },
},
);
@@ -35,4 +36,9 @@
$c->forward('TestApp::View::Dump::Request');
}
+sub six {
+ my ( $self, $c ) = @_;
+ $c->forward('TestApp::View::Dump::Request');
+}
+
1;
More information about the Catalyst-commits
mailing list