Name : perl-Class-Accessor-Lazy
| |
Version : 1.003
| Vendor : obs://build_opensuse_org/devel:languages:perl
|
Release : lp156.4.1
| Date : 2024-07-03 17:50:09
|
Group : Development/Libraries/Perl
| Source RPM : perl-Class-Accessor-Lazy-1.003-lp156.4.1.src.rpm
|
Size : 0.02 MB
| |
Packager : https://www_suse_com/
| |
Summary : Class Accessors Generation with Lazy Accessors and Fast Mode Support
|
Description :
This module allowes you to create accessors and mutators for your class, using one of the modules: Class::Accessor or Class::Accessor::Fast, but, in addition, it allowes you to create lazy accessors.
You may create mix accessors in your module, use Fast and regular ones like this:
package Foo; use base qw(Class::Accessor::Lazy);
Foo->follow_best_practice;
Foo->mk_accessors(slow_accessor);
Foo->fast_accessors;
Foo->mk_accessors(fast_accessor);
Foo->follow_best_practice ->mk_accessors(slow_accessor) ->fast_accessors ->mk_accessors(fast_accessor);
Main documentation may be found on Class::Accessor and Class::Accessor::Fast pages.
The main extension of this module is possibility to make lazy properties, which will be inited on first get operation (if there was no write before).
Such methods are useful for database representation classes, where related data may not be read at all and there is no need to fetch it from database.
For example, there are \'Shop\' class and \'Employee\' class. Each \'Shop\' has property \'employees\', which contains a reference to \'Employee\' objects list. But, you could fetch Shop object from database just to check \'income\' property and no don\'t need information about employees at all. In this case, reading employees list and creating list of \'Employee\' objects makes absolutely no sense.
But, if you want to get access to them, they should be read from database. And here are lazy properties comes:
package Shop; use base \'Class::Accessor::Lazy\';
Shop->follow_best_practice # use set/get for accessors/mutators ->fast_accessors # use Class::Acessor::Fast algorithm ->mk_accessors(\'income\') # regular property ->mk_lazy_accessors(\'employees\'); # lazy property
...
sub _lazy_init_employees { }
On first \'get_employees\' invocation, method \'Shop::_lazy_init_employees\' will be invoked automatically, to allow your class to read related data from database, for example, and store it in object.
IMPORTANT: every lazy property of the class MUST have related init method. The name of such method is \'_lazy_init_{property name}\'.
|
RPM found in directory: /packages/linux-pbone/ftp5.gwdg.de/pub/opensuse/repositories/devel:/languages:/perl:/CPAN-C/15.6/noarch |