Stories
Slash Boxes
Comments

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jk2addict (4946)

jk2addict
  (email not shown publicly)
http://today.icantfocus.com/blog/
AOL IM: chrislaco (Add Buddy, Send Message)
Yahoo! ID: chrislaco@sbcglobal.net (Add User, Send Message)
Jabber: laco@scribblewerks.com

Journal of jk2addict (4946)

Friday January 11, 2008
03:49 PM

Catalyst Chained Hack

[ #35367 ]

With mst pointing in the correct direction [as usual], this is a little hack I have to make Chained('../method') possible.

This is mostly for cases where I want to have Controller::Foo::Child chained off of Controller::Foo, but I feel naughty about hardcoding Chained('/foo/method') in Foo::Child, esp if both of those classes are subclasses, so the name can follow long.

sub _parse_Chained_attr {
    my ($self, $c, $name, $value) = @_;
 
    if ($value && $value =~ /\.\.\//) {
        ## this is a friggin hack because I don't know how to have
        ## Path::Class eval ../ for me
        local $URI::ABS_REMOTE_LEADING_DOTS = 1;
        $value = URI->new(
            Path::Class::Dir->new($self->action_namespace, $value)->as_foreign('Unix')->stringify
        )->abs('http://localhost')->path;
    };
 
    return Chained => $value || $self->action_namespace;
};

That's ugly, but it works. Now, does anyone know how to make Path::Class evaluate ../ in paths? I resoted to that URI hack, but in the end, it did what I needed it to do.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • $value=dir($value)->absolute($self->action_namespace)
      ->as_foreign('Unix')->stringify

    If action_namespace doesn't start with '/':

    $value=dir($value)->absolute(dir('',$self->action_namespace))
      ->relative(dir(''))->as_foreign('Unix')->stringify