Skip to content

Instantly share code, notes, and snippets.

@lopnor
Created January 27, 2009 03:11
Show Gist options
  • Save lopnor/53141 to your computer and use it in GitHub Desktop.
Save lopnor/53141 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
package MyBase;
use Mouse;
has something => (
isa => 'Str',
is => 'ro',
default => 'foo',
);
has lazything => (
isa => 'Str',
is => 'ro',
required => 1,
lazy => 1,
default => sub {
return $_[0]->something;
},
);
package MyBase::Extended;
use Mouse;
extends 'MyBase';
has +something => (
default => 'bar',
);
has +lazything => (
default => sub {
return $_[0]->something . ' (wrapped)';
}
);
package main;
use strict;
use warnings;
use Test::More qw(no_plan);
my $obj = MyBase->new;
is $obj->lazything, 'foo';
my $obj2 = MyBase::Extended->new;
is $obj2->lazything, 'bar (wrapped)';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment