| 1 | package Plack::Handler::Hyperman; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Hyperman (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '0.69'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 12 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | 12 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 11 | 12 | return bless { %args }, $class; | |||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 9 | ▶ | sub _parse_listen { | ||||||||||||||||||||||||||
|
Subroutine
_parse_listen: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 15 | 9 | my $spec = shift; | |||||||||||||||||||||||||||
| 16 | 9 | ▶ | return $spec if ref $spec eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 8 | ▶ | return { path => $spec } if $spec =~ m{/}; # a unix-domain socket | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 6 | ▶ | if ($spec =~ /\A\[([^\]]+)\]:(\d+)\z/) { # [::1]:8080 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 1 | return { host => $1, port => $2 + 0 }; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 5 | ▶ | if ($spec =~ /\A(.*):(\d+)\z/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 3 | ▶ | return { (length $1 ? (host => $1) : ()), port => $2 + 0 }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | 2 | ▶ | return { port => $spec + 0 } if $spec =~ /\A\d+\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 1 | die "Plack::Handler::Hyperman: cannot parse listen spec '$spec'\n"; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | my @PASS = qw(reuseport completion max_requests_per_worker shutdown_grace affinity | |||||||||||||||||||||||||||
| 29 | idle_timeout header_timeout body_timeout request_timeout body_min_rate | ||||||||||||||||||||||||||||
| 30 | max_pipeline http2 http3 http3_max_conns redirect_https | ||||||||||||||||||||||||||||
| 31 | compress compress_min_length compress_level max_body | ||||||||||||||||||||||||||||
| 32 | access_log access_log_format error_log deny_capacity rate_capacity | ||||||||||||||||||||||||||||
| 33 | user group umask pid_file listen_fds proxy_protocol | ||||||||||||||||||||||||||||
| 34 | bus_slots bus_slot_size bus_groups arena_name arena_size | ||||||||||||||||||||||||||||
| 35 | distinct_clients | ||||||||||||||||||||||||||||
| 36 | tls_cert tls_key tls_ca tls_verify tls_sni); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # The spellings other servers use for the same things, so a plackup line | ||||||||||||||||||||||||||||
| 39 | # written for one of them is not silently a plaintext server here. | ||||||||||||||||||||||||||||
| 40 | 2 | my %ALIAS = ( | |||||||||||||||||||||||||||
| 41 | ssl_cert_file => 'tls_cert', | ||||||||||||||||||||||||||||
| 42 | ssl_key_file => 'tls_key', | ||||||||||||||||||||||||||||
| 43 | ssl_cert => 'tls_cert', | ||||||||||||||||||||||||||||
| 44 | ssl_key => 'tls_key', | ||||||||||||||||||||||||||||
| 45 | ssl_ca_file => 'tls_ca', | ||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # What plackup itself hands every handler, or consumes before it does. | ||||||||||||||||||||||||||||
| 49 | 2 | my %PLACK = map { $_ => 1 } | |||||||||||||||||||||||||||
| 50 | qw(app host port socket listen listen_sock server_ready daemonize pid | ||||||||||||||||||||||||||||
| 51 | workers max_workers deny enable_ssl); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 12 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=17 SCAR=28.3
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 12 | my ($self, $app) = @_; | |||||||||||||||||||||||||||
| 55 | my %args = ( | ||||||||||||||||||||||||||||
| 56 | app => $app, | ||||||||||||||||||||||||||||
| 57 | workers => (defined $self->{workers} ? $self->{workers} | ||||||||||||||||||||||||||||
| 58 | : defined $self->{max_workers} ? $self->{max_workers} | ||||||||||||||||||||||||||||
| 59 | : 0), # 0 = ncpu | ||||||||||||||||||||||||||||
| 60 | 12 | ▶ | map { defined $self->{$_} ? ($_ => $self->{$_}) : () } @PASS, | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||
| 62 | 12 | for my $k (sort keys %ALIAS) { | |||||||||||||||||||||||||||
| 63 | 60 | ▶ | next unless defined $self->{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 5 | ▶ | $args{ $ALIAS{$k} } = $self->{$k} unless defined $args{ $ALIAS{$k} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | # Hyperman->run croaks on an option it does not know; a handler that | ||||||||||||||||||||||||||||
| 67 | # dropped one quietly turned a typo (or --enable-ssl with no files) into | ||||||||||||||||||||||||||||
| 68 | # a server that was not what was asked for. | ||||||||||||||||||||||||||||
| 69 | 12 | my %known = (map({ $_ => 1 } @PASS), %ALIAS, %PLACK); | |||||||||||||||||||||||||||
| 70 | 12 | for my $k (sort keys %$self) { | |||||||||||||||||||||||||||
| 71 | 20 | ▶ | next if $known{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 1 | warn "Plack::Handler::Hyperman: option '$k' is not one Hyperman takes; ignored\n"; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 12 | ▶ | if ($self->{enable_ssl} && !defined $args{tls_cert}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"enable_ssl"} and not defined $args{"tls_cert"}
MC/DC100%2/2
$self->{"enable_ssl"} and not defined $args{"tls_cert"}
$self->{"enable_ssl"}
not defined $args{"tls_cert"}
Truth table100%3/3
A and not(B)
A= $self->{"enable_ssl"}B= not defined $args{"tls_cert"}
| |||||||||||||||||||||||||||||
| 75 | 1 | die "Plack::Handler::Hyperman: --enable-ssl needs --ssl-cert-file and " | |||||||||||||||||||||||||||
| 76 | . "--ssl-key-file (or --tls_cert and --tls_key)\n"; | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # `deny` wants an arrayref, and plackup hands a single --deny through as | ||||||||||||||||||||||||||||
| 80 | # a plain scalar - which run() would quietly ignore, since it only reads | ||||||||||||||||||||||||||||
| 81 | # the option when it is a reference. Normalise, so one denied address | ||||||||||||||||||||||||||||
| 82 | # works the same as several. | ||||||||||||||||||||||||||||
| 83 | 11 | ▶ | if (defined $self->{deny}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | $args{deny} = ref $self->{deny} eq 'ARRAY' | ||||||||||||||||||||||||||||
| 85 | 2 | ▶ | ? $self->{deny} : [ $self->{deny} ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 11 | ▶ | if ($self->{listen} && @{ $self->{listen} }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"listen"} and @{$self->{"listen"};}
MC/DC100%2/2
$self->{"listen"} and @{$self->{"listen"};}
$self->{"listen"}
@{$self->{"listen"};}
Truth table100%3/3
A and B
A= $self->{"listen"}B= @{$self->{"listen"};}
| |||||||||||||||||||||||||||||
| 89 | 1 | $args{listen} = [ map { _parse_listen($_) } @{ $self->{listen} } ]; | |||||||||||||||||||||||||||
| 90 | } else { | ||||||||||||||||||||||||||||
| 91 | 10 | ▶ | $args{host} = defined $self->{host} ? $self->{host} : '0.0.0.0'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 10 | ▶ | $args{port} = defined $self->{port} ? $self->{port} : 8080; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 1 | ▶ | Hyperman->run(%args); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 2 | 1; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||||