blib/lib/App/Unicheck/Modules/MongoDB.pm

filter: Statementstmt 62.2% 28 / 45 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 9 / 15 Podpod 33.3% 1 / 3 totaltotal 58.4% 38 / 65 CC 2 SCAR 6.6
CC
2
Cov
60%
_return
6.0
run
2.0
reachable
2.0
CRAP 1.9
↑ Summary
1 package App::Unicheck::Modules::MongoDB;
2  
3 1 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Getopt::Long qw(GetOptionsFromArray);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use MongoDB;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use MongoDB::MongoClient;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 NAME
14  
15 App::Unicheck::Modules::MongoDB - App::Unicheck module to check mongodb servers.
16  
17 =head1 VERSION
18  
19 Version 0.03
20  
21 =cut
22  
23 1 our $VERSION = '0.03';
24  
25  
26 =head1 SYNOPSIS
27  
28 App::Unicheck::Modules::MongoDB can check mongod reachability.
29  
30 # to show available information on parameters run
31 unicheck --info MongoDB
32  
33 =cut
34  
35 0 ▶sub run {
Subroutine run: not called CC=1 SCAR=6.9
Pod undocumented
36 0 my ($self, $action, @params) = @_;
37  
38 0 $self->$action(@params);
39 }
40  
41 =head1 ACTIONS
42  
43 =head2 reachable
44  
45 Check if the server is reachable.
46  
47 # check default localhost:27017
48 unicheck MongoDB reachable
49  
50 # check specific host:port
51 unicheck MongoDB reachable --host example.com --port 1234
52  
53 =cut
54  
55 0 ▶sub reachable {
Subroutine reachable: not called CC=1 SCAR=6.9
Pod documented
56 0 my ($self, @params) = @_;
57  
58 0 my $host = 'localhost';
59 0 my $port = 27017;
60 0 my $format = 'num';
61  
62 0 GetOptionsFromArray([@params],
63 'port=i' => \$port,
64 'host=s' => \$host,
65 'format=s' => \$format,
66 );
67  
68 0 my $retval;
69 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
70 0 MongoDB::MongoClient->new(host => $host, port => $port);
71 0 $retval = $self->_return(1, 'Connection successful', $format);
72 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
73 0 $retval = $self->_return(0, $_, $format);
74 0 };
75  
76 0 $retval;
77 }
78  
79 0 ▶sub _return {
Subroutine _return: not called CC=2 SCAR=17.9
80 0 my ($self, $status, $value, $format) = @_;
81  
82 0 ▶ return JSON->new->encode(
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "json" 0 0 0
83 {
84 message => $value,
85 status => $status,
86 }
87 ) if $format eq 'json';
88 # default last in case some non supported format was given
89 0 return $status; # if $format eq 'num'
90 }
91  
92 0 ▶sub help {
Subroutine help: not called CC=1 SCAR=6.9
Pod undocumented
93 {
94 0 description => 'Check mongoDB status',
95 actions => {
96 reachable => {
97 description => 'Check if mongodb server is reachable',
98 params => {
99 '--host' => 'Default: localhost',
100 '--port' => 'Default: 27017',
101 '--format' => 'Default: num'
102 },
103 formats => {
104 'num' => 'Returns the status code',
105 'json' => 'Returns a JSON structure',
106 },
107 },
108 },
109 }
110 }
111  
112 =head1 AUTHOR
113  
114 Matthias Krull, C<< <<m.krull at uninets.eu>> >>
115  
116 =head1 BUGS
117  
118 Please report any bugs or feature requests to C<bug-app-unicheck-modules-mongodb at rt.cpan.org>, or through
119 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-Unicheck-Modules-MongoDB>. I will be notified, and then you'll
120 automatically be notified of progress on your bug as I make changes.
121  
122  
123  
124  
125 =head1 SUPPORT
126  
127 You can find documentation for this module with the perldoc command.
128  
129 perldoc App::Unicheck::Modules::MongoDB
130  
131  
132 You can also look for information at:
133  
134 =over 4
135  
136 =item * RT: CPAN's request tracker (report bugs here)
137  
138 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-Unicheck-Modules-MongoDB>
139  
140 =item * AnnoCPAN: Annotated CPAN documentation
141  
142 L<http://annocpan.org/dist/App-Unicheck-Modules-MongoDB>
143  
144 =item * CPAN Ratings
145  
146 L<http://cpanratings.perl.org/d/App-Unicheck-Modules-MongoDB>
147  
148 =item * Search CPAN
149  
150 L<http://search.cpan.org/dist/App-Unicheck-Modules-MongoDB/>
151  
152 =item * Github
153  
154 L<https://github.com/uninets/App-Unicheck-Modules-MongoDB/>
155  
156 =back
157  
158  
159 =head1 ACKNOWLEDGEMENTS
160  
161  
162 =head1 LICENSE AND COPYRIGHT
163  
164 Copyright 2013 Matthias Krull.
165  
166 This program is free software; you can redistribute it and/or modify it
167 under the terms of the the Artistic License (2.0). You may obtain a
168 copy of the full license at:
169  
170 L<http://www.perlfoundation.org/artistic_license_2_0>
171  
172 Any use, modification, and distribution of the Standard or Modified
173 Versions is governed by this Artistic License. By using, modifying or
174 distributing the Package, you accept this license. Do not use, modify,
175 or distribute the Package, if you do not accept this license.
176  
177 If your Modified Version has been derived from a Modified Version made
178 by someone other than you, you are nevertheless required to ensure that
179 your Modified Version complies with the requirements of this license.
180  
181 This license does not grant you the right to use any trademark, service
182 mark, tradename, or logo of the Copyright Holder.
183  
184 This license includes the non-exclusive, worldwide, free-of-charge
185 patent license to make, have made, use, offer to sell, sell, import and
186 otherwise transfer the Package with respect to any patent claims
187 licensable by the Copyright Holder that are necessarily infringed by the
188 Package. If you institute patent litigation (including a cross-claim or
189 counterclaim) against any party alleging that the Package constitutes
190 direct or contributory patent infringement, then this Artistic License
191 to you shall terminate on the date that such litigation is filed.
192  
193 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
194 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
195 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
196 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
197 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
198 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
199 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
200 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
201  
202  
203 =cut
204  
205 1 1; # End of App::Unicheck::Modules::MongoDB
↑ Summary