From: Florian Ragwitz Date: Thu, 19 Feb 2009 05:21:45 +0000 (+0000) Subject: First steps towards throwing out attributes. X-Git-Tag: 5.80001~40^2~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=ba545c131c0ce1eb452906b595b95c46c657b555 First steps towards throwing out attributes. --- diff --git a/lib/Catalyst/AttrContainer.pm b/lib/Catalyst/AttrContainer.pm deleted file mode 100644 index 443b416..0000000 --- a/lib/Catalyst/AttrContainer.pm +++ /dev/null @@ -1,60 +0,0 @@ -package Catalyst::AttrContainer; - -use Moose; -use Catalyst::Exception; -with 'Catalyst::ClassData'; - -no Moose; - -__PACKAGE__->mk_classdata(_attr_cache => {} ); -__PACKAGE__->mk_classdata( _action_cache => [] ); - -# note - see attributes(3pm) -sub MODIFY_CODE_ATTRIBUTES { - my ( $class, $code, @attrs ) = @_; - $class->_attr_cache( { %{ $class->_attr_cache }, $code => [@attrs] } ); - $class->_action_cache( - [ @{ $class->_action_cache }, [ $code, [@attrs] ] ] ); - return (); -} - -sub FETCH_CODE_ATTRIBUTES { $_[0]->_attr_cache->{ $_[1] } || () } - -=head1 NAME - -Catalyst::AttrContainer - Handles code attribute storage and caching - -=head1 SYNOPSIS - -=head1 DESCRIPTION - -This class sets up the code attribute cache. It's a base class for -L. - -=head1 METHODS - -=head2 FETCH_CODE_ATTRIBUTES - -Attribute function. See attributes(3pm) - -=head2 MODIFY_CODE_ATTRIBUTES - -Attribute function. See attributes(3pm) - -=head1 SEE ALSO - -L -L. - -=head1 AUTHORS - -Catalyst Contributors, see Catalyst.pm - -=head1 COPYRIGHT - -This program is free software, you can redistribute it and/or modify it under -the same terms as Perl itself. - -=cut - -1; diff --git a/lib/Catalyst/Controller.pm b/lib/Catalyst/Controller.pm index 18c8259..7217551 100644 --- a/lib/Catalyst/Controller.pm +++ b/lib/Catalyst/Controller.pm @@ -1,12 +1,11 @@ package Catalyst::Controller; use Moose; -use Moose::Util qw/find_meta/; +use Moose::Util qw/find_meta does_role/; use namespace::clean -except => 'meta'; -# Note - Must be done at compile time due to attributes (::AttrContainer) -BEGIN { extends qw/Catalyst::Component Catalyst::AttrContainer/; } +BEGIN { extends qw/Catalyst::Component MooseX::MethodAttributes::Inheritable/; } use Catalyst::Exception; use Catalyst::Utils; @@ -182,34 +181,25 @@ sub register_actions { #this is still not correct for some reason. my $namespace = $self->action_namespace($c); my $meta = find_meta($self); - my %methods = map { $_->body => $_->name } + my @methods = grep { does_role($_, 'MooseX::MethodAttributes::Role::Meta::Method') } $meta->get_all_methods; - # Advanced inheritance support for plugins and the like - #moose todo: migrate to eliminate CDI compat - my @action_cache; - for my $isa ( $meta->superclasses, $class ) { - if(my $coderef = $isa->can('_action_cache')){ - push(@action_cache, @{ $isa->$coderef }); - } - } - - foreach my $cache (@action_cache) { - my $code = $cache->[0]; - my $method = delete $methods{$code}; # avoid dupe registers - next unless $method; - my $attrs = $self->_parse_attrs( $c, $method, @{ $cache->[1] } ); + 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 "' - . join( ' ', @{ $cache->[1] } ) - . qq/" for "$class->$method"/ ) + . join( ' ', @{ $attributes } ) + . qq/" for "$class->$name"/ ) if $c->debug; next; } my $reverse = $namespace ? "${namespace}/${method}" : $method; my $action = $self->create_action( - name => $method, - code => $code, + name => $name, + code => $method->body, reverse => $reverse, namespace => $namespace, class => $class,