Skip Menu |

This queue is for tickets about the MooseX-Constructor-AllErrors CPAN distribution.

Report information
The Basics
Id: 52294
Status: resolved
Priority: 0/
Queue: MooseX-Constructor-AllErrors

People
Owner: Nobody in particular
Requestors: schwiege [...] gmx.net
Cc:
AdminCc:

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



type coercion does not work well together with AllErrors...
Subject: 03_type_coercion.t
use strict; use warnings; use Test::More; use Test::Exception; { use Moose::Util::TypeConstraints; use MooseX::Types::Moose qw/:all/; use MooseX::Types::DateTimeX qw/ DateTime /; subtype 'Date', as 'DateTime'; coerce 'Date', from 'HashRef', via { DateTime::->new( $_ ); }; no Moose::Util::TypeConstraints; } { package Foo; use Moose; has date => ( is => 'ro', isa => 'Date', coerce => 1, ); Foo->meta->make_immutable; } { package Bar; use Moose; use MooseX::Constructor::AllErrors; has date => ( is => 'ro', isa => 'Date', coerce => 1, ); Bar->meta->make_immutable; } use DateTime; lives_ok{ Foo->new( date => { year => 2005, month => 2, day => 4, hour => 12, minute => 20, second => 50, }) } 'Instance of Test Class with coercion w/o AllErrors lives'; lives_ok{ Bar->new( date => { year => 2005, month => 2, day => 4, hour => 12, minute => 20, second => 50, }) } 'Instance of Test Class with coercion with AllErrors lives'; my $e = $@; explain "$e" if $e ; done_testing;
Subject: Re: [rt.cpan.org #52294] AutoReply:
Date: Wed, 02 Dec 2009 01:21:43 +0100
To: bug-MooseX-Constructor-AllErrors [...] rt.cpan.org
From: schwiege <schwiege [...] gmx.net>
the problem seems to be that the values are only checked, but not coerced (if possible). my suggestion for a solution (after which my test passes): in MooseX::Constructor::AllErrors::Error, line 40: next if $attr->type_constraint->check( $attr->type_constraint->coerce( $args->{$init_arg}) ); and in MooseX::Constructor::AllErrors::Role::Meta::Method::Constructor, line 49: next if Moose::Util::TypeConstraints::find_type_constraint(\$tc_attrs{\$tc_attr})->check( Moose::Util::TypeConstraints::find_type_constraint(\$tc_attrs{\$tc_attr})->coerce( \$params->{\$tc_attr} ) ); ( or some nicer looking code ;) ). Thank you!
seems better to check whether there IS a coercion before attempting to coerce ;) so here is my revised bugfix suggestion... thus: MooseX::Constructor::AllErrors::Role::Meta::Method::Constructor my $tc = Moose::Util::TypeConstraints::find_type_constraint(\$tc_attrs{\$tc_attr}); next if $tc->check( \$params->{\$tc_attr} ); next if $tc->has_coercion && $tc->check( $tc->coerce( \$params->{\$tc_attr} ) ); and in package MooseX::Constructor::AllErrors::Role::Object line 40: next if $attr->type_constraint->has_coercion && $attr->type_constraint ->check( $attr->type_constraint->coerce( $args->{$init_arg}) );
This should be fixed in version 0.008.