use Moose;
use Class::MOP;
+use Class::Load ':all';
use String::RewritePrefix;
use Moose::Util qw/find_meta/;
use List::Util qw/first/;
sub _build__action_roles {
my $self = shift;
my @roles = $self->_expand_role_shortname($self->_action_role_args);
- Class::MOP::load_class($_) for @roles;
+ load_class($_) for @roles;
return \@roles;
}
my $attributes = $method->can('attributes') ? $method->attributes : [];
my $attrs = $self->_parse_attrs( $c, $name, @{ $attributes } );
if ( $attrs->{Private} && ( keys %$attrs > 1 ) ) {
- $c->log->debug( 'Bad action definition "'
+ $c->log->warn( 'Bad action definition "'
. join( ' ', @{ $attributes } )
. qq/" for "$class->$name"/ )
if $c->debug;
sub _apply_action_class_roles {
my ($self, $class, @roles) = @_;
- Class::MOP::load_class($_) for @roles;
+ load_class($_) for @roles;
my $meta = Moose::Meta::Class->initialize($class)->create_anon_class(
superclasses => [$class],
roles => \@roles,
my %final_attributes;
- foreach my $key (keys %raw_attributes) {
+ while (my ($key, $value) = each %raw_attributes){
+ my $new_attrs = $self->_parse_attr($c, $name, $key => $value );
+ push @{ $final_attributes{$_} }, @{ $new_attrs->{$_} } for keys %$new_attrs;
+ }
- my $raw = $raw_attributes{$key};
+ return \%final_attributes;
+}
- foreach my $value (ref($raw) eq 'ARRAY' ? @$raw : $raw) {
+sub _parse_attr {
+ my ($self, $c, $name, $key, $values) = @_;
- my $meth = "_parse_${key}_attr";
- if ( my $code = $self->can($meth) ) {
- ( $key, $value ) = $self->$code( $c, $name, $value );
+ my %final_attributes;
+ foreach my $value (ref($values) eq 'ARRAY' ? @$values : $values) {
+ my $meth = "_parse_${key}_attr";
+ if ( my $code = $self->can($meth) ) {
+ my %new_attrs = $self->$code( $c, $name, $value );
+ while (my ($new_key, $value) = each %new_attrs){
+ my $new_attrs = $key eq $new_key ?
+ { $new_key => [$value] } :
+ $self->_parse_attr($c, $name, $new_key => $value );
+ push @{ $final_attributes{$_} }, @{ $new_attrs->{$_} } for keys %$new_attrs;
}
+ }
+ else {
push( @{ $final_attributes{$key} }, $value );
}
}
sub _parse_Global_attr {
my ( $self, $c, $name, $value ) = @_;
- return $self->_parse_Path_attr( $c, $name, "/$name" );
+ # _parse_attr will call _parse_Path_attr for us
+ return Path => "/$name";
}
sub _parse_Absolute_attr { shift->_parse_Global_attr(@_); }
sub _parse_Local_attr {
my ( $self, $c, $name, $value ) = @_;
- return $self->_parse_Path_attr( $c, $name, $name );
+ # _parse_attr will call _parse_Path_attr for us
+ return Path => $name;
}
sub _parse_Relative_attr { shift->_parse_Local_attr(@_); }
my ( $self, $c, $name, $value ) = @_;
my $appclass = Catalyst::Utils::class2appclass($self);
- $value = "${appclass}::Action::${value}";
+ $value = "+${appclass}::Action::${value}";
return ( 'ActionClass', $value );
}
return Does => $self->_expand_role_shortname($value);
}
+sub _parse_GET_attr { Method => 'GET' }
+sub _parse_POST_attr { Method => 'POST' }
+sub _parse_PUT_attr { Method => 'PUT' }
+sub _parse_DELETE_attr { Method => 'DELETE' }
+sub _parse_OPTION_attr { Method => 'OPTION' }
+sub _parse_HEAD_attr { Method => 'HEAD' }
+
sub _expand_role_shortname {
my ($self, @shortnames) = @_;
my $app = $self->_application;
return String::RewritePrefix->rewrite(
{ '' => sub {
- my $loaded = Class::MOP::load_first_existing_class(
+ my $loaded = load_first_existing_class(
map { "$_$_[0]" } @prefixes
);
return first { $loaded =~ /^$_/ }