mojolicious

Match any GET path with Mojolicious::Lite

谁说我不能喝 提交于 2021-02-19 03:39:06
问题 I’d like to match any GET request in Mojolicious::Lite. The code looks like this: get '.*' => sub { my $self = shift; $self->render(text => 'Nothing to see here, move along.'); }; This dies with “Modification of non-creatable array value attempted” at MojoX::Routes::Pattern.pm, line 301. I tried other arguments to get , like qr// . That works for / , but does not match /foo . I also tried to peek at the source, but I’m none the wiser. Are you? 回答1: I think you want: get '/(*restofpath)' => ..

How can I execute code after rendering in Mojolicious?

狂风中的少年 提交于 2021-02-10 03:09:33
问题 I have some long running code that I'd like to execute after rendering in a Mojolicious app. I'd like to avoid using Minion queues as I'd be calling many very short processes, and I've looked into Mojolicious::Plugin::ForkCall and Mojolicious::Plugin::Subprocess but they both timeout (as the short processes get called many times). I remember coming across an example of this somewhere but cannot find it anymore. Any help? 回答1: Call fork in an after_dispatch hook? $app->hook(after_dispatch =>

How can I execute code after rendering in Mojolicious?

泪湿孤枕 提交于 2021-02-10 03:08:39
问题 I have some long running code that I'd like to execute after rendering in a Mojolicious app. I'd like to avoid using Minion queues as I'd be calling many very short processes, and I've looked into Mojolicious::Plugin::ForkCall and Mojolicious::Plugin::Subprocess but they both timeout (as the short processes get called many times). I remember coming across an example of this somewhere but cannot find it anymore. Any help? 回答1: Call fork in an after_dispatch hook? $app->hook(after_dispatch =>

How can I execute code after rendering in Mojolicious?

一笑奈何 提交于 2021-02-10 03:04:46
问题 I have some long running code that I'd like to execute after rendering in a Mojolicious app. I'd like to avoid using Minion queues as I'd be calling many very short processes, and I've looked into Mojolicious::Plugin::ForkCall and Mojolicious::Plugin::Subprocess but they both timeout (as the short processes get called many times). I remember coming across an example of this somewhere but cannot find it anymore. Any help? 回答1: Call fork in an after_dispatch hook? $app->hook(after_dispatch =>

How do I most reliably preserve HTML Entities when processing HTML documents with Mojo::DOM?

旧巷老猫 提交于 2020-08-24 07:26:44
问题 I'm using Mojo::DOM to identify and print out phrases (meaning strings of text between selected HTML tags) in hundreds of HTML documents that I'm extracting from existing content in the Movable Type content management system. I'm writing those phrases out to a file, so they can be translated into other languages as follows: $dom = Mojo::DOM->new(Mojo::Util::decode('UTF-8', $page->text)); ########## # # Break down the Body into phrases. This is done by listing the tags and tag combinations

How do I most reliably preserve HTML Entities when processing HTML documents with Mojo::DOM?

▼魔方 西西 提交于 2020-08-24 07:25:09
问题 I'm using Mojo::DOM to identify and print out phrases (meaning strings of text between selected HTML tags) in hundreds of HTML documents that I'm extracting from existing content in the Movable Type content management system. I'm writing those phrases out to a file, so they can be translated into other languages as follows: $dom = Mojo::DOM->new(Mojo::Util::decode('UTF-8', $page->text)); ########## # # Break down the Body into phrases. This is done by listing the tags and tag combinations

Mojolicious / Perl - Getting IP from packet?

China☆狼群 提交于 2020-05-31 22:34:30
问题 I've written an API using the Perl 'Mojolicious' framework that recieves requests from other web servers via CORS, however I'm having trouble extracting the IP address of the requesting server . Extracting headers like X-Forwarded-For only gives the IP address of the client? Is there any way in Perl or Mojolicious to extract the source IP from the IP packet itself? Using the inbuilt Mojolicious $self->tx->remote_address method doesn't work because my API web server sits behind an Nginx

Downloading files in Mojolicious

北城以北 提交于 2020-01-24 10:59:08
问题 Simple question. I have a .doc file generated in my mojolicious app. I want to download it. That's my question, how do I get the browser to download it? I'm using the CPAN module MsOffice::Word::HTML::Writer to generate the doc. Here is the sub routine in my mojolicious app, it is called by an Ajax request in Jquery: sub down_doc { my $self = shift; my $doc = MsOffice::Word::HTML::Writer->new( title => "My new Doc", WordDocument => {View => 'Print'}, ); $doc->write("Content and Stuff"); my

Mojolicious, Layouts and Positioning of Javascript

拟墨画扇 提交于 2020-01-13 19:52:13
问题 I want to load most of my scripts in my main layout ( i.e jquery). Now from my understanding it is best practice to position scripts at the bottom of my html page. However if we put the script at the bottom of the layout page like so. layout/default.html.ep <!doctype html> <html> <head><title><%= title %></title></head> <body><%=content %></body> </html> <script src="js/jquery.min.js" type="text/javascript"></script> And then use this layout in a page that has its own javascript that relies