📜 ⬆️ ⬇️

Mojolicious v1.12

I found that the release of the wonderful Mojolicious perlomovy framework on Habré went completely unnoticed. In the meantime, version v1.12 is already available, this is regrettable , since Now it’s easier to write on pearl than ever. I will show it with a real example.

Recently I was asked to write a simple script - to request from Google the number of indexed pages on the site. I already know about Mojo * for a long time , but it didn’t get to try it anywhere. The script in the example below runs in cgi, although you can twist both under mod_perl and under fastcgi.

I used the lite lite version, the script is intentionally simplified in order to show the idea of ​​how easy it is to write under Mojo * and this is really a working script, and not a synthetic synthetic example from the manual:
')
#!/usr/bin/perl use strict; use Mojolicious::Lite; use Mojo::UserAgent; get '/' => sub { my $self = shift; my $site = $self->param('site'); #      my $text; if($site) { my $ua = Mojo::UserAgent->new; #   UserAgent #     "http://www.google.com/search?q=site%3A$site" #        <div id="resultStats"> $text = $ua->get("http://www.google.com/search?q=site%3A$site")->res->dom->at('div#resultStats'); } $self->render( 'index', #   result => $text ? $text->text : '', #     ,    site => $site, #       ); }; app->start; #        index.html.ep __DATA__ @@ index.html.ep <%= $result %><br /> <form action="/cgi-bin/get_string.pl"> site name: <input type="text" name="site" value="<%= $site %>"/> <input type="submit" /> </form> 


That's all, even easier than php :)

PS: I completely forgot to mention that Mojolicious had imputed documentation, with examples: http://mojolicio.us/perldoc

PPS: the framework is being actively updated and, as fuksito kindly noted , version 1.16 has already appeared, which fixed a serious vulnerability

Source: https://habr.com/ru/post/117693/


All Articles