Skip to content

Instantly share code, notes, and snippets.

@EvanCarroll
Created June 15, 2009 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save EvanCarroll/130258 to your computer and use it in GitHub Desktop.
Save EvanCarroll/130258 to your computer and use it in GitHub Desktop.
package Class;
use Moose;
use Moose::Util::TypeConstraints;
## Whatever, you get the idea.
sub trim_whitespace { my $str = shift; $str =~ s/^\s+|\s+$//; $str };
sub boolify { my $str = shift; $str =~ /^y/i ? 1 : $str };
## Guess i need to say an OLBool is just a regular bool that coerces, stringifies, and removes padding... JOYZER. Shouldn't the where be at the very least, inherited it is a subtype.
subtype 'OLBool' => as 'Bool' => where { /1|0/ };
coerce 'OLBool'
=> from 'Str' => via { boolify( trim_whitespace($_) ) }
;
has 'foo' => ( isa => 'OLBool', is => 'rw' );
my $c = Class->new;
printf ( "Should get %s\n", boolify(trim_whitespace('y')) );
$c->foo( 'y' ); ## EXCPETION
die $c->foo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment