-
Notifications
You must be signed in to change notification settings - Fork 0
Faq for the impatient
Assuming $self
is an instance of Mojolicious::Controller (which is what your action instances are), here is how:
$self->app->static->root
perl startapp.pl daemon --listen=http://*:$port
I need to create a URL that has the same IP number as the incoming request but I need to change the port to 3001 instead of the port 3000 that the incoming request came on.
$self->req->url->clone->to_abs->port(3001);
<@sri> perldoc Mojo::URL
<@sri> the url you get is the absolute incoming url in its relative form with base part store in the base attribute
<@sri> so you have to clone it, make it absolute and then adjust it to your needs
<@sri> dump the url object after clone
<@sri> i think that will illustrate it best
Look here
I have a wildcard route like this: "/bo/(*folder)" => sub { ... }
and it seems to only trigger for /bo/morestuff instead of just /bo . How can I have it trigger forboth?
First, check all answers by running: ./myapp.pl routes
<@sri> anyway solution is
get '/bo/(*folder)' => {folder=> 'default-value-or-undef'} => sub {...}
This solution is best because:
- It allows you to specify a default value for the optional path if not provided instead of writing more code for this
- You dont write 2 routes each times you have a path with optional part.
get '/bo' => \&bo_action;
get '/bo/(*folder)' => \&bo_action;
(provided by MisterHatt and moritz) involve using regexes of Waypoints. Not for the impatient.
It certainly does in the most common M::Lite action: app->secret('signed-cookie-password')->start;
Starting a Mojolicious::Lite prototype from scratch and growing it into a well structured Mojolicious application is a simple process. A Lite app is a single file which will sprout in 3 ways. First an inflate command will extract the inline templates and layout and place them into templates and templates/layout directories. Next, the logic of the script file will go into the startup method of an Application class. Finally, a simple starter script will invoke your application class. An optional fourth step is to extend/replace the default Mojolicious controller. All of these steps are covered in L<WELL_STRUCTURED_APPLICATION>.
in other words - app-> in lite is the same thing as $self in sub startup {}
( https://github.com/kraih/mojo/wiki/Request-data ) my $param = $self->req->body_params->to_hash;
https://metacpan.org/module/Mojolicious::Guides::Rendering
app->start('cgi');
https://metacpan.org/module/Mojolicious::Lite#Stash-and-templates shows you how:
get '/bar' => sub {
my $self = shift;
$self->stash(one => 23);
$self->render('baz', two => 24);
};
__DATA__
@@ baz.html.ep
The magic numbers are <%= $one %> and <%= $two %>.