File Coverage

blib/lib/Mojo/WebSocketProxy/Config.pm
Criterion Covered Total %
statement 28 28 100.0
branch 3 6 50.0
condition 5 12 41.6
subroutine 6 6 100.0
pod 3 3 100.0
total 45 55 81.8


line stmt bran cond sub pod time code
1             package Mojo::WebSocketProxy::Config;
2              
3 17     17   101 use strict;
  17         36  
  17         444  
4 17     17   74 use warnings;
  17         30  
  17         496  
5              
6 17     17   79 use Mojo::Base -base;
  17         30  
  17         91  
7              
8             our $VERSION = '0.12'; ## 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             sub init {
33 22     22 1 62 my ($self, $in_config) = @_;
34              
35 22         104 $self->{config} = {};
36 22         53 $self->{actions} = {};
37 22         49 $self->{backends} = {};
38              
39 22 50 33     97 die 'Expected a coderef for opened_connection' if $in_config->{opened_connection} && ref($in_config->{opened_connection}) ne 'CODE';
40 22 50 33     135 die 'Expected a coderef for finish_connection' if $in_config->{finish_connection} && ref($in_config->{finish_connection}) ne 'CODE';
41 22 50 33     122 die 'Expected a regex for skip_check_sanity' if $in_config->{skip_check_sanity} && ref($in_config->{skip_check_sanity}) ne 'Regexp';
42              
43 22         56 $self->{config} = $in_config;
44 22         51 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             sub add_action {
56 30     30 1 71 my ($self, $action, $order) = @_;
57 30         64 my $name = $action->[0];
58 30         50 my $options = $action->[1];
59              
60 30   66     193 $self->{actions}->{$name} ||= $options;
61 30         81 $self->{actions}->{$name}->{order} = $order;
62 30         74 $self->{actions}->{$name}->{name} = $name;
63 30         137 return;
64             }
65              
66             sub add_backend {
67 24     24 1 75 my ($self, $name, $backend) = @_;
68 24         69 $self->{backends}{$name} = $backend;
69 24         67 return;
70             }
71              
72             1;
73              
74             __END__