Monitor.pm

filter: Statementstmt 33.3% 13 / 39 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 35.0% 20 / 57 CC 5 SCAR 17.6
CC
5
Cov
28%
run
12.0
new
6.0
load
6.0
CRAP 5.8
« Monitor/Backends/Libvirt.pm ↑ Summary
1 package HV::Monitor;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Module::List qw(list_modules);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 HV::Monitor - A generalized module for gathering stats for a hypervisor.
11  
12 =head1 VERSION
13  
14 Version 0.1.0
15  
16 =cut
17  
18 1 our $VERSION = '0.1.0';
19  
20 =head1 SYNOPSIS
21  
22 use HV::Monitor;
23  
24 =head1 METHODS
25  
26 =head2 new
27  
28 Inits the object.
29  
30 One option is taken and that is a hash ref.
31  
32 # init with the cbsd backend
33 my $hm->new({backend=>'CBSD'});
34  
35 The keys are list as below.
36  
37 - backend :: The name of the backend to use.
38 Default :: CBSD
39  
40 =cut
41  
42 sub new {
43 0 ▶ my $module = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
44 0 my $config = shift;
45  
46 0 ▶ if ( !defined( $config->{backend} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $config->{"backend"}) 0 0 0
47 0 $config->{backend} = 'CBSD';
48 }
49  
50 my $self = {
51 version => 1,
52 backend => $config->{backend},
53 0 };
54 0 bless $self;
55  
56 0 return $self;
57 }
58  
59 =head2 load
60  
61 This loads the specified backend.
62  
63 eval{ $hm->load; };
64 if ( $@ ){
65 print "Failed to load the backend... ".$@;
66 }
67  
68 =cut
69  
70 sub load {
71 0 ▶ my $self = $_[0];
Subroutine load: not called CC=2 SCAR=17.9
Pod documented
72  
73 0 my $loaded = 0;
74  
75 0 my $backend_test;
76 my $usable;
77 my $test_string = '
78 use HV::Monitor::Backends::' . $self->{backend} . ';
79 0 $backend_test=HV::Monitor::Backends::' . $self->{backend} . '->new;
80 $usable=$backend_test->usable;
81 ';
82 0 eval($test_string);
83 0 ▶ if ($usable) {
Branch: 1 branch
BranchTrueFalseTotal
if ($usable) { } 0 0 0
84 0 $self->{backend_mod} = $backend_test;
85 0 $loaded = 1;
86 }
87 else {
88 0 die( 'Failed to load backend... ' . $@ );
89 }
90  
91 0 return $loaded;
92 }
93  
94 =head2 run
95  
96 Runs the poller backend and report the results.
97  
98 If nothing is nothing is loaded, load will be called.
99  
100 my $status=$hm->run;
101  
102 =cut
103  
104 sub run {
105 0 ▶ my $self = $_[0];
Subroutine run: not called CC=3 SCAR=24.8
Pod documented
106  
107 0 ▶ if ( !defined( $self->{backend_mod} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"backend_mod"}) 0 0 0
108 return {
109 version => $self->{version},
110 0 data => {},
111 error => 1,
112 errorString => 'No module loaded',
113 };
114 }
115  
116 0 my $to_return;
117 0 eval { $to_return = $self->{backend_mod}->run };
118 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
119 return {
120 version => $self->{version},
121 0 data => {},
122 error => 1,
123 errorString => 'Failed to run backend... ' . $@,
124 };
125 }
126  
127 0 return $to_return;
128 }
129  
130 =head1 AUTHOR
131  
132 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
133  
134 =head1 BUGS
135  
136 Please report any bugs or feature requests to C<bug-hv-monitor at rt.cpan.org>, or through
137 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=HV-Monitor>. I will be notified, and then you'll
138 automatically be notified of progress on your bug as I make changes.
139  
140  
141  
142  
143 =head1 SUPPORT
144  
145 You can find documentation for this module with the perldoc command.
146  
147 perldoc HV::Monitor
148  
149  
150 You can also look for information at:
151  
152 =over 4
153  
154 =item * RT: CPAN's request tracker (report bugs here)
155  
156 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=HV-Monitor>
157  
158 =item * CPAN Ratings
159  
160 L<https://cpanratings.perl.org/d/HV-Monitor>
161  
162 =item * Search CPAN
163  
164 L<https://metacpan.org/release/HV-Monitor>
165  
166 =back
167  
168  
169 =head1 ACKNOWLEDGEMENTS
170  
171  
172 =head1 LICENSE AND COPYRIGHT
173  
174 This software is Copyright (c) 2022 by Zane C. Bowers-Hadley.
175  
176 This is free software, licensed under:
177  
178 The Artistic License 2.0 (GPL Compatible)
179  
180  
181 =cut
182  
183 1 1; # End of HV::Monitor
« Monitor/Backends/Libvirt.pm ↑ Summary