mojolicious

Parallel requests in Mojolicious application

江枫思渺然 提交于 2019-12-09 19:19:43
问题 I have perl application which, for example, parallel searching in google: use Mojo::UserAgent; use Mojo::IOLoop; my $ua = Mojo::UserAgent->new(); my $delay = Mojo::IOLoop->delay(sub { say 'DONE1 (should be before render)'; }); foreach my $i ( 1 .. 10 ) { $delay->begin(); $ua->get("http://www.google.ru/search?q=$i" => sub { say $i; $delay->end(); }); } $delay->wait() unless $delay->ioloop->is_running(); say 'DONE2 (should be before render)'; say 'Found! (render)'; And it's works fine: 6 1 7 10

How can I take credentials from the command line in a Mojolicious app?

被刻印的时光 ゝ 提交于 2019-12-08 17:40:20
问题 I am developing a Mojolcious standalone application. In the code I am contacting an internal backend where the user should provide some credentials. Currently I am using the credentials inside the code as variables. It looks some something like: $password = 'somthing'; I tried to use the config plugin to store the credentials there, but is there an option with Mojolicious to let the user provide his credentials when running the daemon? Maybe like: perl myapp.pl daemon -user username -password

HTTP reponse for error in REST call for Mojolicious

人盡茶涼 提交于 2019-12-07 12:21:01
问题 The mojolicious application that I use is JSON based, that is the interaction between the client and the server is more of an exchange of JSON structured data. I am trying to implement a standard way of handling errors with proper HTTP response code when an error occurs during one of the REST calls. What is the best way of implementing such a standard and where do I do it? I see a couple of ways of doing it Create a class and list all the error response and its associated content, a call

How to upload multiple files using Mojolicious?

大城市里の小女人 提交于 2019-12-07 07:49:42
问题 I'm new to Mojolicious, trying to learn it. I'm trying to upload multiple files using form but only one file is uploaded at a time. Any suggestion? #!perl -w use Mojolicious::Lite; use Mojo::Upload; use v5.14; get '/' => 'page'; post '/' => sub { my $self = shift; my @files; for my $file ($self->req->upload('files')) { my $size = $file->size; my $name = $file->filename; push @files, "$name ($size)"; $file->move_to("C:\\Program Files\\Apache Software Foundation\\Apache24\\htdocs\

perl Mojo and JSON for simultaneous requests

ε祈祈猫儿з 提交于 2019-12-06 07:52:47
问题 I'm usually no Perl coder. However I've got to complete this task. The following code works for me: #!/usr/bin/perl use LWP::UserAgent; use JSON; use strict; my $md5 = $ARGV[0]; $md5 =~ s/[^A-Fa-f0-9 ]*//g; die "invalid MD5" unless ( length($md5) == 32 ); my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 1 }, timeout => 10); my $key="12345...7890"; my $url='https://www.virustotal.com/vtapi/v2/file/report'; my $response = $ua->post( $url, ['apikey' => $key, 'resource' => $md5] );

How to upload multiple files using Mojolicious?

二次信任 提交于 2019-12-05 14:46:27
I'm new to Mojolicious, trying to learn it. I'm trying to upload multiple files using form but only one file is uploaded at a time. Any suggestion? #!perl -w use Mojolicious::Lite; use Mojo::Upload; use v5.14; get '/' => 'page'; post '/' => sub { my $self = shift; my @files; for my $file ($self->req->upload('files')) { my $size = $file->size; my $name = $file->filename; push @files, "$name ($size)"; $file->move_to("C:\\Program Files\\Apache Software Foundation\\Apache24\\htdocs\\ProcessingFolder\\".$name); } $self->render(text => "@files"); } => 'save'; app->start; __DATA__ @@ page.html.ep <

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

和自甴很熟 提交于 2019-12-05 08:50:21
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 $r = $self->routes; $self->config( $ENV{CONFIG} ); $r->route('/')->to('home#'); } This is an

mojolicious referencing a stash variable not always defined

回眸只為那壹抹淺笑 提交于 2019-12-05 04:01:39
I am still learning mojolicious and MVC frameworks in general so this just might be a problem where I am thinking about this wrong so if I am please suggest a better way to do the following. I have a route /route/:param where param is sometimes defined and sometimes not. I am trying to use "param" in the template for that route but I get an error saying "param" requires explicit package name. I know this is due to :param not matching in the route because when I do call /route/value everything works fine. Is there a way to be able to use the same template for both when "param" is defined and

Parallel requests in Mojolicious application

余生长醉 提交于 2019-12-04 14:18:05
I have perl application which, for example, parallel searching in google: use Mojo::UserAgent; use Mojo::IOLoop; my $ua = Mojo::UserAgent->new(); my $delay = Mojo::IOLoop->delay(sub { say 'DONE1 (should be before render)'; }); foreach my $i ( 1 .. 10 ) { $delay->begin(); $ua->get("http://www.google.ru/search?q=$i" => sub { say $i; $delay->end(); }); } $delay->wait() unless $delay->ioloop->is_running(); say 'DONE2 (should be before render)'; say 'Found! (render)'; And it's works fine: 6 1 7 10 3 9 2 5 8 4 DONE1 (should be before render) DONE2 (should be before render) Found! (render) When I use

perl Mojo and JSON for simultaneous requests

烈酒焚心 提交于 2019-12-04 11:51:27
I'm usually no Perl coder. However I've got to complete this task. The following code works for me: #!/usr/bin/perl use LWP::UserAgent; use JSON; use strict; my $md5 = $ARGV[0]; $md5 =~ s/[^A-Fa-f0-9 ]*//g; die "invalid MD5" unless ( length($md5) == 32 ); my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 1 }, timeout => 10); my $key="12345...7890"; my $url='https://www.virustotal.com/vtapi/v2/file/report'; my $response = $ua->post( $url, ['apikey' => $key, 'resource' => $md5] ); die "$url error: ", $response->status_line unless $response->is_success; my $results=$response->content;