concrete
This commit is contained in:
31
lib/CW/Router.pm
Normal file
31
lib/CW/Router.pm
Normal 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;
|
||||
Reference in New Issue
Block a user