/usr/share/perl5/ojo.pm is in libmojolicious-perl 2.23-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | package ojo;
use Mojo::Base -strict;
# "I heard beer makes you stupid.
# No I'm... doesn't."
use Mojo::ByteStream 'b';
use Mojo::Collection 'c';
use Mojo::DOM;
use Mojo::UserAgent;
# Silent oneliners
$ENV{MOJO_LOG_LEVEL} ||= 'fatal';
# User agent
my $UA = Mojo::UserAgent->new;
# "I'm sorry, guys. I never meant to hurt you.
# Just to destroy everything you ever believed in."
sub import {
# Prepare exports
my $caller = caller;
no strict 'refs';
no warnings 'redefine';
# Executable
$ENV{MOJO_EXE} ||= (caller)[1];
# Mojolicious::Lite
eval "package $caller; use Mojolicious::Lite;";
# Allow redirects
$UA->max_redirects(1) unless defined $ENV{MOJO_MAX_REDIRECTS};
# Application
$UA->app(*{"${caller}::app"}->());
# Functions
*{"${caller}::Oo"} = *{"${caller}::b"} = \&b;
*{"${caller}::c"} = \&c;
*{"${caller}::oO"} = sub { _request(@_) };
*{"${caller}::a"} =
sub { *{"${caller}::any"}->(@_) and return *{"${caller}::app"}->() };
*{"${caller}::d"} = sub { _request('delete', @_) };
*{"${caller}::f"} = sub { _request('post_form', @_) };
*{"${caller}::g"} = sub { _request('get', @_) };
*{"${caller}::h"} = sub { _request('head', @_) };
*{"${caller}::p"} = sub { _request('post', @_) };
*{"${caller}::u"} = sub { _request('put', @_) };
*{"${caller}::x"} = sub { Mojo::DOM->new(@_) };
}
# "I wonder what the shroud of Turin tastes like."
sub _request {
# Method
my $method = $_[0] =~ m#:|/# ? 'get' : lc shift;
# Transaction
my $tx =
$method eq 'post_form'
? $UA->build_form_tx(@_)
: $UA->build_tx($method, @_);
# Process
$tx = $UA->start($tx);
# Error
my ($message, $code) = $tx->error;
warn qq/Problem loading URL "$_[0]". ($message)\n/ if $message && !$code;
return $tx->res;
}
1;
__END__
=head1 NAME
ojo - Fun Oneliners with Mojo!
=head1 SYNOPSIS
perl -Mojo -e 'b(g("mojolicio.us")->dom->at("title")->text)->say'
=head1 DESCRIPTION
A collection of automatically exported functions for fun Perl oneliners.
=head1 FUNCTIONS
L<ojo> implements the following functions.
=head2 C<a>
my $app = a('/' => sub { shift->render(json => {hello => 'world'}) });
Create a route with L<Mojolicious::Lite/"any"> and return the current
L<Mojolicious::Lite> object.
perl -Mojo -e 'a("/" => {text => "Hello Mojo!"})->start' daemon
=head2 C<b>
my $stream = b('lalala');
Turn string into a L<Mojo::ByteStream> object.
perl -Mojo -e 'b(g("mojolicio.us")->body)->html_unescape->say'
=head2 C<c>
my $collection = c(1, 2, 3);
Turn list into a L<Mojo::Collection> object.
Note that this function is EXPERIMENTAL and might change without warning!
=head2 C<d>
my $res = d('http://mojolicio.us');
Perform C<DELETE> request with L<Mojo::UserAgent/"delete"> and return
resulting L<Mojo::Message::Response> object.
=head2 C<f>
my $res = f('http://kraih.com/foo' => {test => 123});
Perform C<POST> form request with L<Mojo::UserAgent/"post_form"> and return
resulting L<Mojo::Message::Response> object.
=head2 C<g>
my $res = g('http://mojolicio.us');
Perform C<GET> request with L<Mojo::UserAgent/"get"> and return resulting
L<Mojo::Message::Response> object.
One redirect will be followed by default, you can change this behavior with
the C<MOJO_MAX_REDIRECTS> environment variable.
MOJO_MAX_REDIRECTS=0 perl -Mojo -e 'b(g("mojolicio.us")->code)->say'
=head2 C<h>
my $res = h('http://mojolicio.us');
Perform C<HEAD> request with L<Mojo::UserAgent/"head"> and return resulting
L<Mojo::Message::Response> object.
=head2 C<p>
my $res = p('http://mojolicio.us');
Perform C<POST> request with L<Mojo::UserAgent/"post"> and return resulting
L<Mojo::Message::Response> object.
=head2 C<u>
my $res = u('http://mojolicio.us');
Perform C<PUT> request with L<Mojo::UserAgent/"put"> and return resulting
L<Mojo::Message::Response> object.
=head2 C<x>
my $dom = x('<div>Hello!</div>');
Turn HTML5/XML input into L<Mojo::DOM> object.
say x('<div>Hello!</div>')->at('div')->text;
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
=cut
|