Name : perl-Sub-Trigger-Lock
| |
Version : 0.002
| Vendor : obs://build_opensuse_org/devel:languages:perl
|
Release : lp155.1.1
| Date : 2023-07-20 19:00:25
|
Group : Development/Libraries/Perl
| Source RPM : perl-Sub-Trigger-Lock-0.002-lp155.1.1.src.rpm
|
Size : 0.04 MB
| |
Packager : https://www_suse_com/
| |
Summary : Coderef for Use in Moose Triggers That Will Lock Hashrefs and Arrayrefs
|
Description :
This module provides two constants, \'Lock\' and \'RO\'. The first of these is the only one exported by default, and the key to understanding this module. This module also provides the utility functions \'lock\' and \'unlock\', which are not exported by default.
* \'Lock\'
\'Lock\' is a constant which evaluates to a coderef. The coderef takes two or more arguments. That is, \'Lock\' itself takes no arguments; it returns a coderef that takes arguments!
The first argument is supposed to be a blessed object, but it is actually completely ignored.
If the second argument is not a hashref or arrayref, it is also ignored. Everything is ignored! But if the second argument _is_ a hashref or arrayref, it will be flagged as read-only.
This is a fairly shallow read-only flag. Attempts to add or remove keys from the hash, or change the value for any key will throw an exception. But if the value is reference to some other structure, that structure will be unaffected.
Similarly, attempts to push, pop, shift, or unshift a read-only array, or to change the value for any index will throw an exception. Buf if the values are references to other structures, these will also be unaffected.
Overall, the effect of \'Lock\' is that you can do something like this:
package Person { use Moose;
has name => (is => \'ro\', writer => \'set_name\'); }
package Band { use Moose; use Sub::Trigger::Lock;
has members => (is => \'ro\', trigger => Lock); }
my $spice_girls = Band->new( members => [ Person->new(name => \'Victoria Adams\'), Person->new(name => \'Melanie Brown\'), Person->new(name => \'Emma Bunton\'), Person->new(name => \'Melanie Chisholm\'), Person->new(name => \'Geri Halliwell\'), ], );
$spice_girls->members->[0]->set_name(\'Victoria Beckham\');
$spice_girls->members->[0] = Person->new(name => \'Johnny Cash\');
* \'RO\'
\'RO\' is a constant that evaluates to the list:
\'ro\', \'trigger\', Lock,
* \'lock($ref)\'
A utility function for locking an arrayref or hashref in the same way that the \'Lock\' coderef would.
* \'unlock($ref)\'
A utility function for unlocking an arrayref or hashref.
Note that this returns a _guard object_. You should store this object in a variable. Once the object is destroyed (e.g. because the variable has gone out of scope), \'$ref\' will be automatically locked again!
This allows you to temporarily unlock a hashref or arrayref in order to privately manipulate it:
package Band { use Moose; use Sub::Trigger::Lock qw( Lock unlock );
has members => (is => \'ro\', trigger => Lock);
sub add_members { my ($self, AATTmembers) = AATT_; my $guard = unlock( $self->members ); push AATT{$self->members}, AATTmembers; } }
|
RPM found in directory: /packages/linux-pbone/ftp5.gwdg.de/pub/opensuse/repositories/devel:/languages:/perl:/CPAN-S/15.5/noarch |