| 1 | package Mojo; | ||
| 2 | use Mojo::Base -strict; | ||
| 3 | |||
| 4 | # "Professor: These old Doomsday devices are dangerously unstable. I'll rest | ||
| 5 | # easier not knowing where they are." | ||
| 6 | 1; | ||
| 7 | |||
| 8 | =encoding utf8 | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | Mojo - Web development toolkit | ||
| 13 | |||
| 14 | =head1 SYNOPSIS | ||
| 15 | |||
| 16 | # HTTP/WebSocket user agent | ||
| 17 | use Mojo::UserAgent; | ||
| 18 | my $ua = Mojo::UserAgent->new; | ||
| 19 | say $ua->get('www.mojolicious.org')->result->headers->server; | ||
| 20 | |||
| 21 | # HTML/XML DOM parser with CSS selectors | ||
| 22 | use Mojo::DOM; | ||
| 23 | my $dom = Mojo::DOM->new('<div><b>Hello Mojo!</b></div>'); | ||
| 24 | say $dom->at('div > b')->text; | ||
| 25 | |||
| 26 | # Perl-ish templates | ||
| 27 | use Mojo::Template; | ||
| 28 | my $mt = Mojo::Template->new(vars => 1); | ||
| 29 | say $mt->render('Hello <%= $what %>!', {what => 'Mojo'}); | ||
| 30 | |||
| 31 | # HTTP/WebSocket server | ||
| 32 | use Mojo::Server::Daemon; | ||
| 33 | my $daemon = Mojo::Server::Daemon->new(listen => ['http://*:8080']); | ||
| 34 | $daemon->unsubscribe('request')->on(request => sub ($daemon, $tx) { | ||
| 35 | $tx->res->code(200); | ||
| 36 | $tx->res->body('Hello Mojo!'); | ||
| 37 | $tx->resume; | ||
| 38 | }); | ||
| 39 | $daemon->run; | ||
| 40 | |||
| 41 | # Event loop | ||
| 42 | use Mojo::IOLoop; | ||
| 43 | for my $seconds (1 .. 5) { | ||
| 44 | Mojo::IOLoop->timer($seconds => sub { say $seconds }); | ||
| 45 | } | ||
| 46 | Mojo::IOLoop->start; | ||
| 47 | |||
| 48 | =head1 DESCRIPTION | ||
| 49 | |||
| 50 | A powerful web development toolkit, with all the basic tools and helpers needed to write simple web applications and | ||
| 51 | higher level web frameworks, such as L<Mojolicious>. Some of the most commonly used tools are L<Mojo::UserAgent>, | ||
| 52 | L<Mojo::DOM>, L<Mojo::JSON>, L<Mojo::Server::Daemon>, L<Mojo::Server::Prefork>, L<Mojo::IOLoop> and L<Mojo::Template>. | ||
| 53 | |||
| 54 | See L<Mojolicious::Guides> for more! | ||
| 55 | |||
| 56 | =head1 SEE ALSO | ||
| 57 | |||
| 58 | L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | ||
| 59 | |||
| 60 | =cut |