in reply to Good practice for OO module defaults
Hi John Davies,
A few points in random order:
- It's recommended to always make an Moo attribute lazy unless there's a good reason for it not to be.
- If your attribute is lazy you can declare a builder sub for it.
- The builder sub can be anywhere, including a module that is basically just a config file (but lives in lib/).
- The value of the default property of an attribute can also be a coderef or sub.
- Most applications grow to need a config system at some point; I place changeable config data in config files as it's easiest to maintain. If you are concerned about directory structures you can make you config directory relative to the library directory.
Hope this helps!
The way forward always starts with a minimal test.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Good practice for OO module defaults
by tobyink (Canon) on Apr 09, 2019 at 15:50 UTC | |
by 1nickt (Canon) on Apr 10, 2019 at 10:53 UTC | |
by tobyink (Canon) on Apr 10, 2019 at 14:02 UTC |
In Section
Seekers of Perl Wisdom