Skip to content

Instantly share code, notes, and snippets.

Avatar

Barry Walsh draegtun

View GitHub Profile
View Point_classic_moose.pl
{
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 );
View Point_neo_moose.pl
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 ) }
View Point_neo_moose2.pl
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 Jun 30, 2009
Simple Moose class inheritance
View Animal.pl
#!/usr/local/bin/perl
{
package Animal;
use Moose;
has extinct => ( isa => 'Bool', is => 'rw' );
no Moose;
}
@draegtun
draegtun / Url.pm
Created Dec 15, 2009
URL in Perl with no strings attached!
View Url.pm
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 Jan 13, 2010
Perl6 metaprogramming example
View meta_perl6.pl
#!/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 Apr 20, 2010
Io metaprogramming example
View meta_programming.io
#!/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")
View camping_email_in_perl5
#!/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.
View gist:487366
#!/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 Aug 20, 2010
Custom infix operators in perl5
View infix.pl
#!/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;
{