Skip to content

Instantly share code, notes, and snippets.

@s1037989
s1037989 / gist:7994037
Created December 16, 2013 20:43
Mojolicious Plugin CouchDB
$ cat lib/Mojolicious/Plugin/CouchDB.pm
package Mojolicious::Plugin::CouchDB;
use Mojo::Base 'Mojolicious::Plugin';
use Mojo::Exception;
use Mojo::JSON 'j';
our $VERSION = '0.01';
has 'couch' => 'http://127.0.0.1:5984/';
has 'app';
@s1037989
s1037989 / gist:8118946
Created December 25, 2013 00:00
Sample blocking and non blocking options
#!/usr/bin/perl
use Mojolicious::Lite;
# This route is to emulate a slow web request
# This slow web request does not block; while it sleeps, it passes control
# back to the dispatcher for further request processing. Once the sleep
# completes, it then connects this back to the original request.
get '/:sleep' => {sleep => 0} => sub {
my $self = shift;
use Mojolicious::Lite;
use Socket;
get '/' => {text => 'Hello, World!'};
get '/connect' => sub {
my $self = shift;
my ($ip, $protocol, $port, $myhouse, $yourhouse, $log);
$ip = '192.168.0.52';
@s1037989
s1037989 / Mojo-Storage.pm
Last active August 29, 2015 14:07
Server-side storage for Mojolicious
package Mojo::Storage;
use Mojo::Base 'Mojo::EventEmitter';
use Carp 'croak';
use DBM::Deep;
our $VERSION = '0.01';
has _home => sub { Mojo::Home->new->detect };
has _database => sub { {} };
# Failed test 'content is similar'
# at t/coffee.t line 33.
# '(function(){console.log('hello from c coffee');}).call(this);
# (function(){console.log('hello from d coffee');}).call(this);
# '
# doesn't match '(?^:c coffee.*d coffee)'
# Looks like you failed 1 test of 12.
t/coffee.t .........................
@s1037989
s1037989 / Failed test
Last active August 29, 2015 14:15
Problem with static files in Mounted apps
t/mojolicious/embedded_lite_app.t .......... 3/?
# Failed test 'exact match for content'
# at t/mojolicious/embedded_lite_app.t line 186.
Wide character in print at /usr/share/perl/5.18/Test/Builder.pm line 1759.
# got: 'myapp
# works ♥!Insecure!Insecure!
#
# too!works!!!Mojolicious::Plugin::Config::Sandbox
# <a href="/">Test</a>
# <form action="/%E2%98%83">
@s1037989
s1037989 / gist:7b388a4d01e2cd568bbb
Created February 18, 2015 06:19
CPAN release and bump version
Needs some error handling.
release ()
{
NAME=$(perl -p -E '$_ = /^\s*NAME\s*/ ? eval("{$_}")->{NAME} : undef' Makefile.PL);
VERSION_FROM=$(perl -p -E '$_ = /^\s*VERSION_FROM\s*/ ? eval("{$_}")->{VERSION_FROM} : undef' Makefile.PL);
CV=$(perl -E "require '$VERSION_FROM'; say \$$NAME::VERSION");
BV=$(perl -E "require '$VERSION_FROM'; say \$$NAME::VERSION+0.01");
rm -f Mojolicious-Plugin-MimeTypes-*.tar.gz;
git tag $CV;
@s1037989
s1037989 / oauth2.pl
Created June 25, 2015 06:45
Mojo app that logsin via oauth2
use Mojolicious::Lite;
use experimental 'signatures';
plugin "OAuth2" => {
fix_get_token => 1,
facebook => {
key => $ENV{OAUTH_KEY},
secret => $ENV{OAUTH_SECRET},
},
};
@s1037989
s1037989 / myzoutritionpal.md
Last active January 24, 2016 18:41
Code and demo of MyZoutritionPal
$ cat myapp.pl 
#!/usr/bin/env perl
use Mojolicious::Lite;

my $nn = Mojo::UserAgent->new;
$nn->get('http://zoutrition.missouri.edu/zoutrition');

get '/ShowItemNutritionLabel/:unitOid/:menuOid/:detailOid' => sub {
  my $c = shift;
@s1037989
s1037989 / tap.pl
Created February 15, 2016 09:23
Demonstration of Mojo::Base::tap()
package Cat;
use Mojo::Base -base;
has name => 'Nyan';
has ['age', 'weight'] => 4;
package Tiger;
use Mojo::Base 'Cat';
has friend => sub { Cat->new };