Skip to content

Commit

Permalink
merge arguments in subroutes
Browse files Browse the repository at this point in the history
  • Loading branch information
vti committed Dec 26, 2016
1 parent 97f385c commit da221f5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/Routes/Tiny/Pattern.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,23 @@ sub match {
}
}

my $arguments = {
%{ $args{arguments} || {} },
%{ $self->arguments || {} }
};

my $match = $self->_build_match(
name => $self->name,
arguments => $self->arguments,
arguments => $arguments,
captures => $captures,
parent => $args{parent}
);

if ($self->{subroutes}) {
my $parent = $match;
my $tail = substr($path, length $&);
$match = $self->{subroutes}->match($tail, %args, parent => $parent);
$match = $self->{subroutes}
->match($tail, %args, parent => $parent, arguments => $arguments);
}

return $match;
Expand Down
21 changes: 21 additions & 0 deletions t/subroutes.t
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,25 @@ subtest 'cascading captures' => sub {
};
};

subtest 'merges arguments' => sub {
my $last = Routes::Tiny->new;
$last->add_route('/last/:id/', arguments => {foo => 'bar3', bar => 'baz'});

my $second = Routes::Tiny->new;
$second->mount('/second/:parent_id/', $last, arguments => {second => 'argument', foo => 'bar2'});

my $top = Routes::Tiny->new;
$top->mount('/top/:topic', $second, arguments => {top => 'argument', foo => 'bar'});

my $match = $top->match('/top/rainbows/second/5/last/7/');

is_deeply $match->arguments,
{
top => 'argument',
second => 'argument',
foo => 'bar3',
bar => 'baz',
};
};

done_testing;

0 comments on commit da221f5

Please sign in to comment.