my ($self, $c, $path) = @_;
return if $path =~ m!/!; # Not at root yet, wait for it ...
my $result = @{$c->get_action('default', $c->req->path, 1) || []}[-1];
+ # Find default on namespace or super
if ($result) {
$c->action( $result->[0] );
$c->namespace( $c->req->path );
$c->req->action('default');
$c->req->match('');
+ return 1;
}
+ return 0;
}
1;
sub register_action {
my ( $self, $c, $action ) = @_;
+
my $attrs = $action->attributes;
my @register;
+
foreach my $r (@{$attrs->{Path} || []}) {
- unless ($r =~ m!^/!) {
+ unless ($r =~ m!^/!) { # It's a relative path
$r = $action->prefix."/$r";
}
push(@register, $r);
}
if ($attrs->{Global} || $attrs->{Absolute}) {
- push(@register, $action->name);
+ push(@register, $action->name); # Register sub name against root
}
if ($attrs->{Local} || $attrs->{Relative}) {
push(@register, join('/', $action->prefix, $action->name));
+ # Register sub name as a relative path
}
foreach my $r (@register) {
my ($self, $c, $path) = @_;
return if $self->SUPER::prepare_action($c, $path);
+ # Check path against plain text first
foreach my $compiled (@{$self->{compiled}||[]}) {
if ( my @snippets = ( $path =~ $compiled->{re} ) ) {
my $attrs = $action->attributes;
my @register = map { @{$_ || []} } @{$attrs}{'Regex', 'Regexp'};
foreach my $r (@register) {
- $self->{paths}{$r} = $action;
- push(@{$self->{compiled}},
+ $self->{paths}{$r} = $action; # Register path for superclass
+ push(@{$self->{compiled}}, # and compiled regex for us
{
re => qr#$r#,
action => $action,
DESCEND: while (@path) {
$path = join '/', @path;
+ # Check out dispatch types to see if any will handle the path at
+ # this level
+
foreach my $type (@{$self->dispatch_types}) {
last DESCEND if $type->prepare_action($c, $path);
}
+ # If not, move the last part path to args
+
unshift @args, pop @path;
}
my %attributes;
for my $attr ( @{$attrs} ) {
+
+ # Parse out :Foo(bar) into Foo => bar etc (and arrayify)
+
if ( my ($key, $value) = ($attr =~ /^(.*?)(?:\(\s*(.+)\s*\))?$/) ) {
if ( defined $value ) {
($value =~ s/^'(.*)'$/$1/) || ($value =~ s/^"(.*)"/$1/);
# Set the method value
$parent->getNodeValue->actions->{$method} = $action;
+ # Pass the action to our dispatch types so they can register it if reqd.
foreach my $type ( @{ $self->dispatch_types } ) {
$type->register_action($c, $action);
}