remove use of 'use base'
[catagits/Web-Simple.git] / lib / Web / Dispatch / Node.pm
CommitLineData
4ed4fb42 1package Web::Dispatch::Node;
2
3use Moo;
4
5with 'Web::Dispatch::ToApp';
6
7for (qw(match run)) {
8 has "_${_}" => (is => 'ro', required => 1, init_arg => $_);
9}
10
11sub call {
12 my ($self, $env) = @_;
13 if (my ($env_delta, @match) = $self->_match->($env)) {
1f4dd6f9 14 ($env_delta, $self->_curry(@match));
4ed4fb42 15 } else {
16 ()
17 }
18}
19
20sub _curry {
21 my ($self, @args) = @_;
22 my $run = $self->_run;
1f8cad5e 23 my $code = sub { $run->(@args, $_[0]) };
24 # if the first argument is a hashref, localize %_ to it to permit
25 # use of $_{name} inside the dispatch sub
26 ref($args[0]) eq 'HASH'
27 ? do { my $v = $args[0]; sub { local *_ = $v; &$code } }
28 : $code
4ed4fb42 29}
30
311;