File: Scalar.pm

package info (click to toggle)
libtest-sharedfork-perl 0.35-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 200 kB
  • sloc: perl: 270; makefile: 2
file content (26 lines) | stat: -rw-r--r-- 530 bytes parent folder | download | duplicates (4)
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
package Test::SharedFork::Scalar;
use strict;
use warnings;
use base 'Tie::Scalar';

# create new tied scalar
sub TIESCALAR {
    my ($class, $share, $key) = @_;
    die "missing key" unless $key;
    bless { share => $share, key => $key }, $class;
}

sub FETCH {
    my $self = shift;
    my $lock = $self->{share}->get_lock();
    $self->{share}->get($self->{key});
}

sub STORE {
    my ($self, $val) = @_;
    my $share = $self->{share};
    my $lock = $self->{share}->get_lock();
    $share->set($self->{key} => $val);
}

1;