in reply to [Moose] Critique request on my Moose design (anti?)pattern
I use Moose a lot and can probably help you, but I'm not sure I understand your question.
You said: ...needing "sub" objects regularly. What is a "sub" object to you? What I see in your code is that MyApp (My::App object) is an attribute of the "My" class. Is that what you call a sub object?
Also: How do you deal with passing required attributes through? ... You mean through the "sub" object? If you want to pass your required attributes from the "My" object to the "MyApp" attribute, I recommend using a "lazy" attribute with a "builder". Try this (you can get fancy later):
has 'MyApp' => ( lazy => 1, isa => 'My::App', builder => '_build_myapp', ); sub _build_myapp { my $self = shift; return My::App->new( foo => $self->app_foo, bar => $self->app_bar, ); };
It's much cleaner.
A for will get you from A to Z; a while will get you everywhere.
-- greengaroo
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: [Moose] Critique request on my Moose design (anti?)pattern
by three18ti (Monk) on Feb 01, 2014 at 08:27 UTC |
In Section
Seekers of Perl Wisdom