Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 47350
Status: resolved
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: rt.cpan [...] sartak.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Warn or confess about overriding a local method with an accessor
Hi gang, When I was giving the Moose course, this came up somehow: package Point; use Moose; has x => (is => 'ro'); sub x { } The "x" accessor silently redefined Point->x which kind of sucks. We should have the same error as we do in Moose for delegate methods overriding a local method. I have a Class-MOP patch (attached) for this, and we have todo tests in Moose. Unfortunately, the Class-MOP bootstrap process does this all over the place. I'm not sure how to fix this, other than something idiotic like this in all of the primary Class-MOP packages: sub is_bootstrapper { (blessed(shift) || shift) eq __PACKAGE__ } Ideas? Shawn
Subject: accessor-override.diff
diff --git a/lib/Class/MOP/Attribute.pm b/lib/Class/MOP/Attribute.pm index 9c9f3f7..eef23d1 100644 --- a/lib/Class/MOP/Attribute.pm +++ b/lib/Class/MOP/Attribute.pm @@ -356,6 +356,11 @@ sub _process_accessors { (ref($accessor) eq 'HASH') || confess "bad accessor/reader/writer/predicate/clearer format, must be a HASH ref"; my ($name, $method) = %{$accessor}; + + if ($self->associated_class->has_method($name)) { + confess "You cannot overwrite a locally defined method ($name) with an accessor"; + } + $method = $self->accessor_metaclass->wrap( $method, package_name => $self->associated_class->name, @@ -366,6 +371,10 @@ sub _process_accessors { return ($name, $method); } else { + if ($self->associated_class->has_method($accessor)) { + confess "You cannot overwrite a locally defined method ($accessor) with an accessor"; + } + my $inline_me = ($generate_as_inline_methods && $self->associated_class->instance_metaclass->is_inlinable); my $method; eval {
Subject: Re: [rt.cpan.org #47350] Warn or confess about overriding a local method with an accessor
Date: Thu, 25 Jun 2009 15:16:07 -0500 (CDT)
To: Shawn M Moore via RT <bug-Moose [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Thu, 25 Jun 2009, Shawn M Moore via RT wrote: Show quoted text
> I have a Class-MOP patch (attached) for this, and we have todo tests in > Moose. Unfortunately, the Class-MOP bootstrap process does this all over > the place. I'm not sure how to fix this, other than something idiotic > like this in all of the primary Class-MOP packages: > > sub is_bootstrapper { (blessed(shift) || shift) eq __PACKAGE__ }
I was thinking of adding something like this anyway to allow for some optimizations of the bootstrap, after having to remove the "add_method" cache I added earlier for that purpose. But I was thinking of just doing: local $Class::MOP::_IS_BOOTSTRAPPING = 1 or something just to make it simple and faster. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/
doy took care of this.