Skip to content

Instantly share code, notes, and snippets.

View jberger's full-sized avatar

Joel Berger jberger

View GitHub Profile
@jberger
jberger / command_output.pl
Last active August 29, 2015 14:08
Stream command output to browser via websocket
#!/usr/bin/env perl
use Mojolicious::Lite;
use 5.20.0;
use experimental 'signatures';
get '/' => {template => 'index'};
my $cmd = 'sleep 1; echo "hello world"; sleep 1; echo "yo peeps"';
#!/usr/local/bin/perl
#
# cpan-github-dists
#
# Use the MetaCPAN API to build a list of CPAN distributions that have a github repo
# We show the 2000 most-recently released distributions
#
# See output for this at http://neilb.org/github-dists.html
#
#!/usr/bin/env perl
package Test::Mojo::Phantom;
use Mojo::Base -strict;
use Test::More ();
use File::Temp ();
use Mojo::Util;
use Mojo::IOLoop;
@jberger
jberger / mbtiny-mint
Last active August 29, 2015 14:14
Build App::ModuleBuildTiny dist
#!/usr/bin/env perl
use Mojo::Base -strict;
use Mojo::Util qw/spurt/;
use Mojo::JSON qw/encode_json/;
use Mojo::URL;
use File::Spec;
use Cwd qw/cwd/;
use Mojo::Base -strict;
use Devel::Cycle;
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
sub fetch_it {
my ($url, $cb) = @_;
$ua->get($url => $cb);
}
#!/usr/bin/env perl
use Mojolicious::Lite;
use List::Util 'pairs';
use POSIX 'ceil';
my @pairs = (
Larry => 'Wall',
Tom => 'Christiansen',
use Inline::Perl5;
my $p5 = Inline::Perl5.new;
$p5.use('Mojolicious::Lite');
my $app = $p5.call('app');
$app.routes.get('/', {'text' => 'hello world'});
$app.start(@*ARGS);

Mojolicious at the Command Line

Mojolicious apps are much more than just web apps. From the command line you can unleash hidden power of Mojolicious.

In this talk, you will learn how to mojo to make one-liner prototype apps, and make web requests and inspect the results. You will learn how to use built-in commands to administer and debug your own apps. You will even learn how to add custom commands to your app, useful for adding deployment or maintenance tasks, or whatever you can dream up. I will also demonstrate some commands from CPAN, including the Minion job queue.

package Test::Mojo::Role::Cookies;
use Mojo::Base -strict;
use Role::Tiny;
use Test::More ();
use Mojo::JSON::Pointer;
use Mojo::Util 'encode';
sub _controller {
use Mojolicious::Lite;
use Mojo::URL;
hook 'before_dispatch' => sub {
my $c = shift;
my $url = $c->req->url;
$c->req->url(Mojo::URL->new(lc "$url"));
};