ojo(3)
π ojo β fun one-liners with Mojo (yes that's the whole NAME, periodt)
okay so bestie, this is a page from the User Contributed Perl Documentation manual set, and honestly? it's giving main character energy for Perl one-liners. the page is filed under ojo(3) β that's the manual name, iykyk π
β¨ SYNOPSIS β¨
like, the tiniest taste of what we're doing here:
$ perl -Mojo -E 'say g("mojolicious.org")->dom->at("title")->text'
obsessed. π¦
πΈ DESCRIPTION πΈ
so ojo is a whole collection of automatically exported functions for fun Perl one-liners. no imports, no setup, they're just there for you π
Redundancy check on redirects: ten redirects will be followed by default. you can change this behavior with the MOJO_MAX_REDIRECTS environment variable:
$ MOJO_MAX_REDIRECTS=0 perl -Mojo -E 'say g("example.com")->code'
Proxy detection is enabled by default, but you can disable it with the MOJO_PROXY environment variable:
$ MOJO_PROXY=0 perl -Mojo -E 'say g("example.com")->body'
TLS certificate verification can be disabled with the MOJO_INSECURE environment variable:
$ MOJO_INSECURE=1 perl -Mojo -E 'say g("https://127.0.0.1:3000")->body'
ngl bestie, that last one is a vibe not a security strategy β it literally turns certificate verification off. use it on purpose, not by accident π
and the fun part: every ojo one-liner is also a Mojolicious::Lite application. like, every single one. slay.
$ perl -Mojo -E 'get "/" => {inline => "%= time"}; app->start' get /
on Perl 5.20+, subroutine signatures will be enabled automatically:
$ perl -Mojo -E 'a(sub ($c) { $c->render(text => "Hello!") })->start' get /
and if it is not already defined, the MOJO_LOG_LEVEL environment variable will be set to fatal.
π FUNCTIONS π
ojo implements the following functions, which are automatically exported. one letter each, iconic behavior honestly.
π a
my $app = a('/hello' => sub { $_->render(json => {hello => 'world'}) });
create a route with any in Mojolicious::Lite and return the current Mojolicious::Lite object. the current controller object is also available to actions as $_. see also Mojolicious::Guides::Tutorial for more argument variations π«Ά
$ perl -Mojo -E 'a("/hello" => {text => "Hello Mojo!"})->start' daemon
π b
my $stream = b('lalala');
turn string into a Mojo::ByteStream object.
$ perl -Mojo -E 'b(g("mojolicious.org")->body)->html_unescape->say'
π c
my $collection = c(1, 2, 3);
turn list into a Mojo::Collection object.
π d
my $res = d('example.com');
my $res = d('http://example.com' => {Accept => '*/*'} => 'Hi!');
my $res = d('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
my $res = d('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
perform DELETE request with delete in Mojo::UserAgent and return resulting Mojo::Message::Response object. no cap, that's it π
π f
my $path = f('/home/sri/foo.txt');
turn string into a Mojo::File object.
$ perl -Mojo -E 'say r j f("hello.json")->slurp'
π g
my $res = g('example.com');
my $res = g('http://example.com' => {Accept => '*/*'} => 'Hi!');
my $res = g('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
my $res = g('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
perform GET request with get in Mojo::UserAgent and return resulting Mojo::Message::Response object. the people's champion, honestly π₯
$ perl -Mojo -E 'say g("mojolicious.org")->dom("h1")->map("text")->join("\n")'
π h
my $res = h('example.com');
my $res = h('http://example.com' => {Accept => '*/*'} => 'Hi!');
my $res = h('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
my $res = h('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
perform HEAD request with head in Mojo::UserAgent and return resulting Mojo::Message::Response object.
π j
my $bytes = j([1, 2, 3]);
my $bytes = j({foo => 'bar'});
my $value = j($bytes);
encode Perl data structure or decode JSON with j in Mojo::JSON. yes it does both, it contains multitudes β¨
$ perl -Mojo -E 'f("hello.json")->spew(j {hello => "world!"})'
π l
my $url = l('https://mojolicious.org');
turn a string into a Mojo::URL object.
$ perl -Mojo -E 'say l("/perldoc")->to_abs(l("https://mojolicious.org"))'
π n
n {...};
n {...} 100;
benchmark block and print the results to STDERR, with an optional number of iterations, which defaults to 1.
$ perl -Mojo -E 'n { say g("mojolicious.org")->code }'
heads up bestie, output goes toSTDERRnotSTDOUTβ don't come for me when your pipeline looks empty π
π o
my $res = o('example.com');
my $res = o('http://example.com' => {Accept => '*/*'} => 'Hi!');
my $res = o('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
my $res = o('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
perform OPTIONS request with options in Mojo::UserAgent and return resulting Mojo::Message::Response object.
π p
my $res = p('example.com');
my $res = p('http://example.com' => {Accept => '*/*'} => 'Hi!');
my $res = p('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
my $res = p('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
perform POST request with post in Mojo::UserAgent and return resulting Mojo::Message::Response object.
π r
my $perl = r({data => 'structure'});
dump a Perl data structure with dumper in Mojo::Util.
perl -Mojo -E 'say r g("example.com")->headers->to_hash'
π t
my $res = t('example.com');
my $res = t('http://example.com' => {Accept => '*/*'} => 'Hi!');
my $res = t('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
my $res = t('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
perform PATCH request with patch in Mojo::UserAgent and return resulting Mojo::Message::Response object.
π u
my $res = u('example.com');
my $res = u('http://example.com' => {Accept => '*/*'} => 'Hi!');
my $res = u('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
my $res = u('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
perform PUT request with put in Mojo::UserAgent and return resulting Mojo::Message::Response object.
π x
my $dom = x('<div>Hello!</div>');
turn HTML/XML input into Mojo::DOM object.
$ perl -Mojo -E 'say x(f("test.html")->slurp)->at("title")->text'
π SEE ALSO π
Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
okay that's the whole page bestie, go write some one-liners π
sign-off era: this little beauty is from perl v5.42.0, dated 2026-07-15, and it lives at ojo(3) in the manual. mwah πβ¨π¦
π¦ where this page comes from
- opensuse-leap 16.0: perl-Mojolicious 9.480.0-bp160.2.1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms