File Coverage

blib/lib/XAS/Lib/Lockmgr/Nolock.pm
Criterion Covered Total %
statement 9 41 21.9
branch 0 6 0.0
condition n/a
subroutine 3 14 21.4
pod 4 5 80.0
total 16 66 24.2


line stmt bran cond sub pod time code
1             package XAS::Lib::Lockmgr::Nolock;
2              
3             our $VERSION = '0.01';
4              
5 1     1   767 use Try::Tiny;
  1         2  
  1         47  
6 1     1   4 use XAS::Constants 'TRUE FALSE HASHREF';
  1         2  
  1         5  
7              
8             use XAS::Class
9 1         8 version => $VERSION,
10             base => 'XAS::Base',
11             accessors => 'host port timeout attempts mutex',
12             vars => {
13             PARAMS => {
14             -key => 1,
15             -args => { optional => 1, type => HASHREF, default => {} },
16             }
17             }
18 1     1   140 ;
  1         2  
19              
20             # ----------------------------------------------------------------------
21             # Public Methods
22             # ----------------------------------------------------------------------
23              
24             sub lock {
25 0     0 1   my $self = shift;
26              
27 0           my $count = 0;
28 0           my $stat = TRUE;
29 0           my $key = $self->key;
30              
31             try {
32              
33 0     0     $stat = TRUE;
34              
35             } catch {
36              
37 0     0     my $ex = $_;
38 0 0         my $msg = (ref($ex) eq 'Badger::Exception') ? $ex->info : $ex;
39              
40 0           $self->throw_msg(
41             dotid($self->class) . '.lock',
42             'lock_error',
43             $key, $msg
44             );
45              
46 0           };
47              
48 0           return $stat;
49              
50             }
51              
52             sub unlock {
53 0     0 1   my $self = shift;
54              
55 0           my $stat = FALSE;
56 0           my $key = $self->key;
57              
58             try {
59              
60 0     0     $stat = TRUE;
61              
62             } catch {
63              
64 0     0     my $ex = $_;
65 0 0         my $msg = (ref($ex) eq 'Badger::Exception') ? $ex->info : $ex;
66              
67 0           $self->throw_msg(
68             dotid($self->class) . '.unlock',
69             'lock_error',
70             $key, $msg
71             );
72              
73 0           };
74              
75 0           return $stat;
76              
77             }
78              
79             sub try_lock {
80 0     0 1   my $self = shift;
81              
82 0           my $stat = FALSE;
83 0           my $key = $self->key;
84              
85             try {
86              
87 0     0     $stat = TRUE;
88              
89             } catch {
90              
91 0     0     my $ex = $_;
92 0 0         my $msg = (ref($ex) eq 'Badger::Exception') ? $ex->info : $ex;
93              
94 0           $self->throw_msg(
95             dotid($self->class) . '.try_lock',
96             'lock_error',
97             $key, $msg
98             );
99              
100 0           };
101              
102 0           return $stat;
103              
104             }
105              
106             sub exceptions {
107 0     0 1   my $self = shift;
108              
109 0           my @exceptions = ();
110              
111 0           return \@exceptions;
112              
113             }
114              
115             sub destroy {
116 0     0 0   my $self = shift;
117            
118             }
119              
120             # ----------------------------------------------------------------------
121             # Private Methods
122             # ----------------------------------------------------------------------
123              
124             1;
125              
126             __END__
127              
128             =head1 NAME
129              
130             XAS::Lib::Lockmgr::Nolock - Use no locking at all.
131              
132             =head1 SYNOPSIS
133              
134             use XAS::Lib::Lockmgr;
135              
136             my $key = '/var/lock/xas/alerts';
137             my $lockmgr = XAS::Lib::Lockmgr->new();
138              
139             $lockmgr->add(
140             -key => $key,
141             -driver => 'Nolock',
142             );
143              
144             if ($lockmgr->try_lock($key)) {
145              
146             $lockmgr->lock($key);
147              
148             ...
149              
150             $lockmgr->unlock($key);
151              
152             }
153              
154             =head1 DESCRIPTION
155              
156             This class uses nothing to manage locks. This is a placeholder and allows
157             for fake discretionary locking of resources.
158              
159             =head1 CONFIGURATION
160              
161             This module uses the following fields in -args.
162              
163             =head1 METHODS
164              
165             =head2 lock
166              
167             Attempt to aquire a lock. Returns TRUE for success, FALSE otherwise.
168              
169             =head2 unlock
170              
171             Remove the lock. Returns TRUE for success, FALSE otherwise.
172              
173             =head2 try_lock
174              
175             Check to see if a lock could be aquired. Returns FALSE if not,
176             TRUE otherwise.
177              
178             =head2 exceptions
179              
180             Returns the exceptions that you may not want to continue lock attemtps if
181             triggered.
182              
183             =head1 SEE ALSO
184              
185             =over 4
186              
187             =item L<XAS::Lib::Lockmgr|XAS::Lib::Lockmgr>
188              
189             =item L<XAS|XAS>
190              
191             =back
192              
193             =head1 AUTHOR
194              
195             Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
196              
197             =head1 COPYRIGHT AND LICENSE
198              
199             Copyright (c) 2012-2016 Kevin L. Esteb
200              
201             This is free software; you can redistribute it and/or modify it under
202             the terms of the Artistic License 2.0. For details, see the full text
203             of the license at http://www.perlfoundation.org/artistic_license_2_0.
204              
205             =cut