From: Stevan Little Date: Sun, 19 Mar 2006 20:40:52 +0000 (+0000) Subject: better names for coercion, mst++ X-Git-Tag: 0_05~84 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d6e2d9a1148034e73825e85a8a66dc63dda9c6b4;p=gitmo%2FMoose.git better names for coercion, mst++ --- diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index a4a02f4..362ad54 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -15,7 +15,7 @@ sub import { my $pkg = shift || caller(); return if $pkg eq ':no_export'; no strict 'refs'; - foreach my $export (qw(type subtype as where to coerce)) { + foreach my $export (qw(type subtype as where coerce from via)) { *{"${pkg}::${export}"} = \&{"${export}"}; } } @@ -120,8 +120,9 @@ sub coerce ($@) { } sub as ($) { $_[0] } +sub from ($) { $_[0] } sub where (&) { $_[0] } -sub to (&) { $_[0] } +sub via (&) { $_[0] } # define some basic types @@ -168,8 +169,8 @@ Moose::Util::TypeConstraints - Type constraint system for Moose => where { $_ < 10 }; coerce Num - => as Str - => to { 0+$_ }; + => from Str + => via { 0+$_ }; =head1 DESCRIPTION @@ -230,7 +231,9 @@ Suggestions for improvement are welcome. =item B -=item B +=item B + +=item B =back diff --git a/t/005_basic.t b/t/005_basic.t index 8ffb6b8..19958a2 100644 --- a/t/005_basic.t +++ b/t/005_basic.t @@ -19,10 +19,10 @@ BEGIN { use Moose; coerce 'HTTPHeader' - => as ArrayRef - => to { HTTPHeader->new(array => $_[0]) } - => as HashRef - => to { HTTPHeader->new(hash => $_[0]) }; + => from ArrayRef + => via { HTTPHeader->new(array => $_[0]) } + => from HashRef + => via { HTTPHeader->new(hash => $_[0]) }; has 'array' => (is => 'ro'); has 'hash' => (is => 'ro'); diff --git a/t/054_util_type_coercion.t b/t/054_util_type_coercion.t index a981b10..83bd546 100644 --- a/t/054_util_type_coercion.t +++ b/t/054_util_type_coercion.t @@ -25,10 +25,10 @@ subtype Header => => where { $_->isa('HTTPHeader') }; coerce Header - => as ArrayRef - => to { HTTPHeader->new(array => $_[0]) } - => as HashRef - => to { HTTPHeader->new(hash => $_[0]) }; + => from ArrayRef + => via { HTTPHeader->new(array => $_[0]) } + => from HashRef + => via { HTTPHeader->new(hash => $_[0]) }; Moose::Util::TypeConstraints::export_type_contstraints_as_functions();