| 1 | package RackMan; | ||||||||||||
| 2 | |||||||||||||
| 3 | 5 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 5 | ▶ | use Term::ANSIColor qw< :constants >; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 5 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | |||||||||||||
| 8 | 5 | our $VERSION = "1.19"; | |||||||||||
| 9 | 5 | our $STATUS = 0; | |||||||||||
| 10 | 5 | ▶ | $::COMMAND ||= __PACKAGE__; | ||||||||||
|
Condition50%1/2
$main::COMMAND ||= __PACKAGE__
MC/DC0%0/1
$main::COMMAND ||= __PACKAGE__
$main::COMMAND
Truth table50%1/2
A
A= $main::COMMAND
| |||||||||||||
| 11 | |||||||||||||
| 12 | |||||||||||||
| 13 | has config => ( | ||||||||||||
| 14 | is => "ro", | ||||||||||||
| 15 | isa => "RackMan::Config", | ||||||||||||
| 16 | 0 | ▶ | default => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 17 | 0 | require RackMan::Config; | |||||||||||
| 18 | 0 | RackMan::Config->new(-file => "/etc/rack.conf") | |||||||||||
| 19 | }, | ||||||||||||
| 20 | 5 | ); | |||||||||||
| 21 | |||||||||||||
| 22 | 5 | has options => ( | |||||||||||
| 23 | is => "ro", | ||||||||||||
| 24 | isa => "HashRef", | ||||||||||||
| 25 | ); | ||||||||||||
| 26 | |||||||||||||
| 27 | 5 | has racktables => ( | |||||||||||
| 28 | is => "ro", | ||||||||||||
| 29 | isa => "RackTables::Schema", | ||||||||||||
| 30 | lazy => 1, | ||||||||||||
| 31 | builder => "connection", | ||||||||||||
| 32 | ); | ||||||||||||
| 33 | |||||||||||||
| 34 | |||||||||||||
| 35 | # | ||||||||||||
| 36 | # connection() | ||||||||||||
| 37 | # ---------- | ||||||||||||
| 38 | 0 | ▶ | sub connection { | ||||||||||
|
Subroutine
connection: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 39 | 0 | my $self = shift; | |||||||||||
| 40 | |||||||||||||
| 41 | # check that the connection parameters are correctly set | ||||||||||||
| 42 | 0 | ▶ | my @params = $self->config->val(database => "dsn") | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | or RackMan->error("[database]/dsn is missing from the config file"); | ||||||||||||
| 44 | |||||||||||||
| 45 | push @params, map { | ||||||||||||
| 46 | 0 | my $value = $self->config->val(database => $_); | |||||||||||
| 47 | 0 | ▶ | defined $value ? $value | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | : RackMan->error("[database]/$_ is missing from the config file") | ||||||||||||
| 49 | } qw< user password >; | ||||||||||||
| 50 | |||||||||||||
| 51 | 0 | require RackTables::Schema; | |||||||||||
| 52 | 0 | return RackTables::Schema->connect(@params) | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | |||||||||||||
| 56 | # | ||||||||||||
| 57 | # device_by_id() | ||||||||||||
| 58 | # ------------ | ||||||||||||
| 59 | 0 | ▶ | sub device_by_id { | ||||||||||
|
Subroutine
device_by_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 60 | 0 | my ($self, $id) = @_; | |||||||||||
| 61 | |||||||||||||
| 62 | 0 | require RackMan::Device; | |||||||||||
| 63 | 0 | return RackMan::Device->new({ | |||||||||||
| 64 | id => $id, rackman => $self, | ||||||||||||
| 65 | racktables => $self->racktables, | ||||||||||||
| 66 | }) | ||||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | |||||||||||||
| 70 | # | ||||||||||||
| 71 | # device_by_name() | ||||||||||||
| 72 | # -------------- | ||||||||||||
| 73 | 0 | ▶ | sub device_by_name { | ||||||||||
|
Subroutine
device_by_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 74 | 0 | my ($self, $name) = @_; | |||||||||||
| 75 | |||||||||||||
| 76 | 0 | require RackMan::Device; | |||||||||||
| 77 | 0 | return RackMan::Device->new({ | |||||||||||
| 78 | name => $name, rackman => $self, | ||||||||||||
| 79 | racktables => $self->racktables, | ||||||||||||
| 80 | }) | ||||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | |||||||||||||
| 84 | # | ||||||||||||
| 85 | # device() | ||||||||||||
| 86 | # ------ | ||||||||||||
| 87 | 5 | *device = \&device_by_name; | |||||||||||
| 88 | |||||||||||||
| 89 | |||||||||||||
| 90 | # | ||||||||||||
| 91 | # process() | ||||||||||||
| 92 | # ------- | ||||||||||||
| 93 | 0 | ▶ | sub process { | ||||||||||
|
Subroutine
process: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 94 | 0 | my ($self, $action, @args) = @_; | |||||||||||
| 95 | |||||||||||||
| 96 | 0 | my %opts; | |||||||||||
| 97 | my @rest; | ||||||||||||
| 98 | |||||||||||||
| 99 | # parse task options | ||||||||||||
| 100 | 0 | ▶ | while (my $arg = shift @args) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 101 | 0 | ▶ | if ($arg eq "as") { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 102 | 0 | $opts{$arg} = shift @args; | |||||||||||
| 103 | } | ||||||||||||
| 104 | else { | ||||||||||||
| 105 | 0 | push @rest, $arg; | |||||||||||
| 106 | } | ||||||||||||
| 107 | } | ||||||||||||
| 108 | |||||||||||||
| 109 | 0 | my $name = pop @rest; | |||||||||||
| 110 | 0 | my $method = "task_$action"; | |||||||||||
| 111 | |||||||||||||
| 112 | 0 | require RackMan::Tasks; | |||||||||||
| 113 | |||||||||||||
| 114 | 0 | ▶ | RackMan->error("unknown action '$action'") | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 115 | unless RackMan::Tasks->meta->has_method($method); | ||||||||||||
| 116 | |||||||||||||
| 117 | 0 | ▶ | if ($action eq "list") { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 118 | 0 | RackMan::Tasks->$method({ rackman => $self, stdout => 1, | |||||||||||
| 119 | type => $name, %opts }); | ||||||||||||
| 120 | } | ||||||||||||
| 121 | else { | ||||||||||||
| 122 | 0 | my $object = $self->device($name); | |||||||||||
| 123 | 0 | $self->config->set_current_rackobject($object); | |||||||||||
| 124 | 0 | RackMan::Tasks->meta->apply($object); | |||||||||||
| 125 | 0 | $object->$method({ rackman => $self, stdout => 1, %opts }); | |||||||||||
| 126 | } | ||||||||||||
| 127 | } | ||||||||||||
| 128 | |||||||||||||
| 129 | |||||||||||||
| 130 | # | ||||||||||||
| 131 | # get_scm() | ||||||||||||
| 132 | # ------- | ||||||||||||
| 133 | 0 | ▶ | sub get_scm { | ||||||||||
|
Subroutine
get_scm: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 134 | 0 | my ($self, $args) = @_; | |||||||||||
| 135 | |||||||||||||
| 136 | 0 | my $type = "none"; | |||||||||||
| 137 | 0 | my $caller = caller(); | |||||||||||
| 138 | |||||||||||||
| 139 | 0 | ▶ | if ($self->options->{scm}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 140 | # global default SCM tool | ||||||||||||
| 141 | 0 | my $default = $self->config->val(general => "default_scm", "none"); | |||||||||||
| 142 | |||||||||||||
| 143 | # check if the caller has its own configuration section | ||||||||||||
| 144 | 0 | ▶ | if ($caller->can("CONFIG_SECTION")) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 145 | 0 | my $section = $caller->CONFIG_SECTION; | |||||||||||
| 146 | 0 | $type = $self->config->val($section, "scm", $default); | |||||||||||
| 147 | } | ||||||||||||
| 148 | } | ||||||||||||
| 149 | |||||||||||||
| 150 | # clean leading and trailing spaces | ||||||||||||
| 151 | 0 | $type =~ s/^ +| +$//g; | |||||||||||
| 152 | |||||||||||||
| 153 | 0 | require RackMan::SCM; | |||||||||||
| 154 | return RackMan::SCM->new({ type => $type, %$args, | ||||||||||||
| 155 | 0 | verbose => $self->options->{verbose}, prefix => " x " }) | |||||||||||
| 156 | } | ||||||||||||
| 157 | |||||||||||||
| 158 | |||||||||||||
| 159 | # | ||||||||||||
| 160 | # warning() | ||||||||||||
| 161 | # ------- | ||||||||||||
| 162 | 0 | ▶ | sub warning { | ||||||||||
|
Subroutine
warning: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 163 | 0 | my $class = shift; | |||||||||||
| 164 | 0 | warn "$::COMMAND: ", BOLD(YELLOW("warning: ")), @_, RESET, "\n"; | |||||||||||
| 165 | } | ||||||||||||
| 166 | |||||||||||||
| 167 | |||||||||||||
| 168 | # | ||||||||||||
| 169 | # error() | ||||||||||||
| 170 | # ----- | ||||||||||||
| 171 | 0 | ▶ | sub error { | ||||||||||
|
Subroutine
error: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 172 | 0 | my $class = shift; | |||||||||||
| 173 | 0 | warn "$::COMMAND: ", BOLD(RED("error: ")), @_, RESET, "\n"; | |||||||||||
| 174 | 0 | ▶ | exit ($STATUS || 1); | ||||||||||
|
Condition0%0/2
$RackMan::STATUS || 1
MC/DC0%0/1
$RackMan::STATUS || 1
$RackMan::STATUS
Truth table0%0/2
A
A= $RackMan::STATUS
| |||||||||||||
| 175 | } | ||||||||||||
| 176 | |||||||||||||
| 177 | |||||||||||||
| 178 | # | ||||||||||||
| 179 | # error_n() | ||||||||||||
| 180 | # ------- | ||||||||||||
| 181 | 0 | ▶ | sub error_n { | ||||||||||
|
Subroutine
error_n: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 182 | 0 | print STDERR "\n"; | |||||||||||
| 183 | 0 | goto &error; | |||||||||||
| 184 | } | ||||||||||||
| 185 | |||||||||||||
| 186 | |||||||||||||
| 187 | # | ||||||||||||
| 188 | # status() | ||||||||||||
| 189 | # ------ | ||||||||||||
| 190 | 0 | ▶ | sub status { | ||||||||||
|
Subroutine
status: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 191 | 0 | return $STATUS | |||||||||||
| 192 | } | ||||||||||||
| 193 | |||||||||||||
| 194 | |||||||||||||
| 195 | # | ||||||||||||
| 196 | # set_status() | ||||||||||||
| 197 | # ---------- | ||||||||||||
| 198 | 0 | ▶ | sub set_status { | ||||||||||
|
Subroutine
set_status: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 199 | 0 | $STATUS = $_[1]; | |||||||||||
| 200 | } | ||||||||||||
| 201 | |||||||||||||
| 202 | |||||||||||||
| 203 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 204 | |||||||||||||
| 205 | __END__ | ||||||||||||