Skip to content

Instantly share code, notes, and snippets.

View TristinDavis's full-sized avatar

Tristin Davis TristinDavis

  • Thrivent Financial
  • Arkansas, USA
  • 19:30 (UTC -05:00)
View GitHub Profile
@TristinDavis
TristinDavis / index.pl
Created November 17, 2012 16:38 — forked from dvinciguerra/index.pl
Mojolicious::Lite and Ajax Example
#!/usr/bin/env perl
use DateTime;
use Mojolicious::Lite;
get '/' => 'index';
get '/service/datetime' => sub {
my $self = shift;
my $dt = DateTime->now;
#!/usr/bin/perl
use Mojolicious::Lite;
get '/' => { message => '' } => 'index';
post '/' => sub {
my $self = shift;
# getting params
my $email = $self->param('email') || '';
use Mojolicious::Lite;
use EV;
use AnyEvent;
use AnyEvent::Util;
get '/' => sub {
my $self = shift;
# Run Perl oneliner in separate process and capture STDOUT
fork_call {
use strict;
use warnings;
use IO::Async::Channel;
use IO::Async::Loop;
use IO::Async::Routine;
my $loop = IO::Async::Loop->new();
{
package PiffHop;
use strict;
use warnings;
use base 'Mojolicious';
# This method will run once at server start
sub startup {
my $self = shift;
@TristinDavis
TristinDavis / myapp-validationclass-example.pl
Created November 16, 2012 01:40
Validation-Class Basics
package MyApp::Validation;
use Validation::Class;
use base 'Validation::Class';
# a validation rule
field 'login' => {
label => 'user login',
error => 'login invalid',
validation => sub {
@TristinDavis
TristinDavis / myapp-validationclass-example.pl
Created November 16, 2012 01:40
Validation-Class Basics
package MyApp::Validation;
use Validation::Class;
use base 'Validation::Class';
# a validation rule
field 'login' => {
label => 'user login',
error => 'login invalid',
validation => sub {
#!/usr/bin/env perl
use common::sense;
use lib qw(../.. /tk/lib /tk/mojo2/lib);
use ojo;
use Util;
use Unicode::Normalize 'NFD';
use Data::Dumper;
my $conf = {
use Mojolicious::Lite;
get '/tasks' => sub {
my $self = shift;
$self->stash(
tasks => [
map { [ split /\s+/ ] }
split /\n/, qx(ps axh -o comm,stat,\%cpu,nice,pid,rss,user)
]
@TristinDavis
TristinDavis / gist:4083031
Created November 16, 2012 01:17 — forked from sharifulin/gist:335531
Nested layouts for the Mojolicious
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => 'index';
get '/ok' => 'index_ok';
use Test::More;
plan tests => 6;