Skip to content

Instantly share code, notes, and snippets.

View TristinDavis's full-sized avatar

Tristin Davis TristinDavis

  • Thrivent Financial
  • Arkansas, USA
  • 20:56 (UTC -05:00)
View GitHub Profile
@sharifulin
sharifulin / gist:282378
Created January 20, 2010 22:53
Mojo: bug in routes
#!/usr/bin/perl
use strict;
use lib qw(lib ../mojo/lib);
$ENV{MOJO_APP} ||= 'App';
use Mojolicious::Commands; Mojolicious::Commands->start;
package App;
use strict;
@sharifulin
sharifulin / gist:292838
Created February 2, 2010 17:22
Mojo uploads
#!/usr/bin/env perl
use lib '../mojo/lib';
BEGIN { $ENV{MOJO_TMPDIR} = 'tmp/upload' };
use Mojolicious::Lite;
use Data::Dumper;
get '/' => 'form';
post '/' => sub {
@sharifulin
sharifulin / gist:335531
Created March 17, 2010 18:11
Nested layouts for the Mojolicious
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => 'index';
get '/ok' => 'index_ok';
use Test::More;
plan tests => 6;
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use Data::UUID;
use DBI;
use Time::Piece;
use Mojolicious::Lite;
@xantus
xantus / JSON.pm
Created August 2, 2010 19:39
MojoX::JSON
package MojoX::JSON;
use Mojo::JSON;
our $SINGLETON;
BEGIN {
# install JSON::XS if you can!
eval 'use JSON();';
eval ( $@ ? 'sub HAS_JSON(){ 0 }' : 'sub HAS_JSON(){ 1 }' );
#!/usr/bin/env perl
use Mojolicious::Lite;
my $use_auth = 1; # with auth enabled..
my ( $user, $pass ) = qw/user password/;
if ($use_auth) { plugin 'basic_auth'; }
get '/' => sub { my $self = shift; $self->redirect_to('/upload'); };
get '/upload' => sub {
my $self = shift;
@sharifulin
sharifulin / gist:613760
Created October 6, 2010 17:44
Mojo::IOLoop and Mojo::Client
#!/usr/bin/env perl
use lib 'lib';
use Mojo::IOLoop;
use Mojo::Client;
my $loop = Mojo::IOLoop->new;
my $client = Mojo::Client->new; $client->ioloop( $loop );
foo();
@sharifulin
sharifulin / gist:636577
Created October 20, 2010 14:56
Include and process for Mojolicious app
#!/usr/bin/env perl
use lib 'lib';
package Mojolicious::Plugin::IncludeHelpers;
use strict;
use warnings;
use base 'Mojolicious::Plugin';
use Data::Dumper;
package App::Index;
use App::Base -controller, with => ['App::News', 'App::Book', 'App::Audio'];
sub main {
my $self = shift;
my $limit = $self->conf('limit')->{index};
$self->render('index',
news => $self->news->_last(limit => $limit->{news}),
book => $self->book->_list,
#!perl
package TestApp;
use Mojolicious::Lite;
get '/one/:foo' => [ foo => [qw/bar barfly/] ] => sub { shift->render_text('hi') };
get '/two/:foo' => [ foo => qr[bar|barfly] ] => sub { shift->render_text('hi') };
package main;
use Test::More tests => 8;