Skip to content

Instantly share code, notes, and snippets.

View tobyink's full-sized avatar
🦈
hi

Toby Inkster tobyink

🦈
hi
View GitHub Profile
#!/usr/bin/env perl
# Perl 5 needs a does built-in.
# http://perldoc.perl.org/5.14.2/perltodo.html#A-does()-built-in
#
# In an ideal world the syntax would be `$foo does $bar` but Perl doesn't
# seem able to add infix operators via a module, so `$foo ~~does $bar` is
# needed. (Also in an ideal world it would have the same precedence as `eq`.
#
@tobyink
tobyink / format-registry-prototype.pl
Created August 29, 2012 09:38
Prototype for format registry
BEGIN {
package RDF::Trine::Types::X;
$INC{'RDF/Trine/Types/X.pm'} = __FILE__;
use MooseX::Types -declare => ['TrineFormat'];
use MooseX::Types::Moose qw[Str];
class_type TrineFormat, { class => 'RDF::Trine::Format' };
coerce TrineFormat,
from Str,
via { 'RDF::Trine::FormatRegistry'->instance->find_format($_) };
}
--- orig.pm 2012-09-10 20:46:41.516229122 +0100
+++ mine.pm 2012-09-10 21:38:36.168228288 +0100
@@ -1,3 +1,47 @@
+package RDF::Trine::Parser::TurtleConstants;
+
+no thanks;
+our @EXPORT;
+BEGIN {
+ @EXPORT = qw(
+ LBRACKET
@tobyink
tobyink / AcmeConstructorPythonic.pm
Created October 21, 2012 09:09
As per Hercynium's suggestion...
use strict;
use warnings;
BEGIN {
package Acme::Constructor::Pythonic;
no thanks;
use Data::OptList qw(mkopt);
use Sub::Install qw(install_sub);
use Module::Runtime qw(use_module);
sub import {
@tobyink
tobyink / method-modifiers-benchmarking.t
Created November 2, 2012 14:29
Benchmarks for Class::Method::Modifiers and Class::Method::Modifiers::Fast
use v5.14;
use Benchmark ':all';
use Test::More;
package Base {
no thanks;
sub new { bless \@_, shift }
sub foo { 1 };
sub bench {
my $class = shift;
@tobyink
tobyink / dirtree-coloured.pl
Created November 4, 2012 10:05
Pretty directory trees
#!/usr/bin/env perl
# This version adds pretty colours, plus command-line option processing
use 5.008;
use strict;
use warnings;
use utf8::all;
use constant {
{
package Param;
use Moo;
use overload q[""] => q[to_string];
has [qw/ type name /] => (is => 'ro');
sub BUILDARGS {
my $class = shift;
if (@_==1 and not ref $_[0] and $_[0] =~ /^([\$\%\@])(.+)$/) {
return +{ type => $1, name => $2 };
}
use 5.014;
use Test::More;
package Role {
use Moose::Role;
sub xxx { 'xxx' };
}
package Handler {
use Moose;
@tobyink
tobyink / isa.pm
Created November 20, 2012 16:25
Mo type constraints
package Mo::isa;
$MoPKG = "Mo::";
$VERSION = 0.31;
$Z=CODE;
sub O(_){UNIVERSAL::can(@_,isa)}
sub S(&){pop}
sub Z{1}
sub R(){ref}
sub N(){!defined}

moe wishes...

Add

  • Native MOP
  • Autoboxing
  • Built-in Try/Catch
  • Built-in Fold, Foldr and Unfold list processors
  • Lazy lists?