This commit is contained in:
2026-08-11 23:10:22 -06:00
commit 6fec70c7c8
13 changed files with 334 additions and 0 deletions

31
lib/CW/Router.pm Normal file
View File

@@ -0,0 +1,31 @@
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;