mojolicious

How can I do multipart requests mith Mojo::UserAgent?

核能气质少年 提交于 2019-12-23 19:07:32
问题 I'd like to perform a multipart file upload to Google Drive as described here using a Mojo::UserAgent. I currently do it like this: my $url = Mojo::URL->new('https://www.googleapis.com/upload/drive/v3/files'); $url->query({ fields => 'id,parents', ocr => 'true', ocrLanguage => 'de', uploadType => 'multipart' }); my $tx = $ua->post($url, json => { parents => [ '0ByFk4UawESNUX1Bwak1Ka1lwVE0' ] }, { 'Content-Type' => 'multipart/related', 'parents' => [ '0ByFk4UawESNUX1Bwak1Ka1lwVE0' ] },

serve static directory from mojolicious other than /public

a 夏天 提交于 2019-12-23 13:11:07
问题 I have looked at a variety of places to find the best way to serve a directory of static files from within a mojolicious app and this is as close as I've been able to get: package ExampleServer; use Mojo::Base 'Mojolicious'; use Mojolicious::Static; # This method will run once at server start sub startup { my $self = shift; $ENV{MOJO_REVERSE_PROXY} = 1; # TODO: generalize my $static_path = '/www/example/docroot/.well-known/acme-challenge/'; # Router my $r = $self->routes; # Normal route to

using content_for and ajax/Jquery to partially update webpage

让人想犯罪 __ 提交于 2019-12-23 12:48:19
问题 I've been slowly learning Mojolicious and Perl thanks to the great help from those on this site. I have been trying to determine the best way to dynamically update parts of my page based on the results of Jquery get calls. At the moment I have a template like this (Thanks to one of the Mojo contributors Joel) <!DOCTYPE html> <html> <head> <title><%= title %></title> </head> <body> %= content %= include 'common_js' %= content_for 'js_imports' </body> </html> Then I have a page that uses this

Mojolicious template cache is stale

試著忘記壹切 提交于 2019-12-14 01:20:07
问题 I'm currently developing a small single-page Web app using Mojolicious. The app has a Javascript frontend (using Backbone) that talks to a REST-ish API; the layout of the source is roughly: use Mojolicious::Lite; # ... setup code ... get '/' => sub { my $c = shift; # fetch+stash data for bootstrapped collections... $c->render('app_template'); }; get '/api_endpoint' => sub { my $c = shift; # fetch appropriate API data... $c->render(json => $response); }; # ... more API endpoints ... app->start

“Use of uninitialized value $_” warning with a Mojo::UserAgent non-blocking request

孤街醉人 提交于 2019-12-13 04:22:56
问题 I am trying to make a non-blocking request with Mojo::UserAgent but when I run the code below I get Use of uninitialized value $_ in concatenation (.) or string on the print line. How can I access $_ inside the callback? my $ua = Mojo::UserAgent->new(); my @ids = qw( id1 id2 id3 ); foreach ( @ids ) { my $res = $ua->get('http://my_site/rest/id/'.$_.'.json' => sub { my ($ua, $res) = @_; print "$_ => " . $res->result->json('/net/id/desc'), "\n"; }); } Mojo::IOLoop->start unless Mojo::IOLoop->is

Output command to socket without buffering using Mojo::IOLoop

戏子无情 提交于 2019-12-12 21:03:08
问题 How to do continiously output of command (for me it's long ping) in real-time mode on Mojo server? I'm looking for some example on Mojo::IOLoop. For example, client connects to server and requests for ping X.X.X.X, server returns an non-buffered output (while ping on server return each line to output, client receive this line from socket), after that — server must drop the connection. 来源: https://stackoverflow.com/questions/3171833/output-command-to-socket-without-buffering-using-mojoioloop

Mojolicious websocket usage

我只是一个虾纸丫 提交于 2019-12-12 20:32:55
问题 Given the code below, how do I send a message to the client, via the websocket opened for '/wsinit', from within Fu::Bar::dosomething? package Fu; use Mojo::Base 'Mojolicious'; sub startup { my $r = shift->routes; $r->get('/')->to(controller => 'bar', action => 'init'); $r->websocket('/wsinit')->to(controller => 'bar', action => 'wsinit'); $r->get('/dosomething')->to(controller => 'bar', action => 'dosomething'); } 1; # -- ^L # -- package Fu::Bar; use Mojo::Base 'Mojolicious::Controller'; sub

Mojolicious render_to_string and stash values and output

China☆狼群 提交于 2019-12-12 17:25:15
问题 I'm missing a piece here, hoping someone can point me to what I've done wrong. Mojolicious app has a route /export that creates a href and sends that data to the export.html.ep template for rendering to a string (going to generate an email) The template has been stripped to bare bones for testing: % my $data = stash 'data'; % dumper $data; <div></div> The export route function: use base 'Mojolicious::Controller'; ... sub export { my $self = shift; my $log = $self->log; my $href = { foo =>

Mojo::UserAgent get() with userdefined callback

自作多情 提交于 2019-12-12 17:23:59
问题 Is there a way to write something like this with Mojo::UserAgent ,having the possibility to set equivalent options ( Range , :content_file , :content_cb , size_hint ). #!/usr/bin/env perl use warnings; use 5.12.0; use LWP::UserAgent; use File::Basename; my $url = 'ftp://ftp.vim.org/pub/vim/runtime/spell/en.utf-8.spl'; my $file = basename $url; my $ua = LWP::UserAgent->new(); my $bytes = 0; open my $fh, '>>:raw', $file or die $!; my $res = $ua->get( $url, 'Range' => "bytes=$bytes-", ':content

How to postpone <head> rendering?

不想你离开。 提交于 2019-12-12 12:32:23
问题 I have the layout like this: @@ layouts/v2.html.ep <html lang="en"> <head> %= content_for 'stylesheets' </head> <body> %= include 'layouts/v2/header' <main class="main"> %= include 'layouts/v2/menu' <div class="content"> %= content </div> </main> </body> </html> @@ layouts/v2/menu % content_for stylesheets => begin %= stylesheet 'v2/css/menu.css' % end <aside class="menu"> ... </aside> @@ layouts/v2/header % content_for stylesheets => begin %= stylesheet 'v2/css/header.css' % end <header