Skip to content

Instantly share code, notes, and snippets.

View barefootcoder's full-sized avatar

Buddy Burden barefootcoder

View GitHub Profile
my %KEYNAMES = ( ' ' => 'SPACE', "\n" => 'ENTER' );
func mini_menu ($choices, $prompt, HashRef :$help, HashRef :$dispatch, CodeRef :$premenu, :$delim = ',')
{
my @choices = split(//, $choices);
if ($help)
{
push @choices, '?';
$help->{'?'} = 'print help';
}
my $opts = join($delim, map { $KEYNAMES{$_} // $_ } @choices);
@barefootcoder
barefootcoder / more_line_numbers.t
Created September 21, 2014 01:10
t/more_line_numbers.t - more rigorous testing for Devel::Declare throwing off your line numbers
use strict;
use warnings;
use Test::More;
#use Test::Exception;
use Method::Signatures;
@barefootcoder
barefootcoder / 00.md
Last active December 28, 2015 04:29
This is a quick benchmark I put together to compare command-line use of Moose vs MooseX::Declare. See below for details.

It's Moose vs MooseX::Declare in a speed showdown!!

This benchmark uses MooseX::App::Cmd to create some simple command-line apps, then uses Dumbbench to run them over and over to see which which one is fastest. Well, actually we already know that plain Moose is going to win. The real question is, is it faster enough to be significant in amongst all the overhead of starting up Perl, App::Cmd, loading Moose-guts, etc.

A few notes:

  • In the results, "MXD" indicates a command that uses MooseX::Declare at every level (app, base command, and command subclass). "NoMXD" indicates a command that does not use MooseX::Declare at all.

  • Since each run in our benchmark is spawning a shell, we're going to be comparing compile-time speed and run-time speed, but mostly compile-time (because our command doesn't do very much actual work). That's mainly what I wanted to get at with this benchmark.

@barefootcoder
barefootcoder / hashref-arrayref.pl
Created September 15, 2013 21:24
A bit of code to demonstrate how the ambiguity between auto-deferencing hashrefs and arrayrefs can be caught.
#! /usr/bin/env perl
# a standard prefix for modern Perl
use 5.014; # implies both `use strict` and `use feature :5.14`
use autodie qw< :all >;
use warnings FATAL => 'all';
my $arrayref = [ qw< foo bar baz bmoogle > ];
my $hashref = { map { $_ => 1 } @$arrayref };
@barefootcoder
barefootcoder / gen_pdf
Last active December 17, 2015 18:39
This is the little script I put together to turn my Vroom slides into a PDF. It uses `wkhtmltopdf` to do the hard work.
#! /bin/bash
# To make this work, you will need Vroom 0.28 or later. Slide notes are optional, but
# recommended. Slide titles won't be used for this application.
#
# Earlier versions of Vroom will work if you add the dashes in front of the vroom commands
# (e.g. `vroom -compile` and `vroom -html`). But the HTML is formatted a bit differently, so
# I make no promises that it will come out looking as good as the newest versions.
# You'll also need wkhtmltopdf. If you don't have it, you can get it here:
@barefootcoder
barefootcoder / augment_inner.pl
Created May 19, 2013 23:05
These are the code snippets I created for my blog post ["Augment and Inner: Haters Gotta Hate"](http://blogs.perl.org/users/buddy_burden/2013/05/augment-and-inner-haters-gotta-hate.html). Since blogs.perl.org always seems to mangle the code formatting (although not right away--it happens slowly, like the code is decaying before your eyes), I'm p…
use 5.12.0;
use warnings;
use MooseX::Declare;
use Method::Signatures::Modifiers;
class My::Command extends MooseX::App::Cmd::Command
{
# common stuff goes here
@barefootcoder
barefootcoder / quote_protector.pl
Last active December 14, 2015 16:59
This is code lifted some time ago from an older version of Filter::Simple (by the Damian). I use it whenever I need to make substituions in code-like-strings, but I want to make sure I don't changes things inside quotes.
sub whatever
{
use Text::Balanced qw< extract_multiple extract_delimited >;
my ($string) = @_;
# this replaces all quoted strings with placeholders
my @quoted_strings;
$string = join('', map { ref $_ ? scalar((push @quoted_strings, $_), "{Q$#quoted_strings}") : $_ }
extract_multiple($string,
@barefootcoder
barefootcoder / gist:4208557
Created December 4, 2012 20:54
Example of alias parameters as requested by Gabor in Perl Weekly
#! /usr/bin/env perl
use Modern::Perl;
use Method::Signatures;
func foo(\@bar, \@baz)
{
return map { $bar[$_] + $baz[$_] } 0..$#bar;
}
@barefootcoder
barefootcoder / method_signatures_args_error.pl
Created March 29, 2012 22:15
This demonstrates an error I'm getting in my code relating to Method::Signature's use of a %args variable.
use MooseX::Declare;
use Method::Signatures::Modifiers;
class foo
{
method glitch (:$foo)
{
my %args;
}
}
@barefootcoder
barefootcoder / inner_pm.pm
Created October 28, 2011 21:24
Demonstration of on_scope_end
package inner_pm;
BEGIN { warn "compiling inner pm" };
use B::Hooks::EndOfScope;
sub inner_pm_func
{
warn "entering inner pm sub";
unless (0)