Mailing List Archive

Proposed patch for ActionClass attribute
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@dynamicrange.com
Re: Proposed patch for ActionClass attribute [ In reply to ]
On 3 Apr 2009, at 19:19, Bruce McKenzie wrote:
>
> 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.
>

Hi bruce. Sorry for dropping this for a couple of weeks.

First of all - this sounds like a great idea, but I don't like your
implementation. As a note, unified diffs are preferred generally.

You should be looking to patch:

http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Runtime/5.80/trunk/

However I have to say that the bit of code you're thinking about
patching is something we're heavily prototyping at the moment... With
Catalyst 5.80 (to be released real soon now), applying roles to
action (and many other) classes is possible, and these also could
have nice namespace stuff doing to them.

Have a look at the cute namespace code in an (abandoned, do not try
to use) prototype:

http://github.com/rafl/catalyst-app-roleapplicator/blob/
64ffd5cc3ed3c3df990ad0e9b18aea413cccc617/lib/Catalyst/App/
RoleApplicator.pm

I like the prefix idea, and its not as ambiguous as 'load namespace
one, or namespace two'.

I'd guess the namespace stuff should be done in a generic way in
Catalyst::Utils, and then re-used for ActionClass/ActionRole and all
the other things like request class / request class roles, etc, etc etc.

Well volunteered.

Cheers
t0m

P.S. There is an actual working prototype of App::RoleApplicator, but
without any of the namespace stuff on CPAN.

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev