stevan / p5-mop-redux

A(nother) MOP for Perl 5
139 stars 36 forks source link

weaken attribute value #108

Closed yuki-kimoto closed 11 years ago

yuki-kimoto commented 11 years ago

This topic had been closed. I want to reopen this.

use Scalar::Util 'weaken';
weaken $self->{title};

I need alternative in mop.

doy commented 11 years ago

We already have an alternative:

has $!foo is weak_ref;
yuki-kimoto commented 11 years ago

No, "has $!foo is weak_ref;" is for class author. How can class user weak attribute?

stevan commented 11 years ago

That would be a violation of encapsulation and would not be recommended.

yuki-kimoto commented 11 years ago

But we should allow class user to weaken attribute? Is it bad not to provide the alternative way?

That would be a violation of encapsulation and would not be recommended.

I understand it is not good, but not providing the alternative way is more bad?

For example, There are Class P and Class Q. User is not author of these classes.

my $p = P->new;
my $q = Q->new;

$p->q($q);
$q->p($p);

This is cross-reference. In mop, Is there what way to resolve this case?

doy commented 11 years ago

If you're going to be doing something like that, the classes involved absolutely need to know about it (and probably manage it themselves). That said, the traits are all implemented using public APIs, so there is a way to do it, but again, you really, really shouldn't.

yuki-kimoto commented 11 years ago

My Question is that dose mop provide alternative way. If mop don't provide it, one thing become impossible.

I understand your opinion "you really should't". but above is real problem which can occur in Perl5.

In Perl5 design, is it good that programmer have restriction?