[dancer-users] Retrieving the current prefix?

Andrew Beverley andy at andybev.com
Thu Jan 21 17:45:00 EST 2021


On Thu, 21 Jan 2021 17:12:23 +0000 REMORSE at mgh.harvard.edu wrote:
> Hi! I'm starting to learn Dancer2. One question I have is whether it
> is possible to retrieve the current prefix in some way?

I'm not sure whether this is the correct answer, but can you simply use
a variable? E.g.

my $PREFIX = '/foo';

>     prefix '/foo';

Becomes "prefix $PREFIX"

>     get '/' => sub { forward '/foo'; };

Becomes "forward $PREFIX"

And so on.

Personally I do:

  prefix '/:name'

And then:

  my $prefix = route_parameters->get('name')

But that assumes you want to match multiple prefixes.

Andy


More information about the dancer-users mailing list