line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
4
|
|
|
4
|
|
17153
|
use utf8; |
|
4
|
|
|
|
|
31
|
|
|
4
|
|
|
|
|
13
|
|
2
|
|
|
|
|
|
|
package Etcd3; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Provide access to the etcd v3 API. |
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
141
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
63
|
|
7
|
4
|
|
|
4
|
|
12
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
93
|
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
1228
|
use Etcd3::Client; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
113
|
|
10
|
4
|
|
|
4
|
|
22
|
use Data::Dumper; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
186
|
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
21
|
use namespace::clean; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
16
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=encoding utf8 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Etcd3 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 VERSION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Version 0.004 |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = '0.005'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Etcd v3.1.0-alpha.0 or greater is required. To use the v3 API make sure to set environment |
31
|
|
|
|
|
|
|
variable ETCDCTL_API=3. Precompiled binaries can be downloaded at https://github.com/coreos/etcd/releases. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$etcd = Etcd3->connect(); # host: 127.0.0.1 port: 2379 |
34
|
|
|
|
|
|
|
$etcd = Etcd3->connect( $host, { username => 'HeMan', password =>'GreySkuLz', ssl => '1'}); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# put key |
37
|
|
|
|
|
|
|
$result = $etcd->put({ key =>'foo1', value => 'bar' }); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# get single key |
40
|
|
|
|
|
|
|
$key = $etcd->range({ key =>'test0' }); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
[or] |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$key = $etcd->get({ key =>'test0' }); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# return single key value or the first in a list. |
47
|
|
|
|
|
|
|
$key->get_value |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# get range of keys |
50
|
|
|
|
|
|
|
$range = $etcd->range({ key =>'test0', range_end => 'test100' }); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# return array { key => value } pairs from range request. |
53
|
|
|
|
|
|
|
my @users = $range->all |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# watch key |
56
|
|
|
|
|
|
|
$etcd->range({ key =>'foo', range_end => 'fop' }); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 DESCRIPTION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Perl access to Etcd v3 API. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 host |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 connect |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$etcd = Etcd3->connect(); # host: 127.0.0.1 port: 2379 |
69
|
|
|
|
|
|
|
$etcd = Etcd3->connect($host); |
70
|
|
|
|
|
|
|
$etcd = Etcd3->connect($host, $options); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This function returns a L object. The first parameter is the |
73
|
|
|
|
|
|
|
C argument. The second C is a hashref. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub connect { |
78
|
0
|
|
|
0
|
1
|
|
my ( $self, $host, $options ) = @_; |
79
|
0
|
|
0
|
|
|
|
$host ||= "127.0.0.1"; |
80
|
0
|
|
0
|
|
|
|
$options ||= {}; |
81
|
0
|
|
|
|
|
|
$options->{host} = $host; |
82
|
0
|
0
|
|
|
|
|
$options->{name} = $options->{user} if defined $options->{user}; |
83
|
0
|
|
|
|
|
|
return Etcd3::Client->new($options); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 AUTHOR |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Sam Batschelet, |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
The L developers and community. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 CAVEATS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
The L v3 API is in heavy development and can change at anytime please see |
97
|
|
|
|
|
|
|
https://github.com/coreos/etcd/blob/master/Documentation/dev-guide/api_reference_v3.md |
98
|
|
|
|
|
|
|
for latest details. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Copyright 2017 Sam Batschelet (hexfusion). |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
106
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
107
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|