| 1 | package CallBackery::GuiPlugin::Abstract; | ||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Carp qw(carp croak); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Storable qw(dclone); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Mojo::Template; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Mojo::Util qw(monkey_patch); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use CallBackery::Exception qw(mkerror); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use IPC::Open3; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use POSIX qw<F_SETFD F_GETFD FD_CLOEXEC>; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Time::HiRes qw(usleep); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Mojo::JSON qw(encode_json decode_json true false); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Mojo::File; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 17 | # disable warnings below, otherwise testing will give warnings | ||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | eval { local $^W=0; require "sys/ioctl.ph" }; | |||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||
| 22 | CallBackery::GuiPlugin::Abstract - Reporter base class | ||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||
| 26 | use Mojo::Base 'CallBackery::GuiPlugin::Abstract'; | ||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||
| 30 | The abstract base class for callbackery gui classes. | ||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | use Mojo::Base -base; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||
| 36 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||
| 38 | =head2 config | ||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||
| 40 | The Plugin instance specific config section from the master config file. | ||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||
| 42 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | has 'config'; | |||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||
| 46 | =head2 name | ||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||
| 48 | The PLUGIN instance 'name' as specified in the C<*** PLUGIN:... ***> section. | ||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||
| 50 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | has 'name'; | |||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||
| 54 | =head2 user | ||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||
| 56 | The current user object | ||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||
| 58 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | has 'user'; | |||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||
| 62 | =head2 tabName | ||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||
| 64 | What should the tab holding this plugin be called | ||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | has tabName => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | return shift->config->{'tab-name'}; | |||||||||||||||||||||||||||||||||||||||
| 70 | 1 | }; | |||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||
| 72 | =head2 instantiationMode | ||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||
| 74 | Should the plugin in the webui be instantiated immediately or only when the tab gets selected | ||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | has instantiationMode => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return 'onTabSelection'; # or onStartup | |||||||||||||||||||||||||||||||||||||||
| 80 | 1 | }; | |||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||
| 82 | =head2 grammar | ||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||
| 84 | Returns the L<Config::Grammar> parser for the configuration of this plugin. | ||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | ▶ | has grammar => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 90 | return { | ||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | _doc => 'Base class documentation string. Should be overwritten by the child class', | |||||||||||||||||||||||||||||||||||||||
| 92 | _vars => [qw(tab-name)], | ||||||||||||||||||||||||||||||||||||||||
| 93 | _mandatory => [qw(tab-name)], | ||||||||||||||||||||||||||||||||||||||||
| 94 | title => { | ||||||||||||||||||||||||||||||||||||||||
| 95 | _doc => 'Title of the Plugin Tab' | ||||||||||||||||||||||||||||||||||||||||
| 96 | }, | ||||||||||||||||||||||||||||||||||||||||
| 97 | }; | ||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | }; | |||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||
| 100 | =head2 controller | ||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||
| 102 | the current controller | ||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | has controller => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | shift->user->controller; | |||||||||||||||||||||||||||||||||||||||
| 108 | 1 | }; | |||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||
| 110 | =head2 app | ||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||
| 112 | the app object | ||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||
| 114 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | has app => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | shift->user->app; | |||||||||||||||||||||||||||||||||||||||
| 118 | 1 | }; | |||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||
| 120 | =head2 log | ||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||
| 122 | the log object | ||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||
| 124 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | has log => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | shift->app->log; | |||||||||||||||||||||||||||||||||||||||
| 128 | 1 | }; | |||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||
| 130 | =head2 args | ||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||
| 132 | some meta information provided when instantiating the plugin | ||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||
| 134 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | has 'args' => sub { {} }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||
| 138 | =head2 screenCfg | ||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||
| 140 | Returns the information for building a plugin configuration screen. | ||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | has screenCfg => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 145 | return { | ||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | type => '*unknown*', | |||||||||||||||||||||||||||||||||||||||
| 147 | options => {}, | ||||||||||||||||||||||||||||||||||||||||
| 148 | # followed by type dependent keys | ||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | }; | |||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||
| 152 | =head2 checkAccess() | ||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||
| 154 | Check if the current user may access the Plugin. Override in the Child | ||||||||||||||||||||||||||||||||||||||||
| 155 | class to limit accessibility. By default plugins are not accessible | ||||||||||||||||||||||||||||||||||||||||
| 156 | unless you have numeric UID or the word C<__CONFIG>. | ||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||
| 158 | The L<CallBackery::Command::shell> sets the userId to C<__SHELL>. If a | ||||||||||||||||||||||||||||||||||||||||
| 159 | plugin should be configurable interactively it must allow access to | ||||||||||||||||||||||||||||||||||||||||
| 160 | the C<__SHELL> user. | ||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||
| 162 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | has checkAccess => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.3
| |||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 166 | 1 | my $userId = $self->user->userId; | |||||||||||||||||||||||||||||||||||||||
| 167 | 1 | ▶ | return (defined $userId and $userId eq '__CONFIG' or $userId =~ /^\d+$/); | ||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
defined $userId && $userId eq '__CONFIG' || $userId =~ /^\d+$/u
defined $userId and $userId eq "__CONFIG"
MC/DC0%0/3
defined $userId && $userId eq '__CONFIG' || $userId =~ /^\d+$/u
defined $userId
$userId eq "__CONFIG"
$userId =~ /^\d+$/u
Truth table20%1/5
A and B || C
A= defined $userIdB= $userId eq "__CONFIG"C= $userId =~ /^\d+$/u
| |||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | }; | |||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||
| 170 | =head2 stateFiles | ||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||
| 172 | A list of files that contain the state of the settings configured by | ||||||||||||||||||||||||||||||||||||||||
| 173 | this plugin this is used both for backup purposes and to replicate the | ||||||||||||||||||||||||||||||||||||||||
| 174 | settings to a second installation. | ||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||
| 176 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | has stateFiles => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | []; | |||||||||||||||||||||||||||||||||||||||
| 180 | 1 | }; | |||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||
| 182 | =head2 unconfigureFiles | ||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||
| 184 | a list of files to be removed when 'unConfiguring' a device | ||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||
| 186 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | has unConfigureFiles => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | []; | |||||||||||||||||||||||||||||||||||||||
| 190 | 1 | }; | |||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||
| 192 | =head2 eventActions | ||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||
| 194 | A map of callbacks that will be called according to events in the | ||||||||||||||||||||||||||||||||||||||||
| 195 | system. The following events are available: | ||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||
| 197 | configChanged | ||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||
| 199 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | has eventActions => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | {}; | |||||||||||||||||||||||||||||||||||||||
| 203 | 1 | }; | |||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||
| 205 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||
| 207 | All the methods of L<Mojo::Base> plus: | ||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||
| 209 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||
| 212 | =head2 makeRxValidator(rx,error) | ||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||
| 214 | Create a regular expression base validator function. The supplied | ||||||||||||||||||||||||||||||||||||||||
| 215 | regular expression gets anchored front and back automatically. | ||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||
| 217 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | sub createRxValidator { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
createRxValidator: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 221 | 0 | my $rx = shift; | |||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $error = shift; | |||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | return undef if $value =~ /^${rx}$/; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | return $error; | |||||||||||||||||||||||||||||||||||||||
| 227 | 0 | }; | |||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||
| 230 | =head2 filterHashKey(data,key) | ||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||
| 232 | Walks a hash/array structure and removes all occurrences of the given | ||||||||||||||||||||||||||||||||||||||||
| 233 | key. | ||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||
| 235 | CODE references get turned into 'true' values and JSON true/false get | ||||||||||||||||||||||||||||||||||||||||
| 236 | passed on. | ||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||
| 238 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | sub filterHashKey { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
filterHashKey: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my $data = shift; | |||||||||||||||||||||||||||||||||||||||
| 243 | 0 | my $filterKey = shift; | |||||||||||||||||||||||||||||||||||||||
| 244 | 0 | my $ref = ref $data; | |||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | if (not $ref or $ref eq ref true){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
not $ref or $ref eq ref &true()
MC/DC0%0/2
not $ref or $ref eq ref &true()
not $ref
$ref eq ref &true()
Truth table0%0/3
not(A) or B
A= not $refB= $ref eq ref &true()
| |||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | return $data; | |||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||
| 248 | elsif ($ref eq 'CODE'){ | ||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return true; | |||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||
| 251 | elsif ($ref eq 'ARRAY'){ | ||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | return [ map { $self->filterHashKey($_,$filterKey) } @$data ]; | |||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||
| 254 | elsif ($ref eq 'HASH'){ | ||||||||||||||||||||||||||||||||||||||||
| 255 | return { | ||||||||||||||||||||||||||||||||||||||||
| 256 | map { | ||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $_ ne $filterKey | |||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | ? ( $_ => $self->filterHashKey($data->{$_},$filterKey) ) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 259 | : (); | ||||||||||||||||||||||||||||||||||||||||
| 260 | } keys %$data | ||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||
| 266 | =head2 processData(arguments) | ||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||
| 268 | Take the data from the plug-in screen and process them. | ||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||
| 270 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | sub processData { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
processData: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 274 | 0 | warn "Processing ".Dumper(\@_); | |||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||
| 277 | =head2 getData(arguments) | ||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||
| 279 | Receive current data for plug-in screen content. | ||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||
| 281 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | sub getData { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
getData: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||
| 287 | =head2 reConfigure | ||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||
| 289 | Re-generate all configuration that does not require direct user | ||||||||||||||||||||||||||||||||||||||||
| 290 | input. This function may be called from within action handlers to | ||||||||||||||||||||||||||||||||||||||||
| 291 | apply newly acquired data to to the running system. | ||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||
| 293 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | ▶ | sub reConfigure { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
reConfigure: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||
| 300 | =head2 validateData(arguments) | ||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||
| 302 | Validate user supplied data prior to acting on it. | ||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||
| 304 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | sub validateData { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
validateData: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||
| 310 | =head2 mergeGrammar | ||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||
| 312 | A very simpleminded grammar merger with no recursion. For identical | ||||||||||||||||||||||||||||||||||||||||
| 313 | keys, the later instance wins. | ||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||
| 315 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | ▶ | sub mergeGrammar { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
mergeGrammar: called CC=6 SCAR=18.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 319 | 1 | my $grammar = dclone shift; | |||||||||||||||||||||||||||||||||||||||
| 320 | 1 | my $newGrammar = shift; | |||||||||||||||||||||||||||||||||||||||
| 321 | 1 | for my $key (keys %$newGrammar){ | |||||||||||||||||||||||||||||||||||||||
| 322 | 4 | my $existing = $grammar->{$key}; | |||||||||||||||||||||||||||||||||||||||
| 323 | 4 | ▶ | my $ref = ref $existing // 'NONE'; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
ref $existing // "NONE"
MC/DC0%0/1
ref $existing // "NONE"
ref $existing
Truth table50%1/2
A
A= ref $existing
| |||||||||||||||||||||||||||||||||||||||||
| 324 | 4 | ▶ | $ref eq 'ARRAY' && do { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | push @$existing, @{$newGrammar->{$key}}; | |||||||||||||||||||||||||||||||||||||||
| 326 | 1 | next; | |||||||||||||||||||||||||||||||||||||||
| 327 | }; | ||||||||||||||||||||||||||||||||||||||||
| 328 | 3 | ▶ | $ref eq 'HASH' && do { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | for my $subKey (keys %{$newGrammar->{$key}}) { | |||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $existing->{$subKey} = $newGrammar->{$key}{$subKey}; | |||||||||||||||||||||||||||||||||||||||
| 331 | }; | ||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 333 | }; | ||||||||||||||||||||||||||||||||||||||||
| 334 | 3 | $grammar->{$key} = $newGrammar->{$key}; | |||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | return $grammar; | |||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||
| 339 | =head2 varCompiler | ||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||
| 341 | Returns a compiler sub reference for use in configuration variables or | ||||||||||||||||||||||||||||||||||||||||
| 342 | _text sections with perl syntax. The resulting sub will provide access | ||||||||||||||||||||||||||||||||||||||||
| 343 | to a hash called $variableName. | ||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||
| 345 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | sub varCompiler { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
varCompiler: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | my $code = $_[0] // ''; | ||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$_[0] // ""
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table0%0/2
A
A= $_[0]
| |||||||||||||||||||||||||||||||||||||||||
| 351 | # check and modify content in place | ||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my $perl = 'sub {'.$code.'}'; | |||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my $sub = eval $perl; ## no critic (ProhibitStringyEval) | |||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | if ($@){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | return "Failed to compile $code: $@ "; | |||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | eval { $sub->({}) }; | |||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | if ($@){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | return "Failed to run $code: $@ "; | |||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||
| 361 | # MODIFY the calling argument | ||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $_[0] = $sub; | |||||||||||||||||||||||||||||||||||||||
| 363 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 364 | 0 | }; | |||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||
| 367 | =head2 massageConfig($cfg) | ||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||
| 369 | Allow the plugin to 'massage' the config hash ... doing this requires | ||||||||||||||||||||||||||||||||||||||||
| 370 | deep knowledge of the cfg structure ... | ||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||
| 372 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | sub massageConfig { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
massageConfig: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my $cfg = shift; | |||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||
| 379 | =head2 renderTemplate(template,destination) | ||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||
| 381 | Render the given template and write the result into the given | ||||||||||||||||||||||||||||||||||||||||
| 382 | file. These templates support the L<Mojo::Template> language enhanced | ||||||||||||||||||||||||||||||||||||||||
| 383 | by the command C<L('Plugin::key')> which looks up values from the | ||||||||||||||||||||||||||||||||||||||||
| 384 | config database. The convention is that each plugin writes data in | ||||||||||||||||||||||||||||||||||||||||
| 385 | it's own namespace. | ||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||
| 387 | If the destination already exists, the method compares the current | ||||||||||||||||||||||||||||||||||||||||
| 388 | content with the new one. It will only update the file if the content | ||||||||||||||||||||||||||||||||||||||||
| 389 | differs. | ||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||
| 391 | The method returns 0 when there was no change and 1 when a new version | ||||||||||||||||||||||||||||||||||||||||
| 392 | of the file was written. | ||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||
| 394 | These additional commands are available to the templates. | ||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||
| 396 | =over | ||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||
| 398 | =item * | ||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||
| 400 | slurp(file) | ||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||
| 402 | =back | ||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||
| 404 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | has template => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 408 | 0 | my $mt = Mojo::Template->new(); | |||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | my $dbLookup = sub { $self->getConfigValue(@_) // ''}; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$self->getConfigValue(@_) // ""
MC/DC0%0/1
$self->getConfigValue(@_) // ""
$self->getConfigValue(@_)
Truth table0%0/2
A
A= $self->getConfigValue(@_)
| |||||||||||||||||||||||||||||||||||||||||
| 410 | # don't use L, use dbLookup instead | ||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | monkey_patch $mt->namespace, | |||||||||||||||||||||||||||||||||||||||
| 412 | L => $dbLookup; | ||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | monkey_patch $mt->namespace, | |||||||||||||||||||||||||||||||||||||||
| 414 | dbLookup => $dbLookup; | ||||||||||||||||||||||||||||||||||||||||
| 415 | monkey_patch $mt->namespace, | ||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | slurp => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | my $filename = shift; | |||||||||||||||||||||||||||||||||||||||
| 418 | 0 | return Mojo::File->new($filename)->slurp; | |||||||||||||||||||||||||||||||||||||||
| 419 | 0 | }; | |||||||||||||||||||||||||||||||||||||||
| 420 | monkey_patch $mt->namespace, | ||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | cfgHash => sub { $self->user->app->config->cfgHash }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 422 | monkey_patch $mt->namespace, | ||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | pluginCfg => sub { my $instance = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $self->user->app->config->cfgHash->{PLUGIN}{prototype}{$instance}->config | |||||||||||||||||||||||||||||||||||||||
| 425 | 0 | }; | |||||||||||||||||||||||||||||||||||||||
| 426 | 0 | return $mt; | |||||||||||||||||||||||||||||||||||||||
| 427 | 1 | }; | |||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | has homeDir => sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | [getpwuid $>]->[7]; | |||||||||||||||||||||||||||||||||||||||
| 432 | 1 | }; | |||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | sub renderTemplate{ | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
renderTemplate: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 436 | 0 | my $template = shift; | |||||||||||||||||||||||||||||||||||||||
| 437 | 0 | my $destination = shift; | |||||||||||||||||||||||||||||||||||||||
| 438 | 0 | $self->log->debug('['.$self->name.'] processing template '.$template); | |||||||||||||||||||||||||||||||||||||||
| 439 | 0 | my $newData = $self->template->render($self->app->home->rel_file('templates/system/'.$template)->slurp); | |||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | if (-r $destination){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my $oldData = Mojo::File->new($destination)->slurp; | |||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | if ($newData eq $oldData){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | return 0 | |||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | $self->log->debug('['.$self->name."] writing $destination\n$newData"); | |||||||||||||||||||||||||||||||||||||||
| 448 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||
| 449 | 0 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||||||||||||||
| 450 | 0 | open my $fh, '>',$destination; | |||||||||||||||||||||||||||||||||||||||
| 451 | 0 | print $fh $newData; | |||||||||||||||||||||||||||||||||||||||
| 452 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||
| 453 | }; | ||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | if ($@){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | if (blessed $@ and $@->isa('autodie::exception')){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($@) and $@->isa("autodie::exception")
MC/DC0%0/2
builtin::blessed($@) and $@->isa("autodie::exception")
builtin::blessed($@)
$@->isa("autodie::exception")
Truth table0%0/3
A and B
A= builtin::blessed($@)B= $@->isa("autodie::exception")
| |||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | $self->log->error('['.$self->name."] writing $template -> $destination: ".$@->errno); | |||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||
| 458 | else { | ||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | die $@; | |||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | if ($self->controller and $self->controller->can('runEventActions')){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->controller and $self->controller->can("runEventActions")
MC/DC0%0/2
$self->controller and $self->controller->can("runEventActions")
$self->controller
$self->controller->can("runEventActions")
Truth table0%0/3
A and B
A= $self->controllerB= $self->controller->can("runEventActions")
| |||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | $self->controller->runEventActions('changeConfig'); | |||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||
| 468 | =head2 getConfigValue(key) | ||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||
| 470 | Read a config value from the database. | ||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||
| 472 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | sub getConfigValue { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
getConfigValue: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 476 | 0 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||
| 477 | 0 | my $value = $self->user->db->getConfigValue($key); | |||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | return undef if not defined $value; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | my $ret = eval { decode_json($value) }; | |||||||||||||||||||||||||||||||||||||||
| 480 | # warn "GET $key -> ".Dumper($ret); | ||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | if ($@){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | die mkerror (3984,$@); | |||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | return $ret->[0]; | |||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||
| 487 | =head2 setConfigValue(key) | ||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||
| 489 | Save a config value to the database. | ||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||
| 491 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | sub setConfigValue { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
setConfigValue: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 495 | 0 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||
| 496 | 0 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||
| 497 | # warn "SET $key -> ".Dumper([$value]); | ||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | $self->user->db->setConfigValue($key,encode_json([$value])); | |||||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | if ($self->controller->can('runEventActions')){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | $self->controller->runEventActions('changeConfig'); | |||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||
| 505 | =head2 systemNoFd(args) | ||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||
| 507 | A version of the system function that makes sure to NOT to inherit any | ||||||||||||||||||||||||||||||||||||||||
| 508 | extra filehandles to the kids and sends the output of the call system | ||||||||||||||||||||||||||||||||||||||||
| 509 | log file. I would suggest to use this in preference to the normal | ||||||||||||||||||||||||||||||||||||||||
| 510 | system function. Especially when launching daemons since Mojo seems to | ||||||||||||||||||||||||||||||||||||||||
| 511 | fiddle with $^F and will thus inherit open sockets to child processes. | ||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||
| 513 | If the binary name starts with -, the output will be ignored ... this | ||||||||||||||||||||||||||||||||||||||||
| 514 | can be necessary for programs starting daemons that do not close their | ||||||||||||||||||||||||||||||||||||||||
| 515 | output. Otherwhise you will read the output of the daemon and NOT | ||||||||||||||||||||||||||||||||||||||||
| 516 | terminate. We are also using kill 0 to check if the process is still | ||||||||||||||||||||||||||||||||||||||||
| 517 | active. | ||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||
| 519 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | ▶ | sub systemNoFd { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
systemNoFd: not called CC=14 SCAR=52.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 523 | 0 | my $binary = shift; | |||||||||||||||||||||||||||||||||||||||
| 524 | 0 | my $logoutput = 1; | |||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | if ($binary =~ s/^-//){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | $logoutput = 0; | |||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | my $rdr; | |||||||||||||||||||||||||||||||||||||||
| 529 | my $wtr; | ||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||
| 531 | # make sure there is no inheriting any sockets | ||||||||||||||||||||||||||||||||||||||||
| 532 | # mojo should actually take care of this | ||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | for my $path (glob '/proc/self/fd/*'){ | |||||||||||||||||||||||||||||||||||||||
| 534 | 1 | ▶ | no autodie; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | ▶ | my ($fd) = $path =~ m{/proc/self/fd/(\d+)} or next; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | $fd > 3 or next; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | my $link = readlink $path or next; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | $link =~ /socket/ or next; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | ▶ | if (open my $fh, q{>&=}, int($fd)){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | $self->log->debug("Setting FIOCLEX on fd $fd ($link)"); | |||||||||||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | if (defined &FIOCLEX){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | ioctl $fh, FIOCLEX(),0; | |||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||
| 544 | elsif ($^O eq 'linux'){ | ||||||||||||||||||||||||||||||||||||||||
| 545 | # it seems we did not load the ioctl headers ... | ||||||||||||||||||||||||||||||||||||||||
| 546 | # let's try this blindly since we are on linux after all | ||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | ioctl $fh, 21585, 0; | |||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||
| 549 | else { | ||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | die "investigate this (FD_CLOEXEC) since it should work but does not!"; | |||||||||||||||||||||||||||||||||||||||
| 551 | 0 | fcntl($fh, F_SETFD, FD_CLOEXEC); | |||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | my $pid = eval { | |||||||||||||||||||||||||||||||||||||||
| 556 | 0 | open3($wtr, $rdr, undef,$binary,@_); | |||||||||||||||||||||||||||||||||||||||
| 557 | }; | ||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | my $args = join " ",@_; | |||||||||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | if ($@){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | $self->log->warn("exec '$binary $args' failed: $!"); | |||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||
| 562 | else { | ||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | $self->log->debug("running $binary($pid) $args"); | |||||||||||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | if ($logoutput){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | while (my $line = <$rdr>){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | $line =~ s/[\r\n]//g; | |||||||||||||||||||||||||||||||||||||||
| 567 | 0 | $self->log->debug("$binary($pid) out: $line"); | |||||||||||||||||||||||||||||||||||||||
| 568 | 0 | usleep 200; # give the process a chance to quit | |||||||||||||||||||||||||||||||||||||||
| 569 | 0 | ▶ | last if not kill 0,$pid; # dead yet? | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | my $ret = waitpid( $pid, 0 ); | |||||||||||||||||||||||||||||||||||||||
| 573 | 0 | $self->log->debug("running $binary($pid) done $ret"); | |||||||||||||||||||||||||||||||||||||||
| 574 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||
| 579 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||
| 580 | __END__ | ||||||||||||||||||||||||||||||||||||||||