Skip to content

Instantly share code, notes, and snippets.

View draegtun's full-sized avatar

Barry Walsh draegtun

View GitHub Profile
{
package Point;
use Moose;
has x => ( isa => 'Int', is => 'rw' );
has y => ( isa => 'Int', is => 'rw' );
sub negated {
my $self = shift;
$self->new( x => -$self->x, y => -$self->y );
use MooseX::Declare;
class Point {
has x => ( isa => 'Int', is => 'rw' );
has y => ( isa => 'Int', is => 'rw' );
method negated { $self->new( x => -$self->x, y => -$self->y ) }
method transpose { $self->new( x => $self->y, y => $self->x ) }
use MooseX::Declare;
role DoesNegated {
method negated { $self->new( x => -$self->x, y => -$self->y ) }
}
role DoesTranspose {
method transpose { $self->new( x => $self->y, y => $self->x ) }
}
@draegtun
draegtun / Animal.pl
Created June 30, 2009 09:34
Simple Moose class inheritance
#!/usr/local/bin/perl
{
package Animal;
use Moose;
has extinct => ( isa => 'Bool', is => 'rw' );
no Moose;
}
@draegtun
draegtun / Url.pm
Created December 15, 2009 14:48
URL in Perl with no strings attached!
package Url;
use Modern::Perl;
use Devel::Declare ();
use LWP::Simple ();
use base 'Devel::Declare::Context::Simple';
sub import {
my $class = shift;
my $caller = caller;
my $ctx = __PACKAGE__->new;
@draegtun
draegtun / meta_perl6.pl
Created January 13, 2010 21:25
Perl6 metaprogramming example
#!/usr/bin/env perl6
# see:
# * http://transfixedbutnotdead.com/2010/01/13/anyone_for_metaprogramming/
# * http://transfixedbutnotdead.com/2010/01/14/anyone-for-perl-6-metaprogramming/
# * http://fingernailsinoatmeal.com/post/292301859/metaprogramming-ruby-vs-javascript
# * http://transfixedbutnotdead.com/2010/10/31/perl6-metaprogramming-update/
# below runs on Rakudo Star (2010.10 release).
@draegtun
draegtun / meta_programming.io
Created April 20, 2010 14:48
Io metaprogramming example
#!/usr/bin/env io
# see: http://transfixedbutnotdead.com/2010/01/14/anyone-for-perl-6-metaprogramming/
# http://gist.github.com/276591
Ninja := Object clone do (
name ::= nil
)
drew := Ninja clone setName ("Drew")
#!/usr/bin/env perl
SIX (UNIMPRESSIVE) ;# Markdown version:
REASONS CAMPING IS BETTER ;# 1) Download this email
THAN YOU WOULD IMAGINE ;# 2) ruby email.rb
$reasons->push(COMMUNITY, q%
Yes, Sinatra has a big community, but Camping definitely has a great
community too. Size doesn't always matter. Because there are so few users,
it means every single issue gets full attention.
#!/usr/bin/env perl
use 5.012;
use warnings;
use autodie;
# quick & crude example for comment in:
# http://stackoverflow.com/questions/3308149/perl-function-knowing-receiver-type/3308591#3308591
{
@draegtun
draegtun / infix.pl
Created August 20, 2010 14:59
Custom infix operators in perl5
#!/usr/bin/env perl
# custom infix operators in perl
# see "Infix operators in Python" - http://code.activestate.com/recipes/384122/
# - http://news.ycombinator.com/item?id=1606155
use 5.012;
use warnings;
{