Hi Eric. :)

Thanks for your response!

You mean the default => sub {} is called whenever an object in that class or a derived class is created? That is by-design.

In fact, I implemented a BUILD method in the loader object and let it print a message. It is called when a submodule calls the loader accessor. So, yes, I mean that.

You want it to be a singleton that is shared across all objects?

Yes, that's right. I am going to have a base class for my application that 'collects' the methods of some helper classes (dynamic module loading at runtime, debugging, etc) and provides them to all objects that inherit from it. (I know, that's evil...)

> If so,
you've got a valid solution in the code above. Another alternative would be to construct CM::Module::Loader->new to return this singleton (but that changes the policy at a different level.)

I thought about that, too, but as you said, that would change the policy at a different level. I just don't want to do that.

You mentioned "overhead", which implies that you're only thinking in terms of optimizing? If so, you can't do that. If you want each object to have a distinct instance of 'loader', you need to create a loader every time you create an object, which is what default => sub {} usage is intended to support.

Ahm, no, I'm just going to provide a - hm - let's say, a single entry point for a bunch of helper modules. I am no aware of a term to describe this right, I'm afraid.

Thanks again. :)

Greetings, Bianka

Reply via email to