1ojo(3) User Contributed Perl Documentation ojo(3)
2
3
4
6 ojo - Fun one-liners with Mojo
7
9 $ perl -Mojo -E 'say g("mojolicious.org")->dom->at("title")->text'
10
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
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 n
111 n {...};
112 n {...} 100;
113
114 Benchmark block and print the results to "STDERR", with an optional
115 number of iterations, which defaults to 1.
116
117 $ perl -Mojo -E 'n { say g("mojolicious.org")->code }'
118
119 o
120 my $res = o('example.com');
121 my $res = o('http://example.com' => {Accept => '*/*'} => 'Hi!');
122 my $res = o('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
123 my $res = o('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
124
125 Perform "OPTIONS" request with "options" in Mojo::UserAgent and return
126 resulting Mojo::Message::Response object.
127
128 p
129 my $res = p('example.com');
130 my $res = p('http://example.com' => {Accept => '*/*'} => 'Hi!');
131 my $res = p('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
132 my $res = p('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
133
134 Perform "POST" request with "post" in Mojo::UserAgent and return
135 resulting Mojo::Message::Response object.
136
137 r
138 my $perl = r({data => 'structure'});
139
140 Dump a Perl data structure with "dumper" in Mojo::Util.
141
142 perl -Mojo -E 'say r g("example.com")->headers->to_hash'
143
144 t
145 my $res = t('example.com');
146 my $res = t('http://example.com' => {Accept => '*/*'} => 'Hi!');
147 my $res = t('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
148 my $res = t('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
149
150 Perform "PATCH" request with "patch" in Mojo::UserAgent and return
151 resulting Mojo::Message::Response object.
152
153 u
154 my $res = u('example.com');
155 my $res = u('http://example.com' => {Accept => '*/*'} => 'Hi!');
156 my $res = u('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
157 my $res = u('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
158
159 Perform "PUT" request with "put" in Mojo::UserAgent and return
160 resulting Mojo::Message::Response object.
161
162 x
163 my $dom = x('<div>Hello!</div>');
164
165 Turn HTML/XML input into Mojo::DOM object.
166
167 $ perl -Mojo -E 'say x(f("test.html")->slurp)->at("title")->text'
168
170 Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
171
172
173
174perl v5.28.0 2018-05-20 ojo(3)