Leser: 1
7 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use strict;
use warnings;
package Ox::Lock;
use vars '$VERSION';
$VERSION = '0.05';
use Fcntl ':flock';
sub new {
my $proto = shift;
return undef
unless defined $proto;
my $class = ref($proto) || $proto;
my $self = bless {}, $class;
$self->init(@_) if @_;
$self->directory('/') unless defined $self->directory;
return ($self);
}
sub DESTROY {
shift->unlock;
}
sub directory {
my $self = shift;
return ($self->value_('directory', @_));
}
sub handle {
my $self = shift;
return $self->directory().".lock";
}
sub load {
my $self = shift;
$self->unload();
unless(-e $self->handle) {
my $fh;
if(open my $fh, ">", $self->handle) {
$self->{-lock} = $fh;
return (1);
}
}
return (0);
}
sub unload {
my $self = shift;
if(defined $self->{-lock}) {
close $self->{-lock};
unlink $self->handle;
$self->{-lock} = undef;
}
}
sub lock {
my $self = shift;
if($self->load) {
return (flock $self->{-lock}, LOCK_EX);
} else {
return (0);
}
}
sub trylock {
my $self = shift;
if($self->load) {
return (flock $self->{-lock}, LOCK_EX | LOCK_NB);
} else {
return (0);
}
}
sub unlock {
shift->unload;
}
sub init(\%) {
my ($self, %args) = @_;
exists $args{$_} && ($self->value_($_, delete $args{$_}))
foreach (qw/directory/);
}
sub value_ {
my ($self, $field, $value) = @_;
return (undef)
unless defined $field;
if(defined $value) {
$self->{'OWML_'.lc($field)} = $value;
}
return ($self->{'OWML_'.lc($field)});
}
1;
1
2
3
4
5
6
7
8
9
10
11
12
sub set {
my ($self, $value, $field) = @_;
$self->{$value} = $field;
}
sub update {
my ($self) = @_;
$self->set('feld1', 'wert1');
$self->set('feld2', 'wert2');
$self->set('feld3', 'wert3');
}
7 Einträge, 1 Seite |