Files
compiled.world/lib/CW/Router.pm
2026-08-11 23:10:22 -06:00

32 lines
639 B
Perl

package CW::Router;
use Moo;
use Router::Simple;
use Carp ();
use CW::Route;
has _router => (
is => 'ro',
default => sub { Router::Simple->new },
handles => [qw(match)]
);
{
## no critic [TestingAndDebugging::ProhibitNoStrict]
no strict 'refs';
for (qw(get post put patch delete)) {
*{ __PACKAGE__ . '::' . $_ } = sub {
my ( $self, $path ) = @_;
Carp::croak("Invalid path for route!") unless $path;
my $route = CW::Route->new( path => $path );
$self->_router->connect( $path, { route => $route } );
return $route;
}
}
}
1;