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