Re: Roles, Classes and silent overriding

2009-04-15 Thread Hans Dieter Pearcey
On Tue, Apr 14, 2009 at 02:41:44PM -0400, Stevan Little wrote:
 around() (without calling the next method) would also work.

 That won't be detectable at composition time though.

Well, if you didn't have the method, it would fail at around() time, so it
would work in the sense that it would let you explicitly override a method
from a role.

Am I missing something?

hdp.


Re: Applying a role to an object instance

2009-04-15 Thread Chris Prather
On Tue, Apr 14, 2009 at 6:10 PM, Rolf Schaufelberger r...@plusw.de wrote:
 How can I call some initialisation code in role applied to an already
 existing object ?

 Normally I use   after 'BUILD' for this.

 When I call

  MyApp::Role::Job::Manager-meta-apply($lisa);

 the object  lisa  exists and  so   a Sub BUILD { ... }

 in MyApp::Role::Job::Manager doesn't be called.
 So  where  can I place my init stuff I need for my role ?


 Rolf Schaufelberger

MyApp::Role::Job::Manager;
...
after 'BUILD' = sub { shift-initalize_job_manager() }
sub _initalize_job_manager{ ... }



MyApp;
...
MyApp::role::Job::Manager-meta-apply($lisa)
$lisa-_inialize_job_manager();


Re: Roles, Classes and silent overriding

2009-04-15 Thread Chris Prather
On Tue, Apr 14, 2009 at 2:41 PM, Stevan Little
stevan.lit...@iinteractive.com wrote:

 On Apr 14, 2009, at 2:29 PM, Hans Dieter Pearcey wrote:

 On Tue, Apr 14, 2009 at 02:22:52PM -0400, Stevan Little wrote:

 So, while I am not willing to change this behavior, I am willing to add a
 warning so that it is not so silent anymore. So code like this will
 warn you that your overriding a class method.

 This is a reasonable compromise, and anyone wanting something stricter can
 extend Moose::Meta::Role to get fatal behavior.

Is this possible / easy? This is what I'd originally suggested to Ovid
and I still think that it's the best generic solution.

 You will be able to silence this warning by explicitly excluding the
 method from the role, like so:

 around() (without calling the next method) would also work.

 That won't be detectable at composition time though.

Also it means action at a distance and will fail if/when you delete
the class's local method. I just recommended against this in another
thread because of those issues.

-Chris


Re: Moose::Util function for applying missing roles

2009-04-15 Thread David E. Wheeler

On Apr 14, 2009, at 10:19 AM, Chris Prather wrote:


On Tue, Apr 14, 2009 at 1:14 PM, Stevan Little
stevan.lit...@iinteractive.com wrote:

Or perhaps ensure_all_roles_are_applied?


I'm still voting for also_also_wik()


+1

D



Re: Roles, Classes and silent overriding

2009-04-15 Thread Stevan Little
No, that is correct, but the actual process is that the method from  
the role is composed into the class, then the around wraps it.


So no need to turn off the warning as it would not actually happen.

- Stevan

On Apr 14, 2009, at 2:47 PM, Hans Dieter Pearcey wrote:


On Tue, Apr 14, 2009 at 02:41:44PM -0400, Stevan Little wrote:

around() (without calling the next method) would also work.


That won't be detectable at composition time though.


Well, if you didn't have the method, it would fail at around() time,  
so it
would work in the sense that it would let you explicitly override  
a method

from a role.

Am I missing something?

hdp.




Re: Roles, Classes and silent overriding

2009-04-15 Thread Hans Dieter Pearcey
On Wed, Apr 15, 2009 at 12:24:36PM -0400, Stevan Little wrote:
 No, that is correct, but the actual process is that the method from the 
 role is composed into the class, then the around wraps it.

 So no need to turn off the warning as it would not actually happen.

Er, yeah, that was my point: to avoid the warning, you could use around() 
instead of excluding the
method.

hdp.