On Wed Dec 11 19:03:29 2013, MSTROUT wrote:
Show quoted text> On Wed Dec 11 11:53:38 2013, DJERIUS wrote:
> > Unfortunately, this is the output:
>
> Yes, because overloading %{} on a hashref-based object is obviously
> broken.
But it seems possible to fix that, if that were so desired. How about this?
sub new {
my ( $class, %args ) = @_;
return bless \{%args}, $class;
}
This retains the hash nature of the object, but hides it from the overloading magic. The attribute accessors would obviously have to be changed to handle an extra layer of indirection, but that would be transparent to the end user. All other method calls should work the same.
Show quoted text>
> > If I comment out the overload line, I get
> >
> > % perl hash.pl
> > $VAR1 = {
> > 'tea' => 'Gunpowder'
> > };
> >
> >
> > which is the expected result, but isn't really production code
> > worthy,
> > as I have to assume something about the object's underlying storage
> > mechanism.
>
> No, you don't. The problem here is you *are* making assumptions about
> the implementation.
Unfortunately, it seems no one is intepreting the sentence I wrote in the way that I meant it, and it is leading to many assumptions. Since it really has little bearing on the actual subject of this discussion, I'd suggest we just ignore it and move on.
Show quoted text> The object's API can include "%{} does the right thing" . This is
> fine. External code should *not* need to know that overloading is
> being used to provide that API - as such, the version without
> overloading is *correct*.
I don't think that such a statement would be valid. Since Moo doesn't document its implementation, the result of applying %{} to a Moo based object is technically undefined, and so no guarantees may be made about it. While I may know that Moo is hash based, I can't in good faith use that knowledge if it isn't part of its published API. (I can't find any mention of that in the Moo documentation; perhaps I missed it).
Show quoted text> There is no bug in Moo here, merely a misunderstanding of
> encapsulation on your part.
I misunderstand many, many things in life.