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   105 use strict;
  17         34  
  17         478  
4 17     17   86 use warnings;
  17         49  
  17         474  
5              
6 17     17   83 use Mojo::Base -base;
  17         27  
  17         100  
7              
8             our $VERSION = '0.13'; ## 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 53 my ($self, $in_config) = @_;
34              
35 22         113 $self->{config} = {};
36 22         60 $self->{actions} = {};
37 22         40 $self->{backends} = {};
38              
39 22 50 33     94 die 'Expected a coderef for opened_connection' if $in_config->{opened_connection} && ref($in_config->{opened_connection}) ne 'CODE';
40 22 50 33     121 die 'Expected a coderef for finish_connection' if $in_config->{finish_connection} && ref($in_config->{finish_connection}) ne 'CODE';
41 22 50 33     86 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         49 $self->{config} = $in_config;
44 22         48 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 67 my ($self, $action, $order) = @_;
57 30         60 my $name = $action->[0];
58 30         105 my $options = $action->[1];
59              
60 30   66     183 $self->{actions}->{$name} ||= $options;
61 30         76 $self->{actions}->{$name}->{order} = $order;
62 30         64 $self->{actions}->{$name}->{name} = $name;
63 30         95 return;
64             }
65              
66             sub add_backend {
67 24     24 1 58 my ($self, $name, $backend) = @_;
68 24         58 $self->{backends}{$name} = $backend;
69 24         69 return;
70             }
71              
72             1;
73              
74             __END__