Mojo/WebSocketProxy/Config.pm

filter: Statementstmt 100% 30 / 30 Branchbran 50.0% 3 / 6 Conditioncond 41.6% 5 / 12 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 73.8% 48 / 65 CC 8 SCAR 17.5
CC
8
Cov
79%
init
9.6
add_action
2.0
BEGIN
1.0
CRAP 5.8
« Mojolicious/Plugin/WebSocketProxy.pm ↑ Summary Mojo/WebSocketProxy/Dispatcher.pm »
1 package Mojo::WebSocketProxy::Config;
2  
3 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 21 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 21 our $VERSION = '0.16'; ## VERSION
9  
10 =head1 METHODS
11  
12 =cut
13  
14 =head2 init
15  
16 Applies configuration. Supports the following config vars:
17  
18 =over 4
19  
20 =item * opened_connection - coderef which will be called when a new connection is opened
21  
22 =item * finish_connection - coderef called on connection close
23  
24 =item * skip_check_sanity - actions for which sanity checks will not be applied
25  
26 =back
27  
28 Returns an empty list.
29  
30 =cut
31  
32 25 ▶sub init {
Subroutine init: called CC=7 SCAR=22.6
Pod documented
33 25 my ($self, $in_config) = @_;
34  
35 25 $self->{config} = {};
36 25 $self->{actions} = {};
37 25 $self->{backends} = {};
38  
39 25 ▶ die 'Expected a coderef for opened_connection' if $in_config->{opened_connection} && ref($in_config->{opened_connection}) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $in_config->{"opened_connection"} and ref $in_config->{"opened_connection"} ne "CODE" 0 25 25
Condition33%1/3
$in_config->{"opened_connection"} and ref $in_config->{"opened_connection"} ne "CODE"
!ll&&!rl&&r
2500
MC/DC0%0/2
$in_config->{"opened_connection"} and ref $in_config->{"opened_connection"} ne "CODE"
$in_config->{"opened_connection"} ref $in_config->{"opened_connection"} ne "CODE"
Truth table33%1/3
A and B
A= $in_config->{"opened_connection"}B= ref $in_config->{"opened_connection"} ne "CODE"
ABresult
0X0
100
111
40 25 ▶ die 'Expected a coderef for finish_connection' if $in_config->{finish_connection} && ref($in_config->{finish_connection}) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $in_config->{"finish_connection"} and ref $in_config->{"finish_connection"} ne "CODE" 0 25 25
Condition33%1/3
$in_config->{"finish_connection"} and ref $in_config->{"finish_connection"} ne "CODE"
!ll&&!rl&&r
2500
MC/DC0%0/2
$in_config->{"finish_connection"} and ref $in_config->{"finish_connection"} ne "CODE"
$in_config->{"finish_connection"} ref $in_config->{"finish_connection"} ne "CODE"
Truth table33%1/3
A and B
A= $in_config->{"finish_connection"}B= ref $in_config->{"finish_connection"} ne "CODE"
ABresult
0X0
100
111
41 25 ▶ die 'Expected a regex for skip_check_sanity' if $in_config->{skip_check_sanity} && ref($in_config->{skip_check_sanity}) ne 'Regexp';
Branch: 1 branch
BranchTrueFalseTotal
if $in_config->{"skip_check_sanity"} and ref $in_config->{"skip_check_sanity"} ne "Regexp" 0 25 25
Condition33%1/3
$in_config->{"skip_check_sanity"} and ref $in_config->{"skip_check_sanity"} ne "Regexp"
!ll&&!rl&&r
2500
MC/DC0%0/2
$in_config->{"skip_check_sanity"} and ref $in_config->{"skip_check_sanity"} ne "Regexp"
$in_config->{"skip_check_sanity"} ref $in_config->{"skip_check_sanity"} ne "Regexp"
Truth table33%1/3
A and B
A= $in_config->{"skip_check_sanity"}B= ref $in_config->{"skip_check_sanity"} ne "Regexp"
ABresult
0X0
100
111
42  
43 25 $self->{config} = $in_config;
44 25 return;
45 }
46  
47 =head2 add_action
48  
49 Adds an action to the list of handlers.
50  
51 Expects C<$action> as an arrayref, and an C<$order> in which the action should be applied.
52  
53 =cut
54  
55 32 ▶sub add_action {
Subroutine add_action: called CC=2 SCAR=7.0
Pod documented
56 32 my ($self, $action, $order) = @_;
57 32 my $name = $action->[0];
58 32 my $options = $action->[1];
59  
60 32 ▶ $self->{actions}->{$name} ||= $options;
Condition66%2/3
$self->{"actions"}{$name} ||= $options
l!l&&r!l&&!r
01715
MC/DC50%1/2
$self->{"actions"}{$name} ||= $options
$self->{"actions"}{$name} $options
Truth table66%2/3
A ||= B
A= $self->{"actions"}{$name}B= $options
ABresult
1X1
011
000
61 32 $self->{actions}->{$name}->{order} = $order;
62 32 $self->{actions}->{$name}->{name} = $name;
63 32 return;
64 }
65  
66 26 ▶sub add_backend {
Subroutine add_backend: called CC=1 SCAR=0.0
Pod documented
67 26 my ($self, $name, $backend) = @_;
68 26 $self->{backends}{$name} = $backend;
69 26 return;
70 }
71  
72 21 1;
73  
74 __END__
« Mojolicious/Plugin/WebSocketProxy.pm ↑ Summary Mojo/WebSocketProxy/Dispatcher.pm »