Skip to content

Instantly share code, notes, and snippets.

View augensalat's full-sized avatar

Bernhard Graf augensalat

  • Berlin, Germany
View GitHub Profile
@augensalat
augensalat / gist:3699443
Created September 11, 2012 14:59
Simple Mojolicious::Lite upload
#!/usr/bin/env perl
use Mojolicious::Lite;
any '/upload' => sub {
my $self = shift;
# Check file size
return $self->render(text => 'File is too big.', status => 200)
if $self->req->is_limit_exceeded;
#!/usr/bin/env perl
use strict;
use warnings;
use Mojo::IOLoop;
use Mojo::UserAgent;
# Build a normal transaction
my $ua = Mojo::UserAgent->new;
@augensalat
augensalat / eventemitter-debug
Created June 24, 2015 09:35
extended debugging for Mojo::EventEmitter
--- a/lib/Mojo/EventEmitter.pm
+++ b/lib/Mojo/EventEmitter.pm
@@ -12,7 +12,11 @@ sub emit {
if (my $s = $self->{events}{$name}) {
warn "-- Emit $name in @{[blessed $self]} (@{[scalar @$s]})\n" if DEBUG;
- for my $cb (@$s) { $self->$cb(@_) }
+ my $i = 0;
+ for my $cb (@$s) {
+ warn "xx call cb #@{[$i++]} $name in @{[blessed $self]}\n" if DEBUG;
#!/usr/bin/env perl
BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}
use strict;
use warnings;
use Mojo::IOLoop;
diff --git a/lib/Mojolicious/Plugin/MethodOverride.pm b/lib/Mojolicious/Plugin/MethodOverride.pm
index 3a09501..e9a7f27 100644
--- a/lib/Mojolicious/Plugin/MethodOverride.pm
+++ b/lib/Mojolicious/Plugin/MethodOverride.pm
@@ -9,6 +9,9 @@ our $VERSION = '0.053';
sub register {
my ($self, $app, $conf) = @_;
+ my $log = $app->log;
+
@augensalat
augensalat / noyield.pl
Created March 15, 2017 11:31
Look Ma, no yield!
sub generiere_eins_bis_drei {
$i = 0;
return sub {
return if $i > 2;
return ++$i;
}
}
$generator = generiere_eins_bis_drei;
while ($wert = $generator->()) {
{
"schemes" : [
"http"
],
"paths" : {
"/echo" : {
"post" : {
"x-mojo-name" : "echo",
"responses" : {
"200" : {
{
"swagger" : "2.0",
"x-bundled" : {
"__definitions_DefaultResponse" : {
"type" : "object",
"properties" : {
"errors" : {
"items" : {
"type" : "object",
"required" : [
@augensalat
augensalat / register.t.pl
Created March 10, 2019 09:09
Extend test case for remote file $ref
use Mojo::Base -strict;
use Mojo::JSON 'true';
use Test::Mojo;
use Test::More;
use Mojolicious::Lite;
get(
'/no-default-options/:id' => sub { $_[0]->render(openapi => {id => $_[0]->stash('id')}) },
'Dummy'
);
@augensalat
augensalat / v3-query.t
Created November 7, 2019 10:49
Mojolicious::Plugin::OpenAPI: OpenAPI3 array parameters test
use Mojo::Base -strict;
use Test::Mojo;
use Test::More;
use Mojolicious::Lite;
get '/pets' => sub {
my $c = shift->openapi->valid_input or return;
$c->render(openapi => $c->validation->output);
},