1Mojo(3) User Contributed Perl Documentation Mojo(3)
2
3
4
6 Mojo - The Box!
7
9 use base 'Mojo';
10
11 # All the complexities of CGI, FastCGI, PSGI, HTTP and WebSocket get
12 # reduced to a single method call!
13 sub handler {
14 my ($self, $tx) = @_;
15
16 # Request
17 my $method = $tx->req->method;
18 my $path = $tx->req->url->path;
19
20 # Response
21 $tx->res->headers->content_type('text/plain');
22 $tx->res->body("$method request for $path!");
23 }
24
26 Mojo provides a flexible runtime environment for Perl web frameworks.
27 It provides all the basic tools and helpers needed to write simple web
28 applications and higher level web frameworks such as Mojolicious.
29
30 See Mojolicious for more!
31
33 Mojo implements the following attributes.
34
35 "build_tx_cb"
36 my $cb = $mojo->build_tx_cb;
37 $mojo = $mojo->build_tx_cb(sub { ... });
38
39 The transaction builder callback, by default it builds a
40 Mojo::Transaction::HTTP object.
41
42 "client"
43 my $client = $mojo->client;
44 $mojo = $mojo->client(Mojo::Client->new);
45
46 A full featured HTTP 1.1 client for use in your applications, by
47 default a Mojo::Client object.
48
49 "home"
50 my $home = $mojo->home;
51 $mojo = $mojo->home(Mojo::Home->new);
52
53 The home directory of your application, by default a Mojo::Home object
54 which stringifies to the actual path.
55
56 "log"
57 my $log = $mojo->log;
58 $mojo = $mojo->log(Mojo::Log->new);
59
60 The logging layer of your application, by default a Mojo::Log object.
61
62 "websocket_handshake_cb"
63 my $cb = $mojo->websocket_handshake_cb;
64 $mojo = $mojo->websocket_handshake_cb(sub { ... });
65
66 The websocket handshake callback, by default it builds a
67 Mojo::Transaction::WebSocket object and handles the response for the
68 handshake request.
69
71 Mojo inherits all methods from Mojo::Base and implements the following
72 new ones.
73
74 "new"
75 my $mojo = Mojo->new;
76
77 Construct a new Mojo application. Will automatically detect your home
78 directory and set up logging to "log/mojo.log" if there's a log
79 directory.
80
81 "handler"
82 $tx = $mojo->handler($tx);
83
84 The handler is the main entry point to your application or framework
85 and will be called for each new transaction.
86
87 sub handler {
88 my ($self, $tx) = @_;
89 }
90
91 "start"
92 Mojo->start;
93 Mojo->start('daemon');
94
95 Start the Mojo::Commands command line interface for your application.
96
98 Mojolicious, Mojolicious::Guides, <http://mojolicious.org>.
99
100
101
102perl v5.12.3 2010-08-17 Mojo(3)