develooper Front page | perl.module-authors | Postings from November 2003

Re: Class::FakeAttributes -- Opinions Wanted

Thread Previous | Thread Next
A. Pagaltzis
November 3, 2003 09:06
Re: Class::FakeAttributes -- Opinions Wanted
Message ID:
* Orton, Yves <> [2003-11-03 17:27]:
> Thats because the apporach you are comparing it to is flawed.
>   foreach (@{$self->{foo}||[]}) { ... }                 
> is the correct way to spell that I think.

Actually, no. See below.

> > If the 'foo' attribute hasn't been set to anything, then you
> > want an empty list to iterate over.  With version C, that's
> > what you get.  
> No. If $self->{foo} is undef you get an error with version C.

You're forgetting autovivification. If $self->{foo} is undef it
is coerced into a appropriate reftype.

> Nah, just make the get_ autopopulate an undef attribute on
> fetch. That way its not done unless is actually being used by
> external code.

Yes, but what with? You can't know whether the attempt to access
an undef attribute is inside an array deref, a hash deref,
outside any deref contexts at all, or wherever. That's why I
proposed having a get_attr_with_default.

I did a quick test writing an lvalue sub; I was hoping that if
get_attribute was one, and used in a deref context, then Perl
would DWIM. Unfortunately, it does not.

> Personally I wouldnt have get_foo and set_foo. its too much
> like java or VB for me.


> Seems like you think its useful. Aristotle didnt tell you it
> was stupid.

Well, to be clear: I don't like the idea.

Because just as you said, having a good ::InsideOut would kill
*all* birds with one stone - what this module does and what
several others as well do (modules like the one that ties the
hash and prepends the package name on all accesses to a
traditional hashref $self - I can't remember what it's called).

On the other hand, we _don't_ have ::InsideOut so being
pragmatic, I'm saying that maybe it's not a bad idea to have this
in the meantime..

"If you can't laugh at yourself, you don't take life seriously enough."

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About