Subject: | Incorrect handling of nonword characters in attribute names |
Date: | Fri, 14 Aug 2009 13:11:44 -0700 |
To: | bug-Moose [...] rt.cpan.org |
From: | dtreder <dtreder [...] imdb.com> |
For attributes that contain the character '@', Moose has at least two
problems: before the class is made immutable, the default is correctly
set but the accessors are generated incorrectly (looking for '\@'
instead). Then, after the class is made immutable, the accessor appears
to be working correctly, but the default is stored in the hash under the
incorrect key (the @ is preceded by two backslashes).
Here is a test - on Moose-0.88, the test_foo_class sub fails different
tests before and after make_immutable. I would expect all tests to
succeed in both cases. I tested Moose-0.55 and all tests succeed in
this script on that distribution.
#!/usr/bin/perl
use Test::More 'no_plan';
package Foo;
use Moose;
has '@type' => ( required => 0, reader => 'get_at_type', default => 1 );
has 'type' => ( required => 0, reader => 'get_type', default => 2 );
no Moose;
package main;
sub test_foo_class {
my $foo = Foo->new;
isa_ok($foo, 'Foo');
can_ok($foo, 'get_at_type', 'get_type');
ok(exists $foo->{'@type'}, 'has @type key in hash');
ok(exists $foo->{'type'}, 'has @type key in hash');
is($foo->get_at_type, 1, 'accessor works');
is($foo->get_type, 2, 'accessor works');
diag $foo->dump;
}
diag "Foo class is not immutable";
test_foo_class();
diag "Make Foo immutable";
Foo->meta->make_immutable;
test_foo_class();