Subject: | Possible Bug using coerce |
Date: | Wed, 29 Apr 2009 16:49:41 -0300 |
To: | bug-Moose [...] rt.cpan.org |
From: | Rafael Adson Barbosa Barros <rafael.barros [...] mobimail.locaweb.com.br> |
Hello,
I don't know if this is a bug or if I'm understanding how to use it the
wrong way, but I made a test based on Moose::Cookbook Recipe 5 and it
did not pass on Moose 0.76
(it did pass on previous versions, though).
Here is the git patch I generated from my test.
From e04f02cb458754c52b10cabc376a23b8fd1e8389 Mon Sep 17 00:00:00 2001
From: rafael.barros <rafael.barros@locaweb.com.br>
Date: Wed, 29 Apr 2009 16:38:26 -0300
Subject: [PATCH] Reproduced in a test bug in version 0.76 where Coercion
does not work
with a type defined by me.
---
...24_coercion_fails_for_string_with_custom_type.t | 21
++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
create mode 100644
t/100_bugs/024_coercion_fails_for_string_with_custom_type.t
diff --git a/t/100_bugs/024_coercion_fails_for_string_with_custom_type.t
b/t/100_bugs/024_coercion_fails_for_string_with_custom_type.t
new file mode 100644
index 0000000..24cde93
--- /dev/null
+++ b/t/100_bugs/024_coercion_fails_for_string_with_custom_type.t
@@ -0,0 +1,21 @@
+## This test ensures that a string is coerced normally according to
what is told in the Moose::Cookbook
+## Apr 29 2009 -- Rafael Barros rafael.barros@locaweb.com.br
+package SomeGenericClassWithStringArgument;
+use Moose;
+use Params::Coerce ();
+use Moose::Util::TypeConstraints;
+
+subtype 'MyParamType' => as 'Str' => where { /^[\w_]*$/};
+
+coerce 'MyParamType' => from 'Str' => via { "\L$_" };
+
+has 'parameter' => ( isa => 'MyParamType', is => 'ro', required => 1,
coerce => 1 );
+
+
+package main;
+use Test::More tests => 1;
+
+my $obj = SomeGenericClassWithStringArgument->new( parameter => 'BLAH');
+is $obj->parameter, 'blah';
+
+1;
\ No newline at end of file
--
1.5.6.3
--
Rafael Barros
Engenheiro de Tecnologia
Locaweb
Eleita pela INFO Exame e pelo IDG Brasil
a melhor empresa em webhosting do paĆs.
Geral: +55 11 3544-0444