Skip to content

Instantly share code, notes, and snippets.

@themage
Created September 16, 2013 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themage/6581369 to your computer and use it in GitHub Desktop.
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
====> ./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