From: Guillermo Roditi Date: Fri, 18 May 2007 16:07:03 +0000 (+0000) Subject: reader presedence bug and tests X-Git-Tag: 0_22~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=df492bba76f271734723bf05db630508c8e5c0d7;p=gitmo%2FMoose.git reader presedence bug and tests --- diff --git a/Changes b/Changes index 219c2ee..478dbbe 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,7 @@ Revision history for Perl extension Moose - coerce and lazy now work together correctly, thanks to merlyn for finding this bug - tests added for this + - fix reader presedence bug in Moose::Meta::Attribute + tests 0.21 Thursday, May 2nd, 2007 * Moose diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 491eed5..47587a6 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -93,7 +93,7 @@ sub _process_options { if (exists $options->{is}) { if ($options->{is} eq 'ro') { - $options->{reader} = $name; + $options->{reader} ||= $name; (!exists $options->{trigger}) || confess "Cannot have a trigger on a read-only attribute"; } diff --git a/t/109_reader_precedence_bug.t b/t/109_reader_precedence_bug.t new file mode 100644 index 0000000..b4c18cc --- /dev/null +++ b/t/109_reader_precedence_bug.t @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Moose; + +use Test::More tests => 3; + +{ + package Foo; + use Moose; + has 'foo' => ( is => 'ro', reader => 'get_foo' ); +} + +{ + my $foo = Foo->new(foo => 10); + my $reader = $foo->meta->get_attribute('foo')->reader; + is($reader, 'get_foo', + 'reader => "get_foo" has correct presedence'); + can_ok($foo, 'get_foo'); + is($foo->$reader, 10, "Reader works as expected"); +} + + + +