Hello Monks,

I don't now how many of you have used MooseX-InsideOut but I was playing around with it the other day and discovered something odd. When you sub-class a standard Moose class with MooseX-InsideOut, unless you redefine the attributes in the child class, you cannot assign to them at object creation.

For example:

#!/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

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 =)

Smoothie, smoothie, hundre prosent naturlig!

In reply to Attributes in MooseX-InsideOut sub class not initiated on object creation by j1n3l0

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.