Skip to content

Instantly share code, notes, and snippets.

@preaction
preaction / lib-Mojolicious-Plugin-Yancy.diff
Created March 20, 2020 17:20
patch to fix datetime validation of empty string
diff --git a/lib/Mojolicious/Plugin/Yancy.pm b/lib/Mojolicious/Plugin/Yancy.pm
index 7ed3e54..6ae923e 100644
--- a/lib/Mojolicious/Plugin/Yancy.pm
+++ b/lib/Mojolicious/Plugin/Yancy.pm
@@ -892,6 +892,10 @@ sub _helper_validate {
for my $prop_name ( keys %{ $schema->{properties} } ) {
my $prop = $schema->{properties}{ $prop_name };
+ # These blocks fix problems with validation only. If the
+ # problem is the database understanding the value, it must be
@preaction
preaction / gist:8a9e2cf56e13ff40d3df9fe9e4999bb6
Created February 4, 2020 20:54
Extend Yancy controller to add a modified by field
package MyApp::Controller::ModifiedBy;
use Mojo::Base 'Yancy::Controller::Yancy';
sub _add_modified_by {
my ( $c ) = @_;
$c->req->param( modified_by => $c->current_uid );
if ( my $item = $c->req->json ) {
$item->{ modified_by } = $c->current_uid;
}
}
@preaction
preaction / gist:278860ea296d0c5a84f46b1e777491e2
Created January 10, 2020 17:28
Forbid breaking encapsulation of an object
package Foo;
use overload '%{}' => sub {
my ( $package ) = caller;
if ( !$package->isa( __PACKAGE__ ) ) {
require Carp;
Carp::cluck( "Use a method instead!" );
}
return $_[0];
};
sub new { return bless { foo => 'bar' }, __PACKAGE__ }
@preaction
preaction / outline.md
Last active December 5, 2019 16:02
CPAN Testers Network - Outline

CPAN Testers Network

Goals

  1. Reduce the live database set of the primary CPAN Testers servers
    1. Mostly-static data that does not need deep querying should be removed from the database
  2. Allow individuals to run CPAN Testers databases (schema, backend, api) for their own internal use
    1. Must have an easy way to run a single node that contains a database, backend, and API
    2. Must have an easy way to configure a tester to submit to the internal node
  3. Must have a web app to show the status of the local testing infrastructure
use v5.28;
use warnings;
use experimental qw( signatures postderef );
use version;
use Data::Printer;
use MetaCPAN::Client;
my $mcpan = MetaCPAN::Client->new;
@preaction
preaction / cpantesters-docker-compose.md
Created June 22, 2019 21:54
Work with the CPAN Testers docker-compose development environment
Perl greets you simply
- print "Hello, World\n";
- Change to Hello, Perl
Perl advances when you ask it to
- say "Hello, World\n";
- use feature "say";
- Remove newline
Perl advances in jumps
@preaction
preaction / vack.bash
Created February 22, 2019 17:03
Useful shell functions / scripts
vack() {
# Takes a keyword as an argument, acks current directory, opens a vim session
# with a tab for each file with a match found, and puts the keyword in the @/
# register, so that you can `n` through matches.
my_search=$(ack -l "$1")
if [[ -z $my_search ]]
then
echo "No results found for $1"
else
args=(--cmd "let @/=\"$1\"" -p )
package Local::Plugin::MyPlugin;
use Mojo::Base 'Mojolicious::Plugin';
sub cached_thing {
state $cache = 'expensive';
return $cache;
}
sub register {
my ( $self, $app, $conf ) = @_;
$app->helper( myplugin => sub { $self } );
}
#!/usr/bin/env perl
use Mojolicious::Lite;
use Time::HiRes qw( time );
plugin Minion => {
SQLite => 'sqlite:' . app->home->child('minion.db'),
};
app->minion->add_task(