The point of being able to lazyload just a single instance is basically to be as unintrusive as possible, while still allowing this to be possible. Let me explain in more detail.
Say you want to lazy load ever instance of the class.
use Class::LazyLoader 'My::Class';
push @lazy_classes => My::Class->new() for 1 .. 100;
Every single instance of My::Class is now lazily loaded. This is obvious, and how most of the class proxy/lazy loading module out there work.
Now take this particular example (based on the IOC issues mentioned above in response to dio).
My A constructor requires an instance of B, and my B constructor requires an instance of A. The best solution is to give A a real B instance, and give B a lazy-loaded A instance.
Now say my C constructor requires an instance of A. I previously gave B a lazy-loaded A, however, there is no need to give C a lazy-loaded A, that is an unessecary level of indirection. But if lazy-loading was on a class level only, I would not be able to make this choice. With lazy-loading being available on a per-instance basis I can give C a real A instance.
Of course the need (or desire) to fiddle at this low a level is a rare instance and one not likely to be an issue for anyone but me. However, this is exactly the issue that caused dragonchild and I to start talking about and building this module.
|