in reply to Moose and BUILD and 'ro' attributes

Thank You for pointing out at Moose::Manual::Construction, which is not about Moose construction, but constructing objects in Moose. I should not have ignored that :-(

In short, the problem is I read Log4Perl initialization from a file, for two logfiles, one technical log and one specialized log changing over the time. To create the second one on-the-fly I use the patterns from the config to create a layout class and an appender, which is later used to generate the second logfile. The reason for this is that File-Appenders create the files on construction, but I do not have a filename at that time. So I gather and create all things I need at the beginning to use them when I first have a logfilename. Later I can use file_switch() on the appender but that is Log4Perl. Expensive? I really do not know. My philosophy/religion is that constant things should be initialized at the beginning, when they are used more than once.

I think You are right, I might solve this by reordering my builders and revisting the examples.

Thank You again for Your patience

And it came to pass that in time the Great God Om spake unto Brutha, the Chosen One: "Psst!"
(Terry Pratchett, Small Gods)

  • Comment on Re: Moose and BUILD and 'ro' attributes

Replies are listed 'Best First'.
Re^2: Moose and BUILD and 'ro' attributes
by tospo (Hermit) on Dec 15, 2010 at 11:39 UTC
    Yes, it is probably possible to solve this just by re-thinking the order of events and what actually depends on what. You can usually come up with some workable chain of events using lazy loading. I would also not be too fuzzed about the time of creation of the attribute - if you use lazy the attribute is guaranteed to be populated before you use it the first time, which should be all that matters. In some cases, setting a trigger for an attribute might also help to resolve some more complicated dependencies.