Skip to content

Instantly share code, notes, and snippets.

View augensalat's full-sized avatar

Bernhard Graf augensalat

  • Berlin, Germany
View GitHub Profile
perl -MMojo::Util=dumper -MYAML -wE '
no warnings "once";
sub Vault::yaml_load {
my ($class, $node) = @_;
my ($h, $s) = sub { my @l = split /\n/, $$node; return (shift @l, join("", @l)) }->();
my %h;
@h{qw(blurb version encryption id)} = split /;/, $h;
bless {%h, secret => $s}, $class;
}
$YAML::TagClass->{vault} = "Vault";
@augensalat
augensalat / collectionformat.t
Last active November 7, 2019 17:39
Swagger2: collectionFormat is optional for multi-value parameters
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);
},
@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);
},
@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'
);
{
"swagger" : "2.0",
"x-bundled" : {
"__definitions_DefaultResponse" : {
"type" : "object",
"properties" : {
"errors" : {
"items" : {
"type" : "object",
"required" : [
{
"schemes" : [
"http"
],
"paths" : {
"/echo" : {
"post" : {
"x-mojo-name" : "echo",
"responses" : {
"200" : {
@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->()) {
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;
+
#!/usr/bin/env perl
BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}
use strict;
use warnings;
use Mojo::IOLoop;
@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;