| 1 | =head1 NAME | ||
| 2 | |||
| 3 | Probe::MachineInfo::Metric - Base clas for metric collectors | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | blah | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | blah | ||
| 12 | |||
| 13 | =head1 PUBLIC INTERFACE | ||
| 14 | |||
| 15 | =cut | ||
| 16 | |||
| 17 | package Probe::MachineInfo::Metric; | ||
| 18 | |||
| 19 | |||
| 20 | # pragmata | ||
| 21 | use overload '""' => 'print'; | ||
| 22 | use strict; | ||
| 23 | use warnings; | ||
| 24 | |||
| 25 | |||
| 26 | # Standard Perl Library and CPAN modules | ||
| 27 | use Log::Log4perl; | ||
| 28 | |||
| 29 | # | ||
| 30 | # CLASS ATTRIBUTES | ||
| 31 | # | ||
| 32 | |||
| 33 | # | ||
| 34 | # CONSTRUCTOR | ||
| 35 | # | ||
| 36 | |||
| 37 | =head2 new | ||
| 38 | |||
| 39 | new(%options) | ||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | sub new { | ||
| 44 | my ($class, %options) = @_; | ||
| 45 | |||
| 46 | my $self = { | ||
| 47 | log => Log::Log4perl->get_logger($class), | ||
| 48 | }; | ||
| 49 | |||
| 50 | bless $self, $class; | ||
| 51 | return $self->_init(%options) if($self->can('_init')); | ||
| 52 | return $self; | ||
| 53 | } | ||
| 54 | |||
| 55 | =head2 get | ||
| 56 | |||
| 57 | get() | ||
| 58 | |||
| 59 | Proceeds to collect information about the machine by calling the _get_*_info methods. | ||
| 60 | |||
| 61 | =cut | ||
| 62 | |||
| 63 | sub get { | ||
| 64 | my ($self) = @_; | ||
| 65 | |||
| 66 | die("Abstract Method\n"); | ||
| 67 | } | ||
| 68 | |||
| 69 | =head2 log | ||
| 70 | |||
| 71 | log() | ||
| 72 | |||
| 73 | =cut | ||
| 74 | |||
| 75 | sub log { | ||
| 76 | my($self) = @_; | ||
| 77 | |||
| 78 | return $self->{log}; | ||
| 79 | } | ||
| 80 | |||
| 81 | =head2 print | ||
| 82 | |||
| 83 | print() | ||
| 84 | |||
| 85 | Returns a string representing the metric. This is the metric name plus any units if specified by the subclass. | ||
| 86 | |||
| 87 | This method does not need to be called directly as the stringification operator is overloaded by this method. | ||
| 88 | |||
| 89 | =cut | ||
| 90 | |||
| 91 | sub print { | ||
| 92 | my ($self) = @_; | ||
| 93 | |||
| 94 | my $value = $self->get(); | ||
| 95 | my $units = $self->units(); | ||
| 96 | return ($units) ? "$value $units" : $value; | ||
| 97 | } | ||
| 98 | |||
| 99 | =head2 units | ||
| 100 | |||
| 101 | units() | ||
| 102 | |||
| 103 | Returns the units in which the metric is in | ||
| 104 | |||
| 105 | =cut | ||
| 106 | |||
| 107 | sub units { | ||
| 108 | my ($self) = @_; | ||
| 109 | |||
| 110 | return ''; | ||
| 111 | } | ||
| 112 | |||
| 113 | 1; | ||
| 114 | |||
| 115 | =head1 AUTHOR | ||
| 116 | |||
| 117 | Sagar R. Shah | ||
| 118 | |||
| 119 | =cut |