Last active
November 5, 2015 10:29
-
-
Save leejo/0b4b728b0319bfa01665 to your computer and use it in GitHub Desktop.
routes using a root
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
#!/usr/bin/env perl | |
# in reality this would be in a separate file | |
package ExampleApp; | |
# automatically enables "strict", "warnings", "utf8" and perl 5.10 features | |
use Mojo::Base qw( Mojolicious ); | |
sub startup { | |
my ( $self ) = @_; | |
my $r = $self->routes; | |
my $root = $r->get( '/foo/bar/baz' ); | |
$root->under( 'cb' => sub { | |
my $self = shift; | |
# do some checking here | |
} ); | |
my $boz = $root->get( '/boz' ); # /foo/bar/baz/boz | |
$boz->to( 'ExampleController#example_form' ); | |
my $baz = $root->get( '/baz' ); # /foo/bar/baz/baz | |
$baz->to( 'ExampleController#example_form' ); | |
} | |
# in reality this would be in a separate file | |
package ExampleApp::ExampleController; | |
use Mojo::Base 'Mojolicious::Controller'; | |
sub example_form { | |
my ( $self ) = @_; | |
$self->render( text => 'boo' ); | |
} | |
# in reality this would be in a separate file | |
package main; | |
use strict; | |
use warnings; | |
use Mojolicious::Commands; | |
Mojolicious::Commands->start_app( 'ExampleApp' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment