From: Dave Rolsky Date: Thu, 30 Sep 2010 15:28:17 +0000 (-0500) Subject: Revise Unsweetened X-Git-Tag: 1.15~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=609daa48920190a15c7c61f43659b53cff53edfa;p=gitmo%2FMoose.git Revise Unsweetened --- diff --git a/lib/Moose/Manual/Unsweetened.pod b/lib/Moose/Manual/Unsweetened.pod index 6d79f1a..3a4a7d8 100644 --- a/lib/Moose/Manual/Unsweetened.pod +++ b/lib/Moose/Manual/Unsweetened.pod @@ -47,10 +47,7 @@ First, we define two very small classes the Moose way. handles => { birth_year => 'year' }, ); - subtype 'ShirtSize' - => as 'Str' - => where { /^(?:s|m|l|xl|xxl)$/i } - => message { "$_ is not a valid shirt size (s, m, l, xl, xxl)" }; + enum 'ShirtSize' => qw( s m l xl xxl ); has shirt_size => ( is => 'rw', @@ -58,9 +55,9 @@ First, we define two very small classes the Moose way. default => 'l', ); -This is a fairly simple class with three attributes. We also define a -type to validate t-shirt sizes because we don't want to end up with -something like "blue" for the shirt size! +This is a fairly simple class with three attributes. We also define an enum +type to validate t-shirt sizes because we don't want to end up with something +like "blue" for the shirt size! package User; @@ -96,7 +93,6 @@ helpers like C. use DateTime; use DateTime::Format::Natural; - sub new { my $class = shift; my %p = ref $_[0] ? %{ $_[0] } : @_; @@ -166,7 +162,9 @@ helpers like C. defined $shirt_size or confess 'shirt_size cannot be undef'; - $shirt_size =~ /^(?:s|m|l|xl|xxl)$/ + my %sizes = map { $_ => 1 } qw( s m l xl xxl ); + + $sizes{$shirt_size} or confess "$shirt_size is not a valid shirt size (s, m, l, xl, xxl)"; } @@ -244,7 +242,6 @@ Now let's see User: use base 'Person'; - sub new { my $class = shift; my %p = ref $_[0] ? %{ $_[0] } : @_;