1Mojo(3) User Contributed Perl Documentation Mojo(3)
2
3
4
6 Mojo - Web development toolkit
7
9 # HTTP/WebSocket user agent
10 use Mojo::UserAgent;
11 my $ua = Mojo::UserAgent->new;
12 say $ua->get('www.mojolicious.org')->result->headers->server;
13
14 # HTML/XML DOM parser with CSS selectors
15 use Mojo::DOM;
16 my $dom = Mojo::DOM->new('<div><b>Hello Mojo!</b></div>');
17 say $dom->at('div > b')->text;
18
19 # Perl-ish templates
20 use Mojo::Template;
21 my $mt = Mojo::Template->new(vars => 1);
22 say $mt->render('Hello <%= $what %>!', {what => 'Mojo'});
23
24 # HTTP/WebSocket server
25 use Mojo::Server::Daemon;
26 my $daemon = Mojo::Server::Daemon->new(listen => ['http://*:8080']);
27 $daemon->unsubscribe('request')->on(request => sub {
28 my ($daemon, $tx) = @_;
29 $tx->res->code(200);
30 $tx->res->body('Hello Mojo!');
31 $tx->resume;
32 });
33 $daemon->run;
34
35 # Event loop
36 use Mojo::IOLoop;
37 for my $seconds (1 .. 5) {
38 Mojo::IOLoop->timer($seconds => sub { say $seconds });
39 }
40 Mojo::IOLoop->start;
41
43 A powerful web development toolkit, with all the basic tools and
44 helpers needed to write simple web applications and higher level web
45 frameworks, such as Mojolicious. Some of the most commonly used tools
46 are Mojo::UserAgent, Mojo::DOM, Mojo::JSON, Mojo::Server::Daemon,
47 Mojo::Server::Prefork, Mojo::IOLoop and Mojo::Template.
48
49 See Mojolicious::Guides for more!
50
52 Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
53
54
55
56perl v5.32.0 2020-07-28 Mojo(3)