| 1 | package Etcd::Lock; | ||||||||||||||||||||||||||||
| 2 | 2 | $Etcd::Lock::VERSION = '0.02'; | |||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.012; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Net::Etcd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use boolean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | sub new { | ||||||||||||||||||||||||||||
| 9 | 0 | ▶ | my $c = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | 0 | my %a = @_; | |||||||||||||||||||||||||||
| 11 | 0 | my %b; | |||||||||||||||||||||||||||
| 12 | 0 | $b{etcd} = Net::Etcd->new( { host => $a{host} } ); | |||||||||||||||||||||||||||
| 13 | 0 | foreach (qw/host key/) { | |||||||||||||||||||||||||||
| 14 | 0 | $b{$_} = $a{$_}; | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | 0 | return bless \%b, $c; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | sub lock () { | ||||||||||||||||||||||||||||
| 20 | 0 | ▶ | my $s = shift; | ||||||||||||||||||||||||||
|
Subroutine
lock: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 0 | return $s->_lock_unlock( true ); | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub unlock () { | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my $s = shift;; | ||||||||||||||||||||||||||
|
Subroutine
unlock: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 0 | return $s->_lock_unlock( false ); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub _lock_unlock ( ) { | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $s = shift; | ||||||||||||||||||||||||||
|
Subroutine
_lock_unlock: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 31 | 0 | my $nval = shift; | |||||||||||||||||||||||||||
| 32 | 0 | my $k = $s->{key}; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | my $val = $s->{etcd}->range( { key => $k } )->get_value; | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | return $val unless defined $nval; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return false if defined $val && $val eq $nval; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $val and $val eq $nval
MC/DC0%0/2
defined $val and $val eq $nval
defined $val
$val eq $nval
Truth table0%0/3
A and B
A= defined $valB= $val eq $nval
| |||||||||||||||||||||||||||||
| 37 | $nval | ||||||||||||||||||||||||||||
| 38 | ? $s->{etcd}->put( { key => $k, value => $nval } ) | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | : $s->{etcd}->deleterange( { key => $k } ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | return true; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | 1; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =pod | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =head1 NAME | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | Etcd::Lock - Lock based on etcd | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =for html <p> | ||||||||||||||||||||||||||||
| 52 | <a href="https://github.com/emilianobruni/etcd-lock/actions/workflows/test.yml"> | ||||||||||||||||||||||||||||
| 53 | <img alt="github workflow tests" src="https://github.com/emilianobruni/etcd-lock/actions/workflows/test.yml/badge.svg"> | ||||||||||||||||||||||||||||
| 54 | </a> | ||||||||||||||||||||||||||||
| 55 | <img alt="Top language: " src="https://img.shields.io/github/languages/top/emilianobruni/etcd-lock"> | ||||||||||||||||||||||||||||
| 56 | <img alt="github last commit" src="https://img.shields.io/github/last-commit/emilianobruni/etcd-lock"> | ||||||||||||||||||||||||||||
| 57 | </p> | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head1 VERSION | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | version 0.02 | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | use Etcd::Lock | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | my $etcdLock = Etcd::Lock->new(host => 'host.name.com', key => 'lock_key'); | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Etcd::Lock is a lock based on etcd | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =head1 BUGS/CONTRIBUTING | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Please report any bugs through the web interface at L<https://github.com/EmilianoBruni/etcd-lock/issues> | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | If you want to contribute changes or otherwise involve yourself in development, feel free to fork the Git repository from | ||||||||||||||||||||||||||||
| 80 | L<https://github.com/EmilianoBruni/etcd-lock/>. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | You can find this documentation with the perldoc command too. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | perldoc etcd-lock | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | Emiliano Bruni <info@ebruni.it> | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | This software is copyright (c) 2022 by Emiliano Bruni. | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 97 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =cut | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | __END__ | ||||||||||||||||||||||||||||