[Catalyst-dev] Proposed patch for ActionClass attribute

Bruce McKenzie brucem at dynamicrange.com
Fri Apr 3 18:19:36 GMT 2009


I implemented application-specific an Application-specific action, and  
found the "MyAction" construct to be a little odd. So I took a run at  
extending the ActionClass parser to look for a local app version  
("MyApp::Action::Foo") first, then to fall back to the Catalyst  
version ("Catalyst::Action::Foo") if that's not present. You can still  
use "+My::Full::Path" to force a particular selection (such as to skip  
over an app version for some reason).

Is there a reason that this wasn't tried before?

I hope this helps. I'd appreciate feedback, and can provide the tests  
and doc if this is interesting enough to proceed. Catalyst is a neat  
system, and I appreciate the hard work of those who have made it what  
it is today.

Cheers,

Bruce

diff -rc /Library/Perl/5.8.8/Catalyst/Controller.pm Catalyst/ 
Controller.pm
*** /Library/Perl/5.8.8/Catalyst/Controller.pm	2009-04-02  
14:07:54.000000000 -0700
--- Catalyst/Controller.pm	2009-04-03 11:13:10.000000000 -0700
***************
*** 318,325 ****

   sub _parse_ActionClass_attr {
       my ( $self, $c, $name, $value ) = @_;
!     unless ( $value =~ s/^\+// ) {
!       $value = join('::', $self->_action_class, $value );
       }
       return ( 'ActionClass', $value );
   }
--- 318,344 ----

   sub _parse_ActionClass_attr {
       my ( $self, $c, $name, $value ) = @_;
!     if ( substr($value,0,1) eq '+' )
!     {
!         $value = substr($value,1);
!     }
!     else
!     {
!         eval {
!             # Check our app first...
!             my $appclass = Catalyst::Utils::class2appclass($self);
!
!             Catalyst::Utils::ensure_class_loaded( "$ 
{appclass}::Action::${value}" );
!             $value = "${appclass}::Action::${value}";
!             # $c->log->debug("Succeeded in loading $value");
!         };
!         if ( $@ )
!         {
!             # We take any error to mean "class doesn't exist", so  
fall back
!             # to one in the Catalyst hierarchy.
!             $value = join('::', $self->_action_class, $value );
!             # $c->log->debug("Failed app version, falling back to  
$value");
!         }
       }
       return ( 'ActionClass', $value );
   }

---
Bruce McKenzie
brucem at dynamicrange.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst-dev/attachments/20090403/bbf95da7/attachment.htm


More information about the Catalyst-dev mailing list