Catalyst Chained Hack

jk2addict on 2008-01-11T19:49:28

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.


without URI...

dakkar on 2008-01-11T22:02:53

$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

Re:without URI...

jk2addict on 2008-01-11T23:45:27

Negatory. That code for me yields dirs that stll have ../ in them.