| 1 | package RackMan::Device::PDU; | ||||||||||||||||||||
| 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 | APC_RackPDU => qr/^APC\s+AP\d+/, | ||||||||||||||||||||
| 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')
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')
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 52 | 0 | my ($hw_role) = grep { $hw_type =~ $hw_roles{$_} } keys %hw_roles; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 0 | ▶ | if ($hw_role) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||