stevan / p5-mop-redux

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

Lazy redux #47

Closed perigrin closed 11 years ago

perigrin commented 11 years ago

Change the syntax for lazy attributes from:

has $foo is lazy(sub { ... });

to

has $foo is lazy = ${^SELF}->_foo();

or

has $foo is lazy => do { something; complicated; };

and add class Foo is lazy { } which makes all attributes lazy in a given class.

stevan commented 11 years ago

@perigrin I am not sure we want to add lazyiness predicates to the core attributes actually. I would prefer to add a generic has_trait mechanism to all things (classes, attributes, methods). And then let lazy just do it's thing.

perigrin commented 11 years ago

Yeah, I said I wasn't happy with that solution on IRC. My first idea was to apply a role to $meta that raised a Boolean flag of some kind but role applications to instances is still Moose levels of ugly and I didn't chase that down.

Adding a traits method would work, but mop::object will still end up having to explicitly check for the lazy trait unless we come up with a "do not initialize this attribute" flag that can be used generically by anything that wants the mop to skip initialization, or we make initialization more intelligent and overrideable. Both plans introduce performance and simplicity issues.

This was simply a way to start thinking about those things. — Sent from Mailbox for iPhone

On Mon, Jul 29, 2013 at 8:03 AM, Stevan Little notifications@github.com wrote:

@perigrin I am not sure we want to add lazyiness predicates to the core attributes actually. I would prefer to add a generic has_trait mechanism to all things (classes, attributes, methods). And then let lazy just do it's thing.

Reply to this email directly or view it on GitHub: https://github.com/stevan/p5-mop-redux/pull/47#issuecomment-21715185

stevan commented 11 years ago

Actually, my plan was to just remove the default value from the attribute, and then make the lazy event handler do the installation. Without a default value, the constructor will just ignore it.

perigrin commented 11 years ago

Hmm that could work, but the movers arrive in 20 minutes so it's outside of the time I have this morning.

I've added a generic trait mechanism to mop::attribute though.

doy commented 11 years ago

This was done in 1d61bea.