Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 77357
Status: open
Priority: 0/
Queue: Moose

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

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



Subject: Attribute named "new" breaks weirdly
package Change; use Moose; has old => (is => 'ro'); has new => (is => 'ro'); package main; my $change = Change->new( old => 'Dave', new => 'Stevan', ); print $change->old . ' -> ' . $change->new; The error you get is in the call to Change->new, which is the accessor you declared. Should we warn about accessors named "new"?
On Tue May 22 06:22:39 2012, SARTAK wrote: Show quoted text
> package Change; > use Moose; > > has old => (is => 'ro'); > has new => (is => 'ro'); > > package main; > my $change = Change->new( > old => 'Dave', > new => 'Stevan', > ); > > print $change->old . ' -> ' . $change->new; > > > The error you get is in the call to Change->new, which is the accessor > you declared. > > Should we warn about accessors named "new"?
In theory you can change what the constructor is named. This is easily done by passing an argument to make_immutable, although for non- immutable classes you'd have to write a shim that called SUPER::new or something bizarre like that. That all said, the most common case is that the constructor is called "new". So maybe we should warn by default but provide some way to suppress the warning for people who really really want an attribute named new?
We tried to replicate this issue with a file containing: --- package Change; use Moose; has old => (is => 'ro'); has new => (is => 'ro'); package main; my $change = Change->new( old => 'Dave', new => 'Stevan', ); print $change->old . ' -> ' . $change->new; --- This generates the following error: Cannot assign a value to a read-only accessor at reader Change::new (defined at Change.pl line 5) line 3 Change::new('Change', 'old', 'Dave', 'new', 'Stevan') called at Change.pl line 9 --- So does this suggest that this issue can be closed?
On 2017-11-22 13:33:12, LANCEW wrote: Show quoted text
> We tried to replicate this issue with a file containing: > > --- > > package Change; > use Moose; > > has old => (is => 'ro'); > has new => (is => 'ro'); > > package main; > > my $change = Change->new( old => 'Dave', new => 'Stevan', ); > > print $change->old . ' -> ' . $change->new; > > --- > > This generates the following error: > > Cannot assign a value to a read-only accessor at reader Change::new > (defined at Change.pl line 5) line 3 > Change::new('Change', 'old', 'Dave', 'new', 'Stevan') called > at Change.pl line 9 > > --- > > So does this suggest that this issue can be closed?
No, this is the same issue, I think. The attribute accessor has overridden the constructor so now this class effectively has no constructor.