File Coverage

blib/lib/Pixie/LockStrat.pm
Criterion Covered Total %
statement 30 30 100.0
branch 4 6 66.6
condition n/a
subroutine 11 11 100.0
pod 0 5 0.0
total 45 52 86.5


line stmt bran cond sub pod time code
1             ##
2             # NAME
3             # Pixie::LockStrat - base class for locking strategies in Pixie
4             #
5             # SYNOPSIS
6             # use Pixie::LockStrat;
7             #
8             # my $strat = Pixie::LockStrat->new;
9             # $pre_get_status = $strat->pre_get( $oid, $pixie );
10             # $strat->post_get( $oid, $pixie, $pre_get_status );
11             # $pre_store_status = $strat->pre_store( $oid, $pixie );
12             # $strat->post_store( $oid, $pixie, $pre_store_status );
13             #
14             # $strat->on_DESTROY; # call from your DESTROY
15             #
16             # DESCRIPTION
17             # Pixie::LockStrat's are used by Pixie to control access to the
18             # store. This class implements a basic locking strategy where:
19             #
20             # * get's are not locked
21             # * store's are locked 'atomically'
22             #
23             # Pixie defines what 'atomically' means.
24             #
25             # NOTES
26             # At the moment, everything implemented as class methods.
27             #
28             ##
29              
30             package Pixie::LockStrat;
31              
32 25     25   37419 use strict;
  25         48  
  25         938  
33 25     25   129 use warnings;
  25         54  
  25         846  
34              
35 25     25   129 use Carp qw( carp );
  25         53  
  25         1983  
36 25     25   140 use Scalar::Util qw( blessed );
  25         51  
  25         1226  
37              
38 25     25   122 use base qw( Pixie::Object );
  25         812  
  25         10063  
39              
40             our $VERSION = '2.08_02';
41              
42 1     1 0 10 sub pre_get {}
43              
44 1     1 0 4 sub post_get {}
45              
46             sub pre_store {
47 1     1 0 66 my $self = shift;
48 1         3 my($oid, $pixie) = @_;
49 1         11 $pixie->store->lock_object_for($oid, $pixie);
50             }
51              
52             sub post_store {
53 2     2 0 571 my $self = shift;
54 2         4 my ($oid, $pixie, $pre_status) = @_;
55 2 100       17 $pixie->store->unlock_object_for($oid, $pixie) if $pre_status;
56             }
57              
58             sub on_DESTROY {
59 24     24 0 576 my $self = shift;
60 24         48 my ($oid, $pixie) = @_;
61 24         47 local $@; # preserve errors
62 24         60 $self->{on_DESTROY_called} = 1;
63 24         80 my $store = $pixie->store;
64 24 50       312 $store->unlock_object_for($oid, $pixie) if $store;
65             }
66              
67             sub DESTROY {
68 29 50   29   4368 carp( blessed( $_[0] ) . " destroyed before on_DESTROY called" )
69             unless $_[0]->{on_DESTROY_called};
70             }
71              
72             1;