in reply to Writing Object-Orientated Module: use of “new” and other methods.
The simpler your API, the easier it is to use. I tend to prefer your third option—but I also like to know that once someone has constructed an object of my class, that object is in a well-understood and safe state. (I'll forget to call $obj->process and things will go wrong.)
Moose has an interesting concept called a lazy builder method which gets called to create an attribute if that attribute isn't already set. What you can do is pass in your raw data to the constructor, then parse only if someone requests the value of an attribute which relies on that raw data.
Performing this parsing in the constructor is fine as well, of course, but you don't have to write a constructor in most Moose code.
|
|---|