+0.04 2008-04-18
+
+- This module did not respcet the init_arg attribute setting, and used
+ the attribute name instead. Reported by Matt Trout. RT #34507.
+
+
0.03 2007-11-20
- Require Moose 0.26, since that's first version to offer init_meta(),
my $self = shift;
my $params = shift;
- my %attrs = map { $_->name() => 1 } $self->meta()->compute_all_applicable_attributes();
+ my %attrs =
+ ( map { $_ => 1 }
+ grep { defined }
+ map { $_->init_arg() }
+ $self->meta()->compute_all_applicable_attributes()
+ );
my @bad = sort grep { ! $attrs{$_} } keys %{ $params };
if (@bad)
{
- confess "Found unknown attribute(s) passed to the constructor: @bad";
+ confess "Found unknown attribute(s) init_arg passed to the constructor: @bad";
}
return;
use strict;
use warnings;
-our $VERSION = '0.03';
+our $VERSION = '0.04';
use Moose;
use MooseX::Object::StrictConstructor;
Using this class to load Moose instead of just loading using Moose
itself makes your constructors "strict". If your constructor is called
-with an attribute that your class does not declare, then it calls
-"Carp::confess()". This is a great way to catch small typos.
+with an attribute init argument that your class does not declare, then
+it calls "Carp::confess()". This is a great way to catch small typos.
=head2 Subverting Strictness
use strict;
use warnings;
-use Test::More tests => 9;
+use Test::More tests => 12;
{
}
{
+ package InitArg;
+
+ use MooseX::StrictConstructor;
+
+ has 'thing' => ( is => 'rw', 'init_arg' => 'other' );
+ has 'size' => ( is => 'rw', 'init_arg' => undef );
+}
+
+{
package Immutable;
use MooseX::StrictConstructor;
eval { ImmutableTricky->new( thing => 1, agent => 99 ) };
like( $@, qr/unknown attribute.+: agent/,
'ImmutableTricky still blows up on unknown params other than spy' );
+
+eval { InitArg->new( thing => 1 ) };
+like( $@, qr/unknown attribute.+: thing/,
+ 'InitArg blows up with attribute name' );
+
+eval { InitArg->new( size => 1 ) };
+like( $@, qr/unknown attribute.+: size/,
+ 'InitArg blows up when given attribute with undef init_arg' );
+
+eval { InitArg->new( other => 1 ) };
+is( $@, '',
+ 'InitArg works when given proper init_arg' );