X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FDispatchType%2FChained.pm;h=1d7783b499cb33c66b72cd8fb414bb854e60dd91;hp=132d9efb443f2465604b77a78b79e24106dd049d;hb=8a6a6581d48a3c1c4d5f631cdb7cbda336c0e5e2;hpb=5882c86e1f256e122583dcc311b17bdbf9a4d766 diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index 132d9ef..1d7783b 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -45,7 +45,7 @@ sub list { my $parent = "DUMMY"; my $curr = $endpoint; while ($curr) { - if (my $cap = $curr->attributes->{Captures}) { + if (my $cap = $curr->attributes->{CaptureArgs}) { unshift(@parts, (("*") x $cap->[0])); } if (my $pp = $curr->attributes->{PartPath}) { @@ -60,7 +60,7 @@ sub list { my @rows; foreach my $p (@parents) { my $name = "/${p}"; - if (my $cap = $p->attributes->{Captures}) { + if (my $cap = $p->attributes->{CaptureArgs}) { $name .= ' ('.$cap->[0].')'; } unless ($p eq $parents[0]) { @@ -115,8 +115,9 @@ sub recurse_match { my $children = $self->{children_of}{$parent}; return () unless $children; my @captures; - TRY: foreach my $try_part (sort { length($a) <=> length($b) } + TRY: foreach my $try_part (sort { length($b) <=> length($a) } keys %$children) { + # $b then $a to try longest part first my @parts = @$path_parts; if (length $try_part) { # test and strip PathPart next TRY unless @@ -127,11 +128,11 @@ sub recurse_match { } my @try_actions = @{$children->{$try_part}}; TRY_ACTION: foreach my $action (@try_actions) { - if (my $capture_attr = $action->attributes->{Captures}) { + if (my $capture_attr = $action->attributes->{CaptureArgs}) { my @captures; my @parts = @parts; # localise - # strip Captures into list + # strip CaptureArgs into list push(@captures, splice(@parts, 0, $capture_attr->[0])); # try the remaining parts against children of this action @@ -163,24 +164,26 @@ Matt is an idiot and hasn't documented this yet. sub register { my ( $self, $c, $action ) = @_; - my @child_of_attr = @{ $action->attributes->{Chained} || [] }; + my @chained_attr = @{ $action->attributes->{Chained} || [] }; - return 0 unless @child_of_attr; + return 0 unless @chained_attr; - if (@child_of_attr > 2) { + if (@chained_attr > 2) { Catalyst::Exception->throw( "Multiple Chained attributes not supported registering ${action}" ); } - my $parent = $child_of_attr[0]; + my $parent = $chained_attr[0]; if (defined($parent) && length($parent)) { - unless ($parent =~ m/^\//) { + if ($parent eq '.') { + $parent = '/'.$action->namespace; + } elsif ($parent !~ m/^\//) { $parent = '/'.join('/', $action->namespace, $parent); } } else { - $parent = '/'.$action->namespace; + $parent = '/' } $action->attributes->{Chained} = [ $parent ]; @@ -199,13 +202,19 @@ sub register { ); } + if ($part =~ m(^/)) { + Catalyst::Exception->throw( + "Absolute parameters to PathPart not allowed registering ${action}" + ); + } + $action->attributes->{PartPath} = [ $part ]; unshift(@{ $children->{$part} ||= [] }, $action); ($self->{actions} ||= {})->{'/'.$action->reverse} = $action; - unless ($action->attributes->{Captures}) { + unless ($action->attributes->{CaptureArgs}) { unshift(@{ $self->{endpoints} ||= [] }, $action); } @@ -229,7 +238,7 @@ sub uri_for_action { my $parent = "DUMMY"; my $curr = $action; while ($curr) { - if (my $cap = $curr->attributes->{Captures}) { + if (my $cap = $curr->attributes->{CaptureArgs}) { return undef unless @captures >= $cap->[0]; # not enough captures unshift(@parts, splice(@captures, -$cap->[0])); }