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 to STDERR not STDOUT β€” 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