mojolicious

Can I use Mojolicious to build a static site?

雨燕双飞 提交于 2020-01-13 18:01:59
问题 Is it possible to use the Mojolicious template system to build a static website? I'm trying to use a (skeleton) script like this: use Mojo::Template; use Mojolicious::Plugin::DefaultHelpers; use Mojolicious::Plugin::TagHelpers; my $mt = Mojo::Template->new; print $mt->render_file('index.html.ep'); Where index.html.ep is like this: % layout 'default'; This is a foo However I get an error nessage: String found where operator expected at index.html.ep line 1, near "layout 'default'" (Do you need

Can I use Mojolicious to build a static site?

邮差的信 提交于 2020-01-13 18:01:04
问题 Is it possible to use the Mojolicious template system to build a static website? I'm trying to use a (skeleton) script like this: use Mojo::Template; use Mojolicious::Plugin::DefaultHelpers; use Mojolicious::Plugin::TagHelpers; my $mt = Mojo::Template->new; print $mt->render_file('index.html.ep'); Where index.html.ep is like this: % layout 'default'; This is a foo However I get an error nessage: String found where operator expected at index.html.ep line 1, near "layout 'default'" (Do you need

How to get structure and inheritance history of a Perl object (not a class)?

北战南征 提交于 2020-01-05 05:53:09
问题 use Mojo::UserAgent; my $ua = Mojo::UserAgent->new; my $tx = $ua->get( shift ); How to get structure and inheritance history of these Perl objects ($ua and $tx)? Data::Dumper shows only small part of structure and inheritance history. 回答1: Perl doesn't keep track of historical values of variables. Perl doesn't keep track of historical inheritance relationships. Objects don't have inheritance relationships; classes do. The current structure of an object can be found using the following: use

Mojolicious basic login with

房东的猫 提交于 2020-01-04 07:47:09
问题 iam looking for authentification in Mojolicious. I have 2 pages momcorp1 and momcorp2, But i cant pas between over pages, someone know how do this. Iam reaading about "under", but i dont undertah how do this. The other form do this is use -Mojolicious::Plugin::Authentication - but is more dificult. This is the code, when 1 click link to momcorp 2, show error. #!/usr/bin/env perl use Mojolicious::Lite; helper auth => sub { my $self = shift; return 1 if $self->param('username') eq 'user1' and

Mojolicious basic login with

筅森魡賤 提交于 2020-01-04 07:47:06
问题 iam looking for authentification in Mojolicious. I have 2 pages momcorp1 and momcorp2, But i cant pas between over pages, someone know how do this. Iam reaading about "under", but i dont undertah how do this. The other form do this is use -Mojolicious::Plugin::Authentication - but is more dificult. This is the code, when 1 click link to momcorp 2, show error. #!/usr/bin/env perl use Mojolicious::Lite; helper auth => sub { my $self = shift; return 1 if $self->param('username') eq 'user1' and

Parsing HTML with Mojolicious User Agent

戏子无情 提交于 2020-01-02 08:26:52
问题 I have html something like this <h1>My heading</h1> <p class="class1"> <strong>SOMETHING</strong> INTERESTING (maybe not). </p> <div class="mydiv"> <p class="class2"> <a href="http://www.link.com">interesting link</a> </p> <h2>Some other heading</h2> The content between h1 and h2 varies - I know I can use css selectors in Mojo::Dom to, say, select the content of h1 or h2, or p tags - but how to select everything between h1 and h2? Or more generally, everything between any two given sets of

how to pass arguments from an plack app to an mojolicious app enabled in builder?

徘徊边缘 提交于 2020-01-02 04:50:30
问题 given the example plack app using lots of middleware components and an mojolicious app enabled in builder (see below), how can i pass parameters from the app.psgi to Mojolicious without using the ugly %ENV hack shown? of cause passing an config is just an example, this could be any scalar/object. app.psgi use Plack::Builder; $ENV{CONFIG} = {...}; builder { ... Mojolicious::Commands->start_app('MyApp'); }; MyApp.pm package MyApp; use Mojo::Base 'Mojolicious'; sub startup { my $self = shift; my

How do I fake the client IP address in a unit test for a Mojolicious app?

天大地大妈咪最大 提交于 2020-01-01 08:13:30
问题 In my Mojolicious app I need to use the client's IP address ( $c->tx->remote_address ) for rate limiting of a service. This works well. I am now trying to build a unit test for this feature, but I am having trouble faking the client's IP in my tests. First I thought that local_address in Mojo::UserAgent might do what I want, but that's where the user agent binds the application locally, and changing it breaks everything because it cannot find the app any more. I then tried using Sub::Override

How Upload file using Mojolicious?

匆匆过客 提交于 2020-01-01 02:10:32
问题 I have been trying out Mojolicious web framework based on perl. And I have try to develop a full application instead of the Lite. The problem I am facing is that I am trying to upload files to server, but the below code is not working. Please guide me what is wrong with it. Also, if the file gets uploaded then is it in public folder of the application or some place else. Thanks in advance. sub posted { my $self = shift; my $logger = $self->app->log; my $filetype = $self->req->param('filetype'

Logging of ip address, transaction id or session id in Mojo::Log

▼魔方 西西 提交于 2019-12-25 08:07:00
问题 I make use of simple logging in mojolicious application. I want to extend logging by some information. This could be ip address or transaction id or session id. What I do before is writing for each log level one helper like this: $self->helper( 'info' => sub { my $self=shift; my $msg=shift; my $ip=$self->tx->remote_address; $self->app->log->info("[$ip] $msg"); }); ... $self->info("Login failed of user $user."); I would like to modify format of logging output so I can make use of generic log