File Coverage

blib/lib/Couch/DB/Node.pm
Criterion Covered Total %
statement 15 47 31.9
branch 0 6 0.0
condition 0 3 0.0
subroutine 5 18 27.7
pod 11 12 91.6
total 31 86 36.0


line stmt bran cond sub pod time code
1             # This code is part of Perl distribution Couch-DB version 0.201.
2             # The POD got stripped from this file by OODoc version 3.06.
3             # For contributors see file ChangeLog.
4              
5             # This software is copyright (c) 2024-2026 by Mark Overmeer.
6              
7             # This is free software; you can redistribute it and/or modify it under
8             # the same terms as the Perl 5 programming language system itself.
9             # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10              
11              
12             package Couch::DB::Node;{
13             our $VERSION = '0.201';
14             }
15              
16              
17 1     1   1373 use warnings;
  1         4  
  1         108  
18 1     1   11 use strict;
  1         2  
  1         30  
19              
20 1     1   5 use Couch::DB::Util;
  1         2  
  1         8  
21              
22 1     1   9 use Log::Report 'couch-db';
  1         2  
  1         9  
23              
24 1     1   359 use Scalar::Util qw/weaken/;
  1         3  
  1         1159  
25              
26             #--------------------
27              
28 0     0 1   sub new(@) { my ($class, %args) = @_; (bless {}, $class)->init(\%args) }
  0            
29              
30             sub init($)
31 0     0 0   { my ($self, $args) = @_;
32 0   0       $self->{CDN_name} = delete $args->{name} // panic "Node has no name";
33              
34 0 0         $self->{CDN_couch} = delete $args->{couch} or panic "Requires couch";
35 0           weaken $self->{CDN_couch};
36              
37 0           $self;
38             }
39              
40             #--------------------
41              
42 0     0 1   sub name() { $_[0]->{CDN_name} }
43 0     0 1   sub couch() { $_[0]->{CDN_couch} }
44              
45             #--------------------
46              
47             # [CouchDB API "GET /_node/{node-name}/_prometheus", UNSUPPORTED]
48             # This is not (yet) supported, because it is a plain-text version of the
49             # M<stats()> and M<server()> calls.
50              
51              
52 0     0     sub _pathToNode($) { '/_node/'. $_[0]->name . '/' . $_[1] }
53              
54             sub stats(%)
55 0     0 1   { my ($self, %args) = @_;
56 0           my $couch = $self->couch;
57              
58             #XXX No idea which data transformations can be done
59 0           $couch->call(GET => $self->_pathToNode('_stats'),
60             $couch->_resultsConfig(\%args),
61             );
62             }
63              
64              
65             sub server(%)
66 0     0 1   { my ($self, %args) = @_;
67              
68             #XXX No idea which data transformations can be done
69 0           $self->couch->call(GET => $self->_pathToNode('_system'),
70             $self->couch->_resultsConfig(\%args),
71             );
72             }
73              
74              
75             sub restart(%)
76 0     0 1   { my ($self, %args) = @_;
77              
78             #XXX No idea which data transformations can be done
79 0           $self->couch->call(POST => $self->_pathToNode('_restart'),
80             $self->couch->_resultsConfig(\%args),
81             );
82             }
83              
84              
85             sub software(%)
86 0     0 1   { my ($self, %args) = @_;
87              
88             #XXX No idea which data transformations can be done.
89             #XXX Some versions would match Perl's version object, but that's uncertain.
90 0           $self->couch->call(GET => $self->_pathToNode('_versions'),
91             $self->couch->_resultsConfig(\%args),
92             );
93             }
94              
95              
96             sub config(%)
97 0     0 1   { my ($self, %args) = @_;
98 0           my $path = $self->_pathToNode('_config');
99              
100 0 0         if(my $section = delete $args{section})
101 0           { $path .= "/$section";
102 0 0         if(my $key = delete $args{key})
103 0           { $path .= "/$key";
104             }
105             }
106              
107 0           $self->couch->call(GET => $path,
108             $self->couch->_resultsConfig(\%args),
109             );
110             }
111              
112              
113             sub configChange($$$%)
114 0     0 1   { my ($self, $section, $key, $value, %args) = @_;
115              
116 0           $self->couch->call(PUT => self->_pathToNode("_config/$section/$key"),
117             send => $value,
118             $self->couch->_resultsConfig(\%args),
119             );
120             }
121              
122              
123              
124             sub configDelete($$%)
125 0     0 1   { my ($self, $section, $key, %args) = @_;
126              
127 0           $self->couch->call(DELETE => self->_pathToNode("_config/$section/$key"),
128             $self->couch->_resultsConfig(\%args),
129             );
130             }
131              
132              
133             sub configReload(%)
134 0     0 1   { my ($self, %args) = @_;
135              
136 0           $self->couch->call(POST => self->_pathToNode("_config/_reload"),
137             $self->couch->_resultsConfig(\%args),
138             );
139             }
140              
141             1;