blib/lib/Lemonldap/NG/Manager/Plugin.pm

filter: Statementstmt 65.2% 47 / 72 Branchbran 22.2% 4 / 18 Conditioncond 25.0% 3 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 81.2% 13 / 16 Podpod 0.0% 0 / 5 totaltotal 51.1% 67 / 131 CC 14 SCAR 33.4
CC
14
Cov
53%
applyConf
66.2
__ANON__
2.3
addRoute
2.2
CRAP 28.3
« blib/lib/Lemonldap/NG/Manager/Conf/Diff.pm ↑ Summary blib/lib/Lemonldap/NG/Manager.pm »
1 package Lemonldap::NG::Manager::Plugin;
2  
3 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 28 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 28 ▶use Lemonldap::NG::Common::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 28 ▶use Lemonldap::NG::Common::Conf::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 28 ▶use URI::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 28 our $VERSION = '2.18.0';
10  
11 28 extends 'Lemonldap::NG::Common::Module';
12  
13 has _confAcc => (
14 is => 'rw',
15 lazy => 1,
16 36 ▶ default => sub { return $_[0]->p->{_confAcc} },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 28 );
18  
19 has ua => (
20 is => 'rw',
21 lazy => 1,
22 0 ▶ builder => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 0 Lemonldap::NG::Common::UserAgent->new( $_[0]->{conf} );
24 }
25 28 );
26  
27 # Icon from https://www.w3schools.com/icons/bootstrap_icons_glyphicons.asp
28 28 ▶use constant icon => 'wrench';
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 101 ▶sub sendError {
Subroutine sendError: called CC=1 SCAR=0.0
Pod undocumented
31 101 my $self = shift;
32 101 return $self->p->sendError(@_);
33 }
34  
35 432 ▶sub sendJSONresponse {
Subroutine sendJSONresponse: called CC=1 SCAR=0.0
Pod undocumented
36 432 my $self = shift;
37 432 return $self->p->sendJSONresponse(@_);
38 }
39  
40 1393 ▶sub addRoute {
Subroutine addRoute: called CC=2 SCAR=7.8
Pod undocumented
41 1393 my ( $self, $word, $subName, $methods, $transform ) = @_;
42 4296 ▶ $transform //= sub {
Subroutine __ANON__: called CC=2 SCAR=8.1
43 4296 my ($sub) = @_;
44 4296 ▶ if ( ref $sub ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sub) { } 0 4296 4296
45 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 0 shift;
47 0 return $sub->( $self, @_ );
48 }
49 0 }
50 else {
51 534 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
52 534 shift;
53 534 return $self->$sub(@_);
54 }
55 4296 }
56 1393 ▶ };
Condition33%1/3
$transform //= sub { my($sub) = @_; if (ref $sub) { return sub { shift(); return &$sub($self, @_); } ; } else { return sub { shift(); return $self->$sub(@_); } ; } ; }
l!l&&r!l&&!r
013930
MC/DC0%0/2
$transform //= sub { my($sub) = @_; if (ref $sub) { return sub { shift(); return &$sub($self, @_); } ; } else { return sub { shift(); return $self->$sub(@_); } ; } ; }
$transform sub { my($sub) = @_; if (ref $sub) { return sub { shift(); return &$sub($self, @_); } ; } else { return sub { shift(); return $self->$sub(@_); } ; } ; }
Truth table33%1/3
A //= B
A= $transformB= sub { my($sub) = @_; if (ref $sub) { return sub { shift(); return &$sub($self, @_); } ; } else { return sub { shift(); return $self->$sub(@_); } ; } ; }
ABresult
1X1
011
000
57 1393 $self->p->addRoute( $word, $subName, $methods, $transform );
58 1393 return $self;
59 }
60  
61 0 ▶sub loadTemplate {
Subroutine loadTemplate: not called CC=1 SCAR=6.9
Pod undocumented
62 0 my $self = shift;
63 0 return $self->p->loadTemplate(@_);
64 }
65  
66 ## @method private applyConf()
67 # Try to inform other servers declared in `reloadUrls` that a new
68 # configuration is available.
69 #
70 #@return reload status as boolean
71 50 ▶sub applyConf {
Subroutine applyConf: called CC=12 SCAR=41.9
Pod undocumented
72 50 my ( $self, $newConf ) = @_;
73 return
74 unless $self->p->api->tsv->{msgBrokerWriter}
75 50 ▶ and ref( $self->p->api->tsv->{msgBrokerWriter} ) =~ /NoBroker$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->p->api->tsv->{"msgBrokerWriter"} and ref($self->p->api->tsv->{"msgBrokerWriter"}) =~ /NoBroker$/ 0 50 50
Condition33%1/3
$self->p->api->tsv->{"msgBrokerWriter"} and ref($self->p->api->tsv->{"msgBrokerWriter"}) =~ /NoBroker$/
!ll&&!rl&&r
0050
MC/DC0%0/2
$self->p->api->tsv->{"msgBrokerWriter"} and ref($self->p->api->tsv->{"msgBrokerWriter"}) =~ /NoBroker$/
$self->p->api->tsv->{"msgBrokerWriter"} ref($self->p->api->tsv->{"msgBrokerWriter"}) =~ /NoBroker$/
Truth table33%1/3
A and B
A= $self->p->api->tsv->{"msgBrokerWriter"}B= ref($self->p->api->tsv->{"msgBrokerWriter"}) =~ /NoBroker$/
ABresult
0X0
100
111
76  
77 50 my $status;
78  
79 # 1 Apply conf locally
80 50 $self->p->api->checkConf();
81  
82 # Get apply section values
83 my %reloadUrls =
84 50 %{ $self->confAcc->getLocalConf( APPLYSECTION, undef, 0 ) };
85 50 ▶ if ( !%reloadUrls && $newConf->{reloadUrls} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %reloadUrls and $newConf->{"reloadUrls"}) 50 0 50
Condition33%1/3
not %reloadUrls and $newConf->{"reloadUrls"}
!ll&&!rl&&r
0050
MC/DC0%0/2
not %reloadUrls and $newConf->{"reloadUrls"}
not %reloadUrls $newConf->{"reloadUrls"}
Truth table33%1/3
not(A) and B
A= not %reloadUrlsB= $newConf->{"reloadUrls"}
ABresult
0X0
100
111
86 50 %reloadUrls = %{ $newConf->{reloadUrls} };
87 }
88 50 ▶ return {} unless (%reloadUrls);
Branch: 1 branch
BranchTrueFalseTotal
unless %reloadUrls 50 0 50
89  
90 0 $self->ua->timeout( $newConf->{reloadTimeout} );
91  
92 # Parse apply values
93 0 ▶ while ( my ( $host, $request ) = each %reloadUrls ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %reloadUrls) 0 0 0
94 0 my $r = HTTP::Request->new( 'GET', "http://$host$request" );
95 0 $self->logger->debug("Sending reload request to $host");
96 0 ▶ if ( $request =~ /^https?:\/\/[^\/]+.*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request =~ m[^https?://[^/]+.*$]) 0 0 0
97 0 my $url = URI::URL->new($request);
98 0 my $targetUrl = $url->scheme . "://" . $host;
99 0 ▶ $targetUrl .= ":" . $url->port if defined( $url->port );
Branch: 1 branch
BranchTrueFalseTotal
if defined $url->port 0 0 0
100 0 $targetUrl .= $url->full_path;
101 0 $r =
102 HTTP::Request->new( 'GET', $targetUrl,
103 HTTP::Headers->new( Host => $url->host ) );
104 0 ▶ if ( defined $url->userinfo
Branch: 1 branch
BranchTrueFalseTotal
if (defined $url->userinfo and $url->userinfo =~ /^([^:]+):(.*)$/) 0 0 0
Condition0%0/3
defined $url->userinfo and $url->userinfo =~ /^([^:]+):(.*)$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $url->userinfo and $url->userinfo =~ /^([^:]+):(.*)$/
defined $url->userinfo $url->userinfo =~ /^([^:]+):(.*)$/
Truth table0%0/3
A and B
A= defined $url->userinfoB= $url->userinfo =~ /^([^:]+):(.*)$/
ABresult
0X0
100
111
105 && $url->userinfo =~ /^([^:]+):(.*)$/ )
106 {
107 0 $r->authorization_basic( $1, $2 );
108 }
109 }
110  
111 0 my $response = $self->ua->request($r);
112 0 ▶ if ( $response->code != 200 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->code != 200) { } 0 0 0
113 0 $status->{$host} =
114 "Error " . $response->code . " (" . $response->message . ")";
115 0 $self->logger->error( "Apply configuration for $host: error "
116 . $response->code . " ("
117 . $response->message
118 . ")" );
119 }
120 else {
121 0 $status->{$host} = "OK";
122 0 $self->logger->notice("Apply configuration for $host: ok");
123 }
124 }
125  
126 0 return $status;
127 }
128  
129 28 1;
« blib/lib/Lemonldap/NG/Manager/Conf/Diff.pm ↑ Summary blib/lib/Lemonldap/NG/Manager.pm »