Subject: | inside-out data incapsulation question |
Date: | Sun, 25 May 2008 10:46:40 +0100 |
To: | bug-MooseX-InsideOut [...] rt.cpan.org |
From: | "Tim Rayner" <tfrayner [...] gmail.com> |
Hi,
Apologies if I've misunderstood your code, but are the objects created when
using this package strictly inside-out? It appears that the internal
attribute store is still based around a hashref of attributes (stored in a
class attribute hashref, but that's not the problem):
$__attr{refaddr $instance}->{$slot_name};
whereas (it is my understanding that) a typical inside-out class would
normally store attributes like this:
$__attr{$slot_name}->{refaddr $instance};
This would then encapsulate the data better, preventing subclasses from
interfering with the superclasses attributes. Below is a short code snippet
to illustrate the problem; this code prints out "test", indicating that the
superclass Foo attribute "bar" has been overwritten by the corresponding
subclass Baz attribute:
####################
package Foo;
use MooseX::InsideOut;
has "bar" => (is => "rw");
sub get_val {
my $self=shift;
return $self->bar;
}
package Baz;
use MooseX::InsideOut;
extends "Foo";
has "bar" => (is => "rw");
package main;
my $f=Baz->new(bar=>"test");
print $f->get_val;
#####################
Many thanks,
Tim