blib/lib/RackMan/Device/Switch.pm

filter: Statementstmt 54.0% 20 / 37 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 6 / 8 Podpod 100% 2 / 2 totaltotal 48.2% 28 / 58 CC 5 SCAR 21.0
CC
5
Cov
43%
specialise
20.0
formats
6.0
BEGIN
1.0
CRAP 8.2
« blib/lib/RackMan/Device/PDU.pm ↑ Summary blib/lib/RackMan/Device/Server.pm »
1 package RackMan::Device::Switch;
2  
3 2 ▶use Module::Runtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use RackMan;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 2 ▶use constant HW_ROLES => (
Subroutine BEGIN: called CC=1 SCAR=0.0
10 Cisco_Catalyst => qr/^Cisco\s+Catalyst/,
11 2 );
12  
13 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 CONFIG_SECTION => "device:server",
15 DEFAULT_FORMATS => "Cacti Nagios",
16 2 };
17  
18  
19 2 has class => (
20 is => "rw",
21 isa => "Str",
22 );
23  
24  
25 #
26 # formats()
27 # -------
28 0 ▶sub formats {
Subroutine formats: not called CC=2 SCAR=17.9
Pod documented
29 0 my ($self) = @_;
30  
31 # fetch the list of formats for this type
32 0 my $rackman = $self->rackman;
33 my @formats = split / *,? +/, $rackman->options->{formats}
34 0 ▶ || $rackman->config->val(CONFIG_SECTION, "formats", DEFAULT_FORMATS);
Condition0%0/3
$rackman->options->{'formats'} || $rackman->config->val('device:server', 'formats', 'Cacti Nagios')
l!l&&r!l&&!r
000
MC/DC0%0/2
$rackman->options->{'formats'} || $rackman->config->val('device:server', 'formats', 'Cacti Nagios')
$rackman->options->{'formats'} $rackman->config->val('device:server', 'formats', 'Cacti Nagios')
Truth table0%0/3
A || B
A= $rackman->options->{'formats'}B= $rackman->config->val('device:server', 'formats', 'Cacti Nagios')
ABresult
1X1
011
000
35  
36 return @formats
37 0 }
38  
39  
40 #
41 # specialise()
42 # ----------
43 0 ▶sub specialise {
Subroutine specialise: not called CC=4 SCAR=30.0
Pod documented
44 0 my $self = shift;
45  
46 # fetch the sub-roles patterns
47 0 my %hw_roles = eval { $self->HW_ROLES };
48  
49 # determine the role corresponding to the hardware
50 0 my $hw_type = $self->attributes->{"HW type"};
51 0 ▶ return unless $hw_type;
Branch: 1 branch
BranchTrueFalseTotal
unless $hw_type 0 0 0
52 0 my ($hw_role) = grep { $hw_type =~ $hw_roles{$_} } keys %hw_roles;
53  
54 0 ▶ if ($hw_role) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hw_role) 0 0 0
55 # load and apply the role to the object
56 0 $hw_role = __PACKAGE__."::$hw_role";
57 0 $self->class($hw_role);
58 0 ▶ eval { Module::Runtime::require_module($hw_role) }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &Module::Runtime::require_module($hw_role) } } or "RackMan"->error("can't load ${hw_role}: $@") 0 0 0
59 or RackMan->error("can't load $hw_role: $@");
60 0 $hw_role->meta->apply($self);
61 }
62 }
63  
64  
65 2 __PACKAGE__
66  
67 __END__
« blib/lib/RackMan/Device/PDU.pm ↑ Summary blib/lib/RackMan/Device/Server.pm »