Skip to content

Instantly share code, notes, and snippets.

use Mojolicious::Lite;
get '/a' => sub {
my $self = shift;
$self->res->code(403);
};
app->start;
python -m SimpleHTTPServer
$self->render('ok!')
if $self->ssl_auth( sub {
return 1 if shift->peer_certificate('commonName') eq 'whatever'
} );
$self->render('ok!')
if $self->params_auth( userinput => passinput => captchainput =>
sub { return 1 if "@_" eq 'username password 58ehda3' }
);
$self->render('ok!')
if $self->basic_auth(
realm => sub { return 1 if "@_" eq 'username password' }
);
Mojo::UserAgent->new->get('http://www.google.com/search?q=mojolicious')
->res->dom->find('h3.r a')
->each( sub { print shift->all_text . "\n" } );
my $dom = Mojo::DOM->new;
$dom->parse('
<div>
<h1 id="hope">A new hope</h1>
<p>A neat article about Mojolicious</p>
</div>
');
print $dom->at('#hope')->text;
curl -L cpanmin.us | perl - Mojolicious
my $t = Test::Mojo->new( app => 'MyApp' );
$t->get_ok('/welcome')->status_is(200);
$t->max_redirects(3)
->get_ok('/welcome')
->status_is(200)
->content_like(qr/some text/)
->content_type_is('text/html');