diff options
author | jake <jake@jakes-mail.top> | 2022-08-22 16:26:19 -0400 |
---|---|---|
committer | jake <jake@jakes-mail.top> | 2022-08-22 16:30:07 -0400 |
commit | 6f42d040891cd444443afbe6c664bc4b80884be7 (patch) | |
tree | 7f5c4158576fa0e74a06d1d46c5fd22ea5111a62 /gmi.pl | |
parent | e5fefd1500041620517b19f5c0493059f64a842b (diff) |
Reduce complexity score in listen_config()
comment out Smart::Comments
bump version
Diffstat (limited to 'gmi.pl')
-rwxr-xr-x | gmi.pl | 86 |
1 files changed, 30 insertions, 56 deletions
@@ -7,7 +7,7 @@ use warnings; use 5.010; #use diagnostics; -our $VERSION = 'v0.15.1'; +our $VERSION = 'v0.15.2'; # Modules use IO::Socket::SSL; # CPAN @@ -861,23 +861,22 @@ sub timeout_secs { } } -## no critic (Complex, DeepNest) sub listen_config { my ($conf_ref, $ssl_ref, $ip_ref) = @_; my %listen; my @default_bind; my @default_ports; - if (exists $conf_ref->{default}{bind} and $conf_ref->{default}{bind} ne 'no') { - #@default_bind = give_array($conf_ref->{default}{bind}); - push @default_bind, give_array($conf_ref->{default}{bind}); - } - elsif (exists $conf_ref->{default}{bind} and $conf_ref->{default}{bind} eq 'no') { - ; + + if (exists $conf_ref->{default}{bind}) { + if ($conf_ref->{default}{bind} ne 'no') { + push @default_bind, give_array($conf_ref->{default}{bind}); + } } else { # Listen to all push @default_bind, '::'; } + if (exists $conf_ref->{default}{ports}) { push @default_ports, give_array($conf_ref->{default}{ports}); } @@ -886,74 +885,50 @@ sub listen_config { } if (exists $conf_ref->{default}{unix} and $conf_ref->{default}{unix} ne 'no') { - #$listen{unix}{default}{path} = $conf_ref->{default}{unix}; $listen{unix}{path}{default} = $conf_ref->{default}{unix}; } for my $vhost (keys %{ $conf_ref }) { next if ($vhost eq 'default'); + my $binds; + my $ports; - # Vhost's port and vhost's bind or default's bind if (exists $conf_ref->{$vhost}{ports}) { - for my $port (give_array($conf_ref->{$vhost}{ports})) { - # Vhost has bind - if (exists $conf_ref->{$vhost}{bind} and $conf_ref->{$vhost}{bind} ne 'no') { - for my $bind (give_array($conf_ref->{$vhost}{bind})) { - push @{ $listen{$bind}{$port} }, $vhost; - } - } - elsif (exists $conf_ref->{$vhost}{bind} and $conf_ref->{$vhost}{bind} eq 'no') { - ; - } - # vhost does not have bind - use default - else { - if (@default_bind) { - for my $bind (@default_bind) { - push @{ $listen{$bind}{$port} }, $vhost; - } - } - } - } + @{ $ports } = give_array($conf_ref->{$vhost}{ports}); + } + else { + $ports = \@default_ports; } - # vhost's bind and default ports - elsif (exists $conf_ref->{$vhost}{bind}) { + + if (exists $conf_ref->{$vhost}{bind}) { if ($conf_ref->{$vhost}{bind} ne 'no') { - for my $bind (give_array($conf_ref->{$vhost}{bind})) { - for my $port (@default_ports) { - push @{ $listen{$bind}{$port} }, $vhost; - } - } - } - elsif ($conf_ref->{$vhost}{bind} eq 'no') { - ; + @{ $binds } = give_array($conf_ref->{$vhost}{bind}); } } - # vhost uses default everything else { - for my $port (@default_ports) { - for my $bind (@default_bind) { - push @{ $listen{$bind}{$port} }, $vhost; - } + $binds = \@default_bind; + } + ### $ports + ### $binds + + for my $port (give_array($ports)) { + for my $bind (give_array($binds)) { + push @{ $listen{$bind}{$port} }, $vhost; } } # check vhost unix socket otherwise check for default unix socket - if (exists $conf_ref->{$vhost}{unix}) { - for my $unix_sock_path (give_array($conf_ref->{$vhost}{unix})) { - if ($unix_sock_path ne 'no') { - $listen{unix}{path}{$vhost} = $unix_sock_path; - push @{ $listen{unix}{listen} }, $vhost; - } - } + if (exists $conf_ref->{$vhost}{unix} and $conf_ref->{$vhost}{unix} ne 'no') { + $listen{unix}{path}{$vhost} = $conf_ref->{$vhost}{unix}; + push @{ $listen{unix}{listen} }, $vhost; } - elsif (exists $listen{unix}{path}{default} and $listen{unix}{path}{default} ne 'no') { + elsif (exists $listen{unix}{path}{default}) { push @{ $listen{unix}{listen} }, $vhost; } } # ## %listen return \%listen; } -## use critic sub give_array { my ($ref) = @_; @@ -963,13 +938,13 @@ sub give_array { return @$ref; } elsif (ref $ref eq 'SCALAR') { - return ( $ref ); + return $ref; } elsif (ref \$ref eq 'ARRAY') { return @$ref; } elsif (ref \$ref eq 'SCALAR') { - return ( $ref ); + return $ref; } else { confess 'not array or scalar nor a reference to such.'; @@ -1025,7 +1000,6 @@ sub get_fh_data { sub select_add_listen { my ($sell, @srvv) = @_; for my $lsn (@srvv) { - ### $lsn ## no critic (DoubleSigil) if (exists $lsn->{LocalAddr}) { $sell->add(IO::Socket::IP->new(%$lsn)) |