1ojo(3)                User Contributed Perl Documentation               ojo(3)
2
3
4

NAME

6       ojo - Fun one-liners with Mojo
7

SYNOPSIS

9         $ perl -Mojo -E 'say g("mojolicious.org")->dom->at("title")->text'
10

DESCRIPTION

12       A collection of automatically exported functions for fun Perl one-
13       liners. Ten redirects will be followed by default, you can change this
14       behavior with the "MOJO_MAX_REDIRECTS" environment variable.
15
16         $ MOJO_MAX_REDIRECTS=0 perl -Mojo -E 'say g("example.com")->code'
17
18       Proxy detection is enabled by default, but you can disable it with the
19       "MOJO_PROXY" environment variable.
20
21         $ MOJO_PROXY=0 perl -Mojo -E 'say g("example.com")->body'
22
23       TLS certificate verification can be disabled with the "MOJO_INSECURE"
24       environment variable.
25
26         $ MOJO_INSECURE=1 perl -Mojo -E 'say g("https://127.0.0.1:3000")->body'
27
28       Every ojo one-liner is also a Mojolicious::Lite application.
29
30         $ perl -Mojo -E 'get "/" => {inline => "%= time"}; app->start' get /
31
32       On Perl 5.20+ subroutine signatures will be enabled automatically.
33
34         $ perl -Mojo -E 'a(sub ($c) { $c->render(text => "Hello!") })->start' get /
35
36       If it is not already defined, the "MOJO_LOG_LEVEL" environment variable
37       will be set to "fatal".
38

FUNCTIONS

40       ojo implements the following functions, which are automatically
41       exported.
42
43   a
44         my $app = a('/hello' => sub { $_->render(json => {hello => 'world'}) });
45
46       Create a route with "any" in Mojolicious::Lite and return the current
47       Mojolicious::Lite object. The current controller object is also
48       available to actions as $_. See also Mojolicious::Guides::Tutorial for
49       more argument variations.
50
51         $ perl -Mojo -E 'a("/hello" => {text => "Hello Mojo!"})->start' daemon
52
53   b
54         my $stream = b('lalala');
55
56       Turn string into a Mojo::ByteStream object.
57
58         $ perl -Mojo -E 'b(g("mojolicious.org")->body)->html_unescape->say'
59
60   c
61         my $collection = c(1, 2, 3);
62
63       Turn list into a Mojo::Collection object.
64
65   d
66         my $res = d('example.com');
67         my $res = d('http://example.com' => {Accept => '*/*'} => 'Hi!');
68         my $res = d('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
69         my $res = d('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
70
71       Perform "DELETE" request with "delete" in Mojo::UserAgent and return
72       resulting Mojo::Message::Response object.
73
74   f
75         my $path = f('/home/sri/foo.txt');
76
77       Turn string into a Mojo::File object.
78
79         $ perl -Mojo -E 'say r j f("hello.json")->slurp'
80
81   g
82         my $res = g('example.com');
83         my $res = g('http://example.com' => {Accept => '*/*'} => 'Hi!');
84         my $res = g('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
85         my $res = g('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
86
87       Perform "GET" request with "get" in Mojo::UserAgent and return
88       resulting Mojo::Message::Response object.
89
90         $ perl -Mojo -E 'say g("mojolicious.org")->dom("h1")->map("text")->join("\n")'
91
92   h
93         my $res = h('example.com');
94         my $res = h('http://example.com' => {Accept => '*/*'} => 'Hi!');
95         my $res = h('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
96         my $res = h('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
97
98       Perform "HEAD" request with "head" in Mojo::UserAgent and return
99       resulting Mojo::Message::Response object.
100
101   j
102         my $bytes = j([1, 2, 3]);
103         my $bytes = j({foo => 'bar'});
104         my $value = j($bytes);
105
106       Encode Perl data structure or decode JSON with "j" in Mojo::JSON.
107
108         $ perl -Mojo -E 'f("hello.json")->spurt(j {hello => "world!"})'
109
110   l
111         my $url = l('https://mojolicious.org');
112
113       Turn a string into a Mojo::URL object.
114
115         $ perl -Mojo -E 'say l("/perldoc")->to_abs(l("https://mojolicious.org"))'
116
117   n
118         n {...};
119         n {...} 100;
120
121       Benchmark block and print the results to "STDERR", with an optional
122       number of iterations, which defaults to 1.
123
124         $ perl -Mojo -E 'n { say g("mojolicious.org")->code }'
125
126   o
127         my $res = o('example.com');
128         my $res = o('http://example.com' => {Accept => '*/*'} => 'Hi!');
129         my $res = o('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
130         my $res = o('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
131
132       Perform "OPTIONS" request with "options" in Mojo::UserAgent and return
133       resulting Mojo::Message::Response object.
134
135   p
136         my $res = p('example.com');
137         my $res = p('http://example.com' => {Accept => '*/*'} => 'Hi!');
138         my $res = p('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
139         my $res = p('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
140
141       Perform "POST" request with "post" in Mojo::UserAgent and return
142       resulting Mojo::Message::Response object.
143
144   r
145         my $perl = r({data => 'structure'});
146
147       Dump a Perl data structure with "dumper" in Mojo::Util.
148
149         perl -Mojo -E 'say r g("example.com")->headers->to_hash'
150
151   t
152         my $res = t('example.com');
153         my $res = t('http://example.com' => {Accept => '*/*'} => 'Hi!');
154         my $res = t('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
155         my $res = t('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
156
157       Perform "PATCH" request with "patch" in Mojo::UserAgent and return
158       resulting Mojo::Message::Response object.
159
160   u
161         my $res = u('example.com');
162         my $res = u('http://example.com' => {Accept => '*/*'} => 'Hi!');
163         my $res = u('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
164         my $res = u('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
165
166       Perform "PUT" request with "put" in Mojo::UserAgent and return
167       resulting Mojo::Message::Response object.
168
169   x
170         my $dom = x('<div>Hello!</div>');
171
172       Turn HTML/XML input into Mojo::DOM object.
173
174         $ perl -Mojo -E 'say x(f("test.html")->slurp)->at("title")->text'
175

SEE ALSO

177       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
178
179
180
181perl v5.34.0                      2022-01-21                            ojo(3)
Impressum