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