Skip to content

Instantly share code, notes, and snippets.

View fgabolde's full-sized avatar

Fabrice Gabolde fgabolde

View GitHub Profile
@fgabolde
fgabolde / bench-type-tiny.out
Last active December 20, 2015 16:59
Benchmarking Type::Tiny parameter validation, all three variants from the SYNOPSIS, plus Params::Validate thrown in for good measure.
$ perl bench-type-tiny.pl
Rate shortcutly params_validate stately lexically
shortcutly 9137/s -- -86% -96% -96%
params_validate 67202/s 635% -- -68% -68%
stately 207567/s 2172% 209% -- -2%
lexically 212347/s 2224% 216% 2% --
@fgabolde
fgabolde / curry.pl
Last active December 17, 2015 16:09
Currying with Moose.
#!perl
use strict;
use warnings;
use 5.010;
use Carp;
package Supercali;
use Moose;
@fgabolde
fgabolde / reloading.pl
Created April 26, 2013 15:07
Reloading a module at runtime.
#!perl
use strict;
use warnings;
use 5.010;
use Carp;
eval 'require Package::Reloaded';
if ($@) { say "exception: $@" }
@fgabolde
fgabolde / Build.PL
Created April 12, 2013 09:38
Skipping SVN junk in a Module::Build share_dir.
use 5.010;
use strict;
use warnings;
use Module::Build;
my $class = Module::Build->subclass(code => q{sub _share_dir_map {
my ($self, $prefix, $list) = @_;
my %files;
for my $dir ( @$list ) {
for my $f ( @{ $self->rscan_dir( $dir, sub {-f and not m/\B.svn/} )} ) {
@fgabolde
fgabolde / real_unicorns.t
Created April 5, 2013 14:40
Baking roles into Moose classes.
use strict;
use warnings;
use 5.012;
use Carp;
use Moose;
use Moose::Util qw/apply_all_roles with_traits/;
use Test::More;
{
@fgabolde
fgabolde / object-oriented-filehandles.pl
Created November 29, 2012 15:01
Object-oriented filehandles
#!perl
use strict;
use warnings;
use IO::File;
my $target = shift or die 'no arg? go away';
open my $fh, '>', $target
@fgabolde
fgabolde / catch_warnings.pl
Created November 29, 2012 14:18
Catching warnings
#!perl
use strict;
use warnings;
use 5.010;
my $escape = 0;
while (not $escape) {
@fgabolde
fgabolde / bench_unpacking.pl
Created November 26, 2012 14:09
Comparing performance of common idioms for unpacking a subroutine's arguments
#!perl
use strict;
use warnings;
use 5.010;
use Carp;
use Params::Validate qw/validate/;
use Benchmark qw/cmpthese/;
@fgabolde
fgabolde / redenumifying.pl
Created November 7, 2012 10:50
Solving JSON encoding issues when handling numbers
#!perl
use strict;
use warnings;
use 5.010;
use JSON;
my $number = 3.5;
my $string = 3.5;
@fgabolde
fgabolde / a_dancer_route.pm
Created September 19, 2012 13:49
Demonstrate incremental building of DBIC queries
get '/routers' => sub {
my $routers = schema->resultset('Router')->search({},
{ join => [ qw/network device_type/ ],
prefetch => [ qw/network device_type/ ],
order_by => 'me.name' });
my $networks = schema->resultset('Network')->search({},
{ order_by => 'name' });