File Coverage

blib/lib/URI/ws_Punix.pm
Criterion Covered Total %
statement 32 34 94.1
branch 10 12 83.3
condition n/a
subroutine 11 11 100.0
pod 5 5 100.0
total 58 62 93.5


line stmt bran cond sub pod time code
1             package URI::ws_Punix;
2              
3             our $VERSION=.001;
4             our %KNOWN;
5              
6             =head1 NAME
7              
8             URI::ws_Punix - URI for ws+unix
9              
10             =head1 SYNOPSIS
11              
12             use URI;
13             my $url='ws+unix://unix%2F:%2Ftest%2Fsocket.sock/testing';
14              
15             my $uri=new URI($url);
16              
17             # will output: ws+unix
18             print $uri->scheme,"\n";
19              
20             # will output: unix/
21             print $uri->host,"\n";
22              
23             # will output: /test/socket.sock
24             print $uri->port
25              
26             # some classes don't yet understand the scheme ws+unix, so here is a work around
27             $uri->set_false_scheme('ws');
28             print $uri->scheme,"\n"; # now prints "ws"
29              
30             =head1 DESCRIPTION
31              
32             This class acts as a parser layer for URI, and adds support for handling the rare WebSocket URI using a "Unix Domain Socket. The scheme expected is "ws+unix". Since most modules don't understand this just yet, the fake scheme or $uri->set_false_scheme('ws') was added.
33              
34             =cut
35              
36 2     2   1316 use strict;
  2         4  
  2         59  
37 2     2   10 use warnings;
  2         4  
  2         53  
38              
39 2     2   836 use parent q(URI::_server);
  2         616  
  2         13  
40 2     2   17390 use URI::Escape qw(uri_unescape);
  2         5  
  2         738  
41              
42             =head1 METHODS
43              
44             =head2 URI::ws_Punix-Edefault_port
45              
46             Returns the default port /tmp/unix.sock
47              
48             =cut
49              
50 1     1 1 83 sub default_port { '/tmp/unix.sock' }
51              
52             sub _port {
53 3     3   16 my $self=shift;
54 3 100       13 return $self->SUPER::_port(@_) if $#_ >-1;
55 2 50       13 if($$self=~ m,^ws+\+unix://unix%2F:?([^/]+),is) {
56 2         6 return uri_unescape($1);
57             }
58 0         0 return $self->SUPER::_port(@_);
59             }
60              
61             sub host {
62 3     3 1 1363 my $self=shift;
63 3 100       16 return $self->SUPER::host('unix/') if $#_ >-1;
64 2 50       15 if($$self=~ m,^ws+\+unix://unix%2F:?.*$,is) {
65 2         10 return 'unix/';
66             }
67 0         0 return $self->SUPER::host(@_);
68             }
69              
70             =head2 $uri->set_false_scheme('ws')
71              
72             Used to overload the default behavior.. sometimes you may want to say "ws" in place of "ws+unix". Some modules expect ws, this method lets you overload the default of $uri->scheme.
73              
74             =cut
75              
76             sub set_false_scheme {
77 1     1 1 183 my ($self,$scheme)=@_;
78              
79 1         55 $KNOWN{$self}=$scheme;
80             }
81              
82             =head2 URI::ws_Punix-Escheme
83              
84             Normally follows the defaults unless $uri->set_false_scheme('value') was called on this instance.
85              
86             =cut
87              
88             sub scheme {
89 3     3 1 579 my $self=shift;
90 3 100       12 if($#_ >-1) {
91 1         5 return $self->SUPER::scheme(@_);
92             }
93              
94 2 100       5 if(exists $KNOWN{$self}) {
95 1         7 return $KNOWN{$self};
96             }
97              
98 1         9 return $self->SUPER::scheme;
99             }
100              
101             =head2 URI::ws_Punix-Esecure
102              
103             Returns false
104              
105             =cut
106              
107 1     1 1 952 sub secure { 0 }
108              
109             our %KNWON=();
110              
111             sub DESTROY {
112 3     3   1559 my $self=shift;
113              
114 3         10 delete $KNOWN{$self};
115             }
116              
117             =head1 AUTHOR
118              
119             Michael Shipper
120              
121             =cut
122              
123             1;
124