1611 shaares
17 private links
17 private links
1 result
tagged
placeholder
% mojo generate lite_app optional
...
% $EDITOR optional
One could mark the date as optional by giving it a default value of undef
:
#!/usr/bin/env perl
use Mojolicious::Lite -signatures;
get '/vote/:value/*when' => { when => undef } => sub ($c) {
my $value = $c->stash('value');
my $when = $c->stash('when');
$c->render(
format => 'txt',
text => $value . ' ' . ( defined $when ? $when : 'nope' ) . "\n"
);
};
app->start;
which then allows with-or-without the date queries:
% ./optional get /vote/42 2>/dev/null
42 nope
% ./optional get /vote/42/2020/01/07 2>/dev/null
42 2020/01/07
%