This file documents the revision history for Perl extension Catalyst.
+ - added ability to set action attributes from controller config
- added merge_config_hashes() as a convenience method
- Swapped out CGI::Cookie in favour of CGI::Simple::Cookie
- Removed test dependencies on Test::NoWarnings, Test::MockObject
sub action_namespace {
my ( $self, $c ) = @_;
- my $hash = (ref $self ? $self : $self->config);
+ my $hash = (ref $self ? $self : $self->config); # hate app-is-class
return $hash->{namespace} if exists $hash->{namespace};
return Catalyst::Utils::class2prefix( ref($self) || $self,
$c->config->{case_sensitive} )
}
}
+ my $hash = (ref $self ? $self : $self->config); # hate app-is-class
+
+ if (exists $hash->{actions} || exists $hash->{action}) {
+ my $a = $hash->{actions} || $hash->{action};
+ %raw_attributes = ((exists $a->{'*'} ? %{$a->{'*'}} : ()),
+ %raw_attributes,
+ (exists $a->{$name} ? %{$a->{$name}} : ()));
+ }
+
my %final_attributes;
foreach my $key (keys %raw_attributes) {
- foreach my $value (@{$raw_attributes{$key}}) {
+ my $raw = $raw_attributes{$key};
+
+ foreach my $value (ref($raw) ? @$raw : $raw) {
my $meth = "_parse_${key}_attr";
if ( $self->can($meth) ) {
package MyApp::Controller::Login;
- sub sign-in : Local { }
- sub new-password : Local { }
- sub sign-out : Local { }
+ use base qw/Catalyst::Controller/;
+
+ sub sign_in : Path("sign-in") { }
+ sub new_password : Path("new-password") { }
+ sub sign_out : Path("sign-out") { }
package MyApp::Controller::Catalog;
+ use base qw/Catalyst::Controller/;
+
sub view : Local { }
sub list : Local { }
package MyApp::Controller::Cart;
+ use base qw/Catalyst::Controller/;
+
sub add : Local { }
sub update : Local { }
sub order : Local { }
+Note that you can also supply attributes via the Controller's config so long
+as you have at least one attribute on a subref to be exported (:Action is
+commonly used for this) - for example the following is equivalent to the same
+controller above
+
+ package MyApp::Controller::Login;
+
+ use base qw/Catalyst::Controller/;
+
+ __PACKAGE__->config(
+ actions => {
+ 'sign_in' => { Path => 'sign-in' },
+ 'new_password' => { Path => 'new-password' },
+ 'sign_out' => { Path => 'sign-out' },
+ },
+ );
+
+ sub sign_in : Action { }
+ sub new_password : Action { }
+ sub sign_out : Action { }
+
=head3 Testing
Catalyst has a built-in http server for testing! (Later, you can easily
use strict;
use base 'TestApp::Controller::Action';
-sub one : Action Path("a path with spaces") {
+__PACKAGE__->config(
+ actions => {
+ 'one' => { 'Path' => [ 'a path with spaces' ] },
+ 'two' => { 'Path' => "åäö" },
+ },
+);
+
+sub one : Action Path("this_will_be_overriden") {
my ( $self, $c ) = @_;
$c->forward('TestApp::View::Dump::Request');
}
-sub two : Action Path("åäö") {
+sub two : Action {
my ( $self, $c ) = @_;
$c->forward('TestApp::View::Dump::Request');
}