Changeset 22322

Show
Ignore:
Timestamp:
10/29/08 20:44:13 (6 years ago)
Author:
masaki
Message:

ActionClass? の弊害に対応して複数 Controller 併用可にしたつもり

Location:
lang/perl/Catalyst-Controller-Resources/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Catalyst-Controller-Resources/trunk/Makefile.PL

    r9671 r22322  
    55requires('Catalyst::Runtime' => 5.70); 
    66requires('Class::C3'); 
     7requires('List::Util'); 
    78 
    89feature 'Catalyst::Helper support', 
  • lang/perl/Catalyst-Controller-Resources/trunk/lib/Catalyst/Controller/Resource.pm

    r9909 r22322  
    88use Catalyst::Action; 
    99use Catalyst::ActionChain; 
     10use List::Util qw(first); 
    1011 
    1112our $VERSION = '0.03'; 
     
    110111    my $class = ref $self || $self; 
    111112 
     113    my @action_cache = @{ $class->_action_cache }; 
    112114    while (my ($action, $map) = each %$maps) { 
    113         my $subname = join '::' => $class, $action; 
     115        next unless my $code = $class->can($action); 
     116        $map = { method => uc $map } unless ref($map) eq 'HASH'; 
    114117 
    115         no strict 'refs'; 
    116         next unless defined &$subname; 
     118        my @attrs = $self->_construct_action_attributes($map_to, $map); 
     119        unshift @attrs => @{ attributes::get($code) || [] }; 
    117120 
    118         $map = { method => uc $map } unless ref($map) eq 'HASH'; 
    119         my @attrs = $self->_construct_action_attributes($map_to, $map); 
    120         attributes->import($class, \&$subname, @attrs); 
     121        # rewrite cache 
     122        if (my $cache = first { $code eq $_->[0] } @action_cache) { 
     123            $cache->[1] = [@attrs]; 
     124        } 
     125        else { 
     126            push @action_cache => [ $code => [@attrs] ]; 
     127        } 
     128        $class->_attr_cache->{$code} = [@attrs]; 
     129 
     130        attributes->import($class, $code, @attrs); 
    121131    } 
     132 
     133    # set action_cache 
     134    $class->_action_cache(\@action_cache); 
    122135} 
    123136