Re: Setting delegated attributes in constructors

2018-02-13 Thread Buddy Burden
Merlyn, I guess the problem here is that Moose doesn't really call the accessors in the constructor but just uses some shortcut to copy the constructor parameters to the object. While I fully admit that I've not been following this discussion closely, whenever I've seen a statement such as thi

Re: Setting delegated attributes in constructors

2018-02-13 Thread Merlyn Kline
Thanks for quick and helpful replies. I'm not really trying to subvert inheritance though I now see that my simplified example looks much like that. I'd contemplated the BUILD(ARGS) route but couldn't see exactly how to do it without losing some of the validation benefits (again, not really visible

Re: Setting delegated attributes in constructors

2018-02-13 Thread Harald Jörg
Merlyn Kline writes: > I'd like to set delegated attributes in my object constructors > (e.g. as below) but this doesn't seem to work. Am I missing > something? perldoc Moose::Manual::Delegation calls it "Attribute delegation", but actually you're not delegating attributes. Instead, you are del

Re: Setting delegated attributes in constructors

2018-02-13 Thread Nick Perez
Delegated methods are typically used as a convenience technique to class composition to avoid writing your own wrapper methods that call the underlying methods the contained object has. It really wasn't intended to subvert inheritance like you're trying to do. HTH, Nick On Tue, 13 Feb 2018 10:

Setting delegated attributes in constructors

2018-02-13 Thread Merlyn Kline
I'd like to set delegated attributes in my object constructors (e.g. as below) but this doesn't seem to work. Am I missing something? Merlyn #!/usr/bin/perl package SubClass; use Moose; has thing => ( is => 'rw', isa => 'Int' ); before thing => sub { shift; print "subthing: ", @_ ?