The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
use strict;
use warnings;
use Test::More;
use Path::Dispatcher;

{
    package My::Rule::NamedEnum;
    use Any::Moose;
    extends 'Path::Dispatcher::Rule';

    has name => (
        is       => 'ro',
        isa      => 'Str',
        required => 1,
    );

    has regex => (
        is       => 'ro',
        isa      => 'RegexpRef',
        required => 1,
    );

    sub _match {
        my $self = shift;
        my $path = shift;

        return unless $path =~ $self->regex;

        return {
            named_captures => {
                $self->name => $&,
            },
        };
    }
}

my $dispatcher = Path::Dispatcher->new(
    rules => [
        My::Rule::NamedEnum->new(
            name  => 'hoo-ah',
            regex => qr/^\w+::/,
            block => sub { shift },
        )
    ],
);

my $match = $dispatcher->run("Foo::Bar");
is_deeply($match->positional_captures, []);
is_deeply($match->named_captures, { "hoo-ah" => "Foo::" });

done_testing;