Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

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

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

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



Subject: Default attribute values break when inheriting from Pod::Parser
I haven't had time to debug this, but I do have a simple test case. Consider the following code: #!/usr/bin/env perl { package MyBase; sub foo { 1 } } { package One; use Moose; extends qw{MyBase Moose::Object}; has counter => ( is => 'rw', isa => 'Int', default => 1 ); sub inc_counter { my $self = shift; $self->counter( $self->counter + 1 ); } } my $one = One->new; $one->inc_counter; print $one->counter, $/; The prints '2', as expected. However, if the extends line is changed to inherit from Pod::Parser, we no longer have a default value: extends qw{Pod::Parser Moose::Object}; Running the code now produces this: Use of uninitialized value in addition (+) at inherit.pl line 19. 1 I've worked around this by providing a BUILD method which sets the defaults, but I'm curious to know if I've done something wrong or if this is a bug in Moose (if it's not a bug, it's definitely counter-intuitive). Cheers, Ovid
This is because Pod::Parser has a new() method, so that's taking precedence over Moose::Object's new (since you listed it first in the extends line). See Moose::Cookbook::Basics::Recipe11 for a discussion of the issues involved, but really, you should just be using MooseX::NonMoose. Moose::Manual::FAQ also touches on this issue.