This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% mkdir hellomojo | |
% cd hellomojo | |
% touch myapp.pl | |
% touch Makefile.PL | |
% touch app.psgi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% dotcloud create hellomojo | |
... | |
% dotcloud deploy --type perl hellomojo.www | |
... | |
% dotcloud push hellomojo.www . | |
... | |
% dotcloud run hellomojo.www | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# main.pl | |
use Mojolicious::Lite; | |
get '/' => sub { shift->render_text('ROOT!') }; | |
under '/foo'; | |
require 'foo.pl'; | |
app->start; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use 5.14.0; | |
use Mojo::DOM; | |
# Let's start with something simple | |
my $dom = Mojo::DOM->new('<div id="a">A</div>'); | |
# All child elements now have accessors you can use instead of CSS3 selectors | |
say $dom->div->text; | |
# You also get direct hash access to element attributes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% ./myapp.pl eval -v 'join "\n", sort keys %{app->renderer->helpers}' | |
app | |
base_tag | |
check_box | |
content | |
content_for | |
dumper | |
extends | |
file_field | |
flash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use 5.14.0; | |
use Mojo::Server; | |
# Load application with mock server | |
my $server = Mojo::Server->new; | |
my $app = $server->load_app('./myapp.pl'); | |
# Access fully initialized application | |
say $app->static->paths->[0]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojolicious::Lite; | |
get '/' => sub { | |
my $self = shift; | |
# Write two chunks right away | |
$self->write("first\n"); | |
$self->write("second\n"); | |
# Wait 3 seconds and write last chunk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set background=dark | |
hi clear | |
if exists("syntax_on") | |
syntax reset | |
endif | |
let colors_name = "kraihlight" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojo::UserAgent; | |
my $ua = Mojo::UserAgent->new; | |
$ua->websocket('ws://localhost:3000/echo' => sub { | |
my $tx = pop; | |
$tx->on(finish => sub { Mojo::IOLoop->stop }); | |
$tx->on(message => sub { | |
my ($tx, $message) = @_; | |
print "$message\n"; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Mojo::Base 'Mojolicious'; | |
sub handler { | |
my $tx = pop; | |
my $res = $tx->res; | |
$res->code(200); | |
$res->body('Hello World!'); | |
$tx->resume; | |
}; |