Created
September 16, 2013 14:24
-
-
Save themage/6581369 to your computer and use it in GitHub Desktop.
a simple version of the crazy stuff I was trying to do with Mojolicious::Routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
====> ./MojoTest.pm | |
package MojoTest; | |
use Mojo::Base qw(Mojolicious); | |
sub startup { | |
my $self = shift; | |
$self->plugins->register_plugin('MojoTest::Plugin', $self); | |
my $rb = $self->routes->route('/')->over('true'); | |
$rb->route('/test')->to(cb => sub { | |
my $c = shift; | |
$c->render(text => 'Some test'); | |
}); | |
$rb->to(cb => sub { | |
my $c = shift; | |
$c->render(text => 'root path'); | |
}); | |
} | |
1; | |
====> ./MojoTest/Plugin.pm | |
package MojoTest::Plugin; | |
use Mojo::Base qw(Mojolicious::Plugin); | |
sub register { | |
my ($self, $app) = @_; | |
$app->routes->add_condition( true => sub { return 1; } ); | |
my $tr = $app->routes->route('/')->over('true'); | |
$tr->route('/plugged/')->to(cb => sub { | |
my $c = shift; | |
$c->render(text => 'You are now plugged'); | |
}); | |
} | |
1; | |
====> ./test.pl | |
#!/usr/bin/perl -w | |
use strict; | |
use warnings; | |
use MojoTest; | |
MojoTest->new->start; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment