Hello, as in subject I would like to quickly (without many changes in
existing code) switch from old script written in CGI to Mojolicious.
CGI script uses CGI::Simple || CGI::Fast module and perform almost all
actions based on "param" value (my $action = param('do');) Below, fragment
of this script:
### OLD Script ###
my $do = $c->param('do'); #read /?do=action
my $action={
home => \&Home,
login => \&LoginPage,
news => \&News,
#...
}->{ $do };
&$action if $action;
As bad as it looks I would like to keep this schema. Yes I do know that
with mojolicious it may be done much better, but as for now I would like to
adjust mojolicious to this code. Here the problems start to happen. I try
to establish one route which selects all incoming HTTP request and then
base on param('do); (like in CGI script) call apropriate function which
generate apropriate webpage. Below example code.
### Mojolicious Script ###
package MyApp;
use Mojo::Base 'Mojolicious';
sub startup {
my $self = shift;
# Router
my $r = $self->routes;
# Route
$r->route('/')->to(controller => 'Foo', action => 'welcome');
}
# Controller #
package MyApp::Foo;
use Mojo::Base 'Mojolicious::Controller';
my $sub={
home => \&home,
login => \&LoginPage,
news => \&News,
faq => \&Faq,
#...
};
# Action
sub welcome {
my $self = shift;
my $action = $self->param('do');
$sub->{$action};
return $action;
}
sub home {
my $self = shift;
$self->PrintTemplate('home');
}
sub PrintTemplate {
my $self = $_[0];
my $page = $_[1];
$self->render(text => "This is ($page) webpage ;)");
}
1;
###
Morbo returns:
Inactivity timeout.
GET "/".
Routing to controller "MyApp::Foo" and action
Template "foo/welcome.html.ep" not found.
Nothing has been rendered, expecting delayed
Inactivity timeout.
So, it is looking for rendering from "welcome" subroutine. How to make it
work "my way" even if it is probaly worst then "get '/action' " for every
webpage. How to make it work ?
PS:I don't want any dependencies from CPAN.
Regards.
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.