line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Keys::E::UniqSet; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Data::Keys::E::UniqSet - a key can be set only once |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
One key can be set only once. Second set attempt on a key will throw an |
10
|
|
|
|
|
|
|
exception. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
1271
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
15
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
5
|
use Moose::Role; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
20
|
1
|
|
|
1
|
|
4903
|
use Fcntl qw(:DEFAULT); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
535
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
requires('set', 'lock_ex', 'unlock'); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
around 'set' => sub { |
25
|
|
|
|
|
|
|
my $set = shift; |
26
|
|
|
|
|
|
|
my $self = shift; |
27
|
|
|
|
|
|
|
my $key = shift; |
28
|
|
|
|
|
|
|
my $value = shift; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$self->lock_ex($key); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# pass through in case of delete |
33
|
|
|
|
|
|
|
$self->$set($key, undef) |
34
|
|
|
|
|
|
|
if not defined $value; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
die '"'.$key.'" already exists' |
37
|
|
|
|
|
|
|
if $self->get($key); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# call set |
40
|
|
|
|
|
|
|
my $ret = $self->$set($key, $value); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$self->unlock($key); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return $ret; |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 AUTHOR |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Jozef Kutej |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |