Search code examples
perlroutesmojoliciouscamelcasing

Mojolicious Routing and CamelCase


I have a my mojolicious routes set up like this:

my $r = $self->routes;
my $users = $r->route('/users')->to(controller => 'controller-users');

$users->get('/select')->to(                 action => 'select' );
$users->get('/list')->to(                   action => 'list' );

Where my user controller is defined in Users.pm, called Project::Controller::Users. This all works fine and without any problems. However, I also have some controllers like UserGroups. These are defined in the same way, Project::Controller::UserGroups.

However, the line

my $users = $r->route('/users')->to(controller => 'controller-usergroups');

doesn't work for that. It keeps trying to find the controller Project::Controller::Usergroups, which doesn't exist. What's the correct syntax for camelcase for the "to"-method of Mojolicious' router?


Solution

  • Did you try:

    my $users = $r->route('/users')->to(controller => 'controller-userGroups');
    

    EDIT:

    Can you try it like this:

    my $users = $r->route('/users')->to(namespace=> 'Project::Controller::UserGroups', action => 'users');
    

    Based on this: http://mojolicio.us/perldoc/Mojolicious/Guides/Routing#Route_to_class