Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 45570
Status: resolved
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: rafael.barros [...] mobimail.locaweb.com.br
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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
I second on this bug. I have a program, which used coerce, that worked on 0.74 but failed on 0.79. The test script (with 'use Params::Coerce ();' removed since I don't have that module installed) by rafael works on my 0.74 env, but failed on 0.79 env. Please help to fix this problem! plasma On Wed Apr 29 15:50:14 2009, rafael.barros@mobimail.locaweb.com.br wrote: Show quoted text
> 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
On Tue May 19 05:30:02 2009, https://me.yahoo.com/a/x9YprNRns5GxyoKSjBFTsdlktbyUIQ--#3ae44 wrote: Show quoted text
> I second on this bug. I have a program, which used coerce, that worked > on 0.74 but failed on 0.79. The test script (with 'use Params::Coerce > ();' removed since I don't have that module installed) by rafael works > on my 0.74 env, but failed on 0.79 env. Please help to fix this problem!
It's the old behavior that was buggy. If a given value passes a type constraint, it should not be coerced. In the original example, the type constraint allows any string, so "BLAH" satisfies the type constraint. Trying to coerce a valid value doesn't make any sense.