-
-
Save hdp/130282 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | |
coerce => 1, # HTH | |
); | |
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