Skip to content

Instantly share code, notes, and snippets.

View Akron's full-sized avatar

Nils Diewald Akron

View GitHub Profile
@Akron
Akron / gist:3811025
Created October 1, 2012 11:15
Start App with a script
# test.pl:
#!/usr/bin/env perl
use TestApp;
TestApp->start;
# TestApp.pm:
package TestApp;
use Mojo::Base 'Mojolicious';
#!/usr/bin/env perl
use Mojo;
use Mojo::Base -strict;
my $ua = Mojo::UserAgent->new;
$ua->max_redirects(5);
my $domain = 'http://api.powerhousemuseum.com';
my $base_url ="$domain/api/v1/category/xml/";
my $api_key = '8fbb61ea34d6f5d';
#!/usr/bin/env perl
use Mojo;
my $ua = Mojo::UserAgent->new;
$ua->max_redirects(5);
my $base_url ='http://api.powerhousemuseum.com/api/v1/category/xml/';
my $api_key = 'xxx';
my $base_rest_url = Mojo::URL->new($base_url)->query({ api_key => $api_key});
@Akron
Akron / gist:2698091
Created May 14, 2012 23:40
Mojo::URL-Behaviour
#!/usr/bin/env perl
use Mojo::URL;
my $url = Mojo::URL->new('http://example.com/?action=test');
my $url2 = Mojo::URL->new('broker.js?foo=bar');
$url->path($url2->path);
$url->query($url2->query);
# http://example.combroker.js?foo=bar
# ^ ???
@Akron
Akron / gist:2567746
Created May 1, 2012 12:54
Hynotoad Example
#!/usr/bin/env perl
use Mojolicious::Lite;
our $counter = 0;
app->secret('kashkgfsjgnscjzgang');
app->config({
hypnotoad => {
listen => ['http://*:8765'],
#!/usr/bin/env perl
BEGIN {
unshift(@INC,
'home/me/cgi-bin/lib' # absolute path
};
use Mojolicious::Lite;
my $count = 0;
@Akron
Akron / gist:1377960
Created November 18, 2011 22:23
Filter Plugin 2 - with Closure
package Mojolicious::Plugin::Filter2;
use Mojo::Base 'Mojolicious::Plugin';
# Register plugin
sub register {
my ($plugin, $mojo) = @_;
my %filters;
# Filter helper
@Akron
Akron / gist:1377904
Created November 18, 2011 22:00
Filter Plugin
package Mojolicious::Plugin::Filter;
use Mojo::Base 'Mojolicious::Plugin';
# Register plugin
sub register {
my ($plugin, $mojo) = @_;
my %filters;
# Filter helper
@Akron
Akron / gist:1376998
Created November 18, 2011 16:45
Filtering in Mojolicious
# Some values.
my ($a, $b, $c) = ('hallo', 'foo', 'bar');
# Emit a filter hook
$c->filter(
'on_database_access' =>
\$a, \$b, \$c =>
sub { # Do whenever all subscribers are done.
print $a,"\n";
}
@Akron
Akron / gist:1314239
Created October 25, 2011 20:57
Tidy up when guests are gone (write cb)
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => sub {
my $c = shift;
$c->res->headers->content_length(5);
$c->write(
'Hallo' => sub {
my $c = shift;
sleep(3);