Revision history for Perl extension Moose
+0.22
+ * Moose::Meta::Method::Accessor
+ - coerce and lazy now work together correctly, thanks to
+ merlyn for finding this bug
+ - tests added for this
+
0.21 Thursday, May 2nd, 2007
* Moose
- added SUPER_SLOT and INNER_SLOT class hashes to support unimport
t/070_more_attr_delegation.t
t/071_misc_attribute_tests.t
t/072_attr_dereference_test.t
+t/073_misc_attribute_coerce_lazy.t
t/100_subtype_quote_bug.t
t/101_subtype_conflict_bug.t
t/102_Moose_Object_error.t
-Moose version 0.21
+Moose version 0.22
===========================
See the individual module documentation for more information
use strict;
use warnings;
-our $VERSION = '0.21';
+our $VERSION = '0.22';
our $AUTHORITY = 'cpan:STEVAN';
use Scalar::Util 'blessed', 'reftype';
if (!defined $val && $self->has_default) {
$val = $self->default($instance);
}
+
if (defined $val) {
if ($self->has_type_constraint) {
my $type_constraint = $self->type_constraint;
use Carp 'confess';
-our $VERSION = '0.03';
+our $VERSION = '0.04';
our $AUTHORITY = 'cpan:STEVAN';
use base 'Moose::Meta::Method',
return 'unless (exists $_[0]->{$attr_name}) {' .
' if ($attr->has_default) {' .
' my $default = $attr->default($_[0]);' .
+ ($attr->should_coerce
+ ? '$default = $attr->type_constraint->coerce($default);'
+ : '') .
' (defined($type_constraint->($default)))' .
' || confess "Attribute (" . $attr->name . ") does not pass the type constraint ("' .
' . $attr->type_constraint->name . ") with " . (defined($default) ? "\'$default\'" : "undef")' .
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+use Test::Exception;
+
+BEGIN {
+ use_ok('Moose');
+}
+
+{
+ package HTTPHeader;
+ use Moose;
+
+ has 'array' => (is => 'ro');
+ has 'hash' => (is => 'ro');
+}
+
+{
+ package Request;
+ use Moose;
+ use Moose::Util::TypeConstraints;
+
+ subtype Header =>
+ => as Object
+ => where { $_->isa('HTTPHeader') };
+
+ coerce Header
+ => from ArrayRef
+ => via { HTTPHeader->new(array => $_[0]) }
+ => from HashRef
+ => via { HTTPHeader->new(hash => $_[0]) };
+
+ has 'headers' => (
+ is => 'rw',
+ isa => 'Header',
+ coerce => 1,
+ lazy => 1,
+ default => sub { [ 'content-type', 'text/html' ] }
+ );
+}
+
+my $r = Request->new;
+isa_ok($r, 'Request');
+
+lives_ok {
+ $r->headers;
+} '... this coerces and passes the type constraint even with lazy';
+
+
+