Skip to content

Instantly share code, notes, and snippets.

@0branch
0branch / gcheck.lua
Created August 27, 2011 16:07
check what's being exported into the global table by a given module
#!/usr/bin/env lua
--------------------------------------------------------------------------------
-- _ _
-- __ _ ___| |__ ___ ___| | __
-- / _` |/ __| '_ \ / _ \/ __| |/ /
-- | (_| | (__| | | | __/ (__| <
-- \__, |\___|_| |_|\___|\___|_|\_\
-- |___/
--
-- Check what's being exported into the global table by a given module.
@0branch
0branch / mismatch.pl
Created April 2, 2011 17:24
Example of type mismatching for Str in Moose
#!/usr/bin/env perl
use strict;
use warnings;
use Object;
my $foo = Object->new(name => "lamp");
my $bar = Object->new(name => {});
@0branch
0branch / object-constraint.pl
Created April 2, 2011 17:14
moose definition of Object type constraint
subtype 'Object' => as 'Ref' =>
where { blessed($_) && blessed($_) ne 'Regexp' } =>
optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Object;
@0branch
0branch / entity.pl
Created April 2, 2011 17:03
entity.pl, third draft
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
use Entity;
use Player;
my $lamp = Entity->new(name => "lamp");
@0branch
0branch / entity.pl
Created April 2, 2011 17:03
entity.pl, second draft
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
use Entity;
use Player;
my $lamp = Entity->new(name => "lamp");
@0branch
0branch / Player.pm
Created April 2, 2011 17:02
Player.pm, third draft.
package Player;
use Moose;
has 'inventory' => (
handles => { obtain => 'push' },
isa => 'ArrayRef[Entity]',
default => sub { [] },
traits => ['Array'],
is => 'ro',
);
@0branch
0branch / Entity.pm
Created April 2, 2011 17:02
Entity.pm (redraft of Object.pm)
package Entity;
use Moose;
has 'name' => (
isa => 'Str',
is => 'rw',
required => 1,
);
has 'description' => (
@0branch
0branch / Player.pm
Created April 2, 2011 17:01
Player.pm, second draft.
package Player;
use Moose;
has 'inventory' => (
handles => { obtain => 'push' },
isa => 'ArrayRef[Object]',
default => sub { [] },
traits => ['Array'],
is => 'ro',
);
@0branch
0branch / entry.pl
Created April 2, 2011 17:01
entry.pl, first draft
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
use Object;
use Player;
my $lamp = Object->new(name => "lamp");
@0branch
0branch / Player.pm
Created April 2, 2011 17:00
Player.pm, first draft.
package Player;
use Moose;
has 'inventory' => (
default => sub { [] },
is => 'ro',
);
sub list_inventory {
my $self = shift;