File Coverage

blib/lib/IPC/Lock/RabbitMQ/Lock.pm
Criterion Covered Total %
statement 15 26 57.6
branch 0 4 0.0
condition n/a
subroutine 5 9 55.5
pod 2 2 100.0
total 22 41 53.6


line stmt bran cond sub pod time code
1             package IPC::Lock::RabbitMQ::Lock;
2 1     1   7 use Moose;
  1         2  
  1         9  
3 1     1   7483 use MooseX::Types::Moose qw/ Int /;
  1         3  
  1         13  
4 1     1   11646 use Devel::GlobalDestruction;
  1         2  
  1         12  
5 1     1   103 use Scalar::Util qw/ refaddr /;
  1         2  
  1         90  
6 1     1   7 use namespace::autoclean;
  1         3  
  1         10  
7              
8             with 'IPC::Lock::RabbitMQ::HasTimeout';
9              
10             has locker => (
11             is => 'ro',
12             required => 1,
13             );
14              
15             has lock_name => (
16             is => 'ro',
17             required => 1,
18             );
19              
20             has channel => (
21             is => 'ro',
22             required => 1,
23             );
24              
25             sub DEMOLISH {
26 0     0 1   my $self = shift;
27 0 0         return if in_global_destruction();
28 0           $self->unlock;
29             }
30              
31             sub unlock {
32 0     0 1   my ($self) = @_;
33 0 0         return 0 unless $self->channel->{_is_open}; # This is fugly, the API to AnyEvent::RabbitMQ sucks here..
34 0           my $cv = AnyEvent->condvar;
35 0           my $t = $self->_gen_timer($cv, 'Unlock');
36             $self->channel->close(
37 0     0     on_success => sub { $cv->send(1) },
38 0     0     on_failure => sub { $cv->send(0) },
39 0           );
40 0           $cv->recv;
41             }
42              
43             __PACKAGE__->meta->make_immutable;
44             1;
45              
46             =head1 NAME
47              
48             IPC::Lock::RabbitMQ - Simple and reliable scoped locking for coarse grained locks.
49              
50             =head1 SYNOPSIS
51              
52             my $locker = IPC::Lock::RabbitMQ->new( mq => $rabbitfoot );
53              
54             my $lock = $locker->lock("foo");
55             $lock->unlock;
56              
57             =head1 DESCRIPTION
58              
59             See L<IPC::Lock::RabbitMQ>
60              
61             =head1 METHODS
62              
63             =head2 new
64              
65             Constructs a lock object. You should never need to call this
66              
67             =head2 unlock
68              
69             Unlocks this lock.
70              
71             =head2 DEMOLISH
72              
73             Called when the lock object goes out of scope. Calls the unlock method.
74              
75             =head1 AUTHOR, COPYRIGHT & LICENSE
76              
77             See L<IPC::Lock::RabbitMQ>.
78              
79             =cut