Skip to content

Instantly share code, notes, and snippets.

@rsrchboy
Created November 19, 2012 20:09
Show Gist options
  • Save rsrchboy/4113553 to your computer and use it in GitHub Desktop.
Save rsrchboy/4113553 to your computer and use it in GitHub Desktop.
on-the-fly subtyping
use MooseX::AttributeShortcuts;
use MooseX::CoercePerAttribute;
use MooseX::AlwaysCoerce;
# create an attribute where value must be a subtype of Str that ends in '.',
# and can be coerced from a non-conformant Str by adding a '.'
has foo => (
is => 'ro',
isa => 'Str',
constraint => sub { /\.$/ },
coerce => {
Str => sub { "$_." },
},
builder => sub { 'some string' },
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment