blib/lib/Ganglia/Gmetric.pm

filter: Statementstmt 37.8% 14 / 37 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 100% 2 / 2 totaltotal 33.3% 19 / 57 CC 7 SCAR 35.0
CC
7
Cov
29%
run
56.0
new
2.0
__ANON__
2.0
CRAP 33.2
↑ Summary
1 package Ganglia::Gmetric;
2 1 $VERSION=0.3;
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base qw(Class::Accessor);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use IO::CaptureOutput qw/capture/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Ganglia::Gmetric - perl gmetric wrapper
10  
11 =head1 SYNOPSIS
12  
13 use Ganglia::Gmetric;
14  
15 my $gmetric=Ganglia::Gmetric->new({
16 name => 'some name',
17 value => 'some value',
18 units => 'm/s',
19 type => 'int16'
20 });
21  
22 $gmetric->ttl('5');
23 $gmetric->run(\$stdout,\$stderr);
24  
25 =cut
26  
27 1 my $gmetric='gmetric';
28  
29 =head1 DESCRIPTION
30  
31 Simple perl wrapper around ganglia's gmetric.
32  
33 =head2 new
34  
35 my $gmetric=Ganglia::Gmetric->new;
36  
37 my $gmetric=Ganglia::Gmetric->new({name => 'some name',
38 value => 'some value',
39 units => 'm/s',
40 type => 'int16',
41 channel => 'channel',
42 port => 'port',
43 iface => 'iface',
44 ttl => 'ttl',
45 path => '/path/to/gmetric/',
46 });
47  
48 =cut
49  
50 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
51 0 my $class = shift;
52 0 my $self = $class->SUPER::new(@_);
53 0 return $self;
54 }
55 1 __PACKAGE__->mk_accessors(qw[name value type path units channel port iface ttl]);
56 1 __PACKAGE__->mk_ro_accessors(qw[command]);
57  
58 =head2 run
59  
60 $gmetric->run(\$stdout,\$stderr);
61  
62 runs the gmetric command. returns gmetric return code (0 on succes).
63  
64 =cut
65 0 ▶sub run {
Subroutine run: not called CC=7 SCAR=40.3
Pod documented
66 0 my $self = shift;
67 0 my ($stdout, $stderr)=@_;
68 0 ▶ if ($self->{path}){$gmetric=$self->{path}.$gmetric}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"path"}) 0 0 0
69 0 my $command="$gmetric -n $self->{name} -v $self->{value} -t $self->{type}";
70 0 ▶ if ($self->{units}){$command.=" -u $self->{units}"}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"units"}) 0 0 0
71 0 ▶ if ($self->{channel}){$command.=" -c $self->{channel}"}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"channel"}) 0 0 0
72 0 ▶ if ($self->{port}){$command.=" -p $self->{port}"}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"port"}) 0 0 0
73 0 ▶ if ($self->{iface}){$command.=" -i $self->{iface}"}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"iface"}) 0 0 0
74 0 ▶ if ($self->{ttl}){$command.=" -l $self->{ttl}"}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ttl"}) 0 0 0
75 0 $self->{command}=$command;
76 0 print $self->command;
77 0 ▶ capture sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 0 system($command);
79 0 } => $stdout, $stderr;
80 0 return $? >> 8;
81 }
82  
83 1 1;
84 __END__
↑ Summary