[Moose-commits] r7188 - in
MooseX-Emulate-Class-Accessor-Fast/trunk: .
lib/MooseX/Emulate/Class/Accessor t
groditi at code2.0beta.co.uk
groditi at code2.0beta.co.uk
Mon Dec 29 17:17:09 GMT 2008
Author: groditi
Date: 2008-12-29 09:17:08 -0800 (Mon, 29 Dec 2008)
New Revision: 7188
Added:
MooseX-Emulate-Class-Accessor-Fast/trunk/t/recreated_accessors.t
Modified:
MooseX-Emulate-Class-Accessor-Fast/trunk/Changes
MooseX-Emulate-Class-Accessor-Fast/trunk/lib/MooseX/Emulate/Class/Accessor/Fast.pm
Log:
fix recreated accessor bug
Modified: MooseX-Emulate-Class-Accessor-Fast/trunk/Changes
===================================================================
--- MooseX-Emulate-Class-Accessor-Fast/trunk/Changes 2008-12-29 16:45:18 UTC (rev 7187)
+++ MooseX-Emulate-Class-Accessor-Fast/trunk/Changes 2008-12-29 17:17:08 UTC (rev 7188)
@@ -1,3 +1,7 @@
+0.00700
+ - Creating a new accessor with the same name as an old one would result in
+ a new attribute with no reader/writer/accessor. Reported by t0m
+ - tests (t0m)
0.00600 Dec 17, 2008
- Add test for a 'meta' accessor, which we need to treat as a
special case (t0m)
Modified: MooseX-Emulate-Class-Accessor-Fast/trunk/lib/MooseX/Emulate/Class/Accessor/Fast.pm
===================================================================
--- MooseX-Emulate-Class-Accessor-Fast/trunk/lib/MooseX/Emulate/Class/Accessor/Fast.pm 2008-12-29 16:45:18 UTC (rev 7187)
+++ MooseX-Emulate-Class-Accessor-Fast/trunk/lib/MooseX/Emulate/Class/Accessor/Fast.pm 2008-12-29 17:17:08 UTC (rev 7188)
@@ -103,6 +103,8 @@
my $self = shift;
my $meta = $locate_metaclass->($self);
for my $attr_name (@_){
+ $meta->remove_attribute($attr_name)
+ if $meta->find_attribute_by_name($attr_name);
my $reader = $self->accessor_name_for($attr_name);
my $writer = $self->mutator_name_for( $attr_name);
@@ -134,6 +136,8 @@
my $self = shift;
my $meta = $locate_metaclass->($self);
for my $attr_name (@_){
+ $meta->remove_attribute($attr_name)
+ if $meta->find_attribute_by_name($attr_name);
my $reader = $self->accessor_name_for($attr_name);
my @opts = ($meta->has_method($reader) ? () : (reader => $reader) );
my $attr = $meta->add_attribute($attr_name, @opts);
@@ -155,6 +159,8 @@
my $self = shift;
my $meta = $locate_metaclass->($self);
for my $attr_name (@_){
+ $meta->remove_attribute($attr_name)
+ if $meta->find_attribute_by_name($attr_name);
my $writer = $self->mutator_name_for($attr_name);
my @opts = ($meta->has_method($writer) ? () : (writer => $writer) );
my $attr = $meta->add_attribute($attr_name, @opts);
Added: MooseX-Emulate-Class-Accessor-Fast/trunk/t/recreated_accessors.t
===================================================================
--- MooseX-Emulate-Class-Accessor-Fast/trunk/t/recreated_accessors.t (rev 0)
+++ MooseX-Emulate-Class-Accessor-Fast/trunk/t/recreated_accessors.t 2008-12-29 17:17:08 UTC (rev 7188)
@@ -0,0 +1,32 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+use Test::More tests => 4;
+use Test::Exception;
+
+# 1
+use_ok('MooseX::Emulate::Class::Accessor::Fast');
+{
+ package My::Test::Package;
+ use Moose;
+ with 'MooseX::Emulate::Class::Accessor::Fast';
+ for (0..1) {
+ __PACKAGE__->mk_accessors(qw( foo ));
+ __PACKAGE__->mk_ro_accessors(qw( bar ));
+ __PACKAGE__->mk_wo_accessors(qw( baz ));
+ }
+}
+
+my $i = My::Test::Package->new(bar => 'bar');
+
+# 2
+lives_ok {
+ $i->foo('foo');
+ $i->baz('baz');
+
+ # 3-4
+ is($i->foo, 'foo');
+ is($i->bar, 'bar');
+} 'No exception';
+
More information about the Moose-commits
mailing list