j1n3l0 has asked for the wisdom of the Perl Monks concerning the following question:
As you can imagine, it would be really annoying to have to go through each attribute and modify them just so they work! (This does not seem to be a problem when sub-classing a standard perl hash-based class) Is this desired behaviour? Is there some flag I'm missing somewhere (init_arg or the like...)? Could this be a bug? I'm just curious here =)#!/usr/bin/env perl { package Normal::Moose::Class; use Moose; has 'name' => ( is => 'rw', default => __PACKAGE__, ); no Moose; 1; } { package Repeat::Attr::No; use MooseX::InsideOut; extends 'Normal::Moose::Class'; no MooseX::InsideOut; 1; } { package Repeat::Attr::Yes; use MooseX::InsideOut; extends 'Normal::Moose::Class'; has '+name' => ( default => __PACKAGE__, ); no MooseX::InsideOut; 1; } { package main; use 5.010_000; use strict; use warnings; use Test::More 'no_plan'; # Test a standard Moose class my $norm_moose = Normal::Moose::Class->new( name => 'normal-moose- +class' ); is( $norm_moose->name, 'normal-moose-class', 'normal-moose-class h +as the correct name' ); # Test the sub class with unmodified attribute my $io_moose = Repeat::Attr::No->new( name => 'repeat-attr-no' ); is( $io_moose->name, undef, 'insideout subclass does not assign to + attribute name on creation' ); $io_moose->name('repeat-attr-no'); is( $io_moose->name, 'repeat-attr-no', 'but will at any other time +' ); # Test the sub class with modified attribute my $child = Repeat::Attr::Yes->new( name => 'repeat-attr-yes' ); is( $child->name, 'repeat-attr-yes', 'unless you modify the attrib +ute in the class declaration' ); exit 0; } __END__ ok 1 - normal-moose-class has the correct name ok 2 - insideout subclass does not assign to attribute name on creatio +n ok 3 - but will at any other time ok 4 - unless you modify the attribute in the class declaration 1..4
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Attributes in MooseX-InsideOut sub class not initiated on object creation
by stvn (Monsignor) on Jul 16, 2008 at 15:59 UTC | |
by j1n3l0 (Friar) on Jul 16, 2008 at 17:40 UTC |