| 1 | package URI::ws_Punix; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | our $VERSION=.001; | |||||||||
| 4 | 2 | 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 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 38 | |||||||||||
| 39 | 2 | ▶ | use parent q(URI::_server); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 40 | 2 | ▶ | use URI::Escape qw(uri_unescape); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | |||||||||||
| 42 | =head1 METHODS | ||||||||||
| 43 | |||||||||||
| 44 | =head2 URI::ws_Punix-E<gt>default_port | ||||||||||
| 45 | |||||||||||
| 46 | Returns the default port /tmp/unix.sock | ||||||||||
| 47 | |||||||||||
| 48 | =cut | ||||||||||
| 49 | |||||||||||
| 50 | 1 | ▶ | sub default_port { '/tmp/unix.sock' } | ||||||||
|
Subroutine
default_port: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 51 | |||||||||||
| 52 | sub _port { | ||||||||||
| 53 | 3 | ▶ | my $self=shift; | ||||||||
|
Subroutine
_port: called CC=3 SCAR=11.3
| |||||||||||
| 54 | 3 | ▶ | return $self->SUPER::_port(@_) if $#_ >-1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 2 | ▶ | if($$self=~ m,^ws+\+unix://unix%2F:?([^/]+),is) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 2 | return uri_unescape($1); | |||||||||
| 57 | } | ||||||||||
| 58 | 0 | return $self->SUPER::_port(@_); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | sub host { | ||||||||||
| 62 | 3 | ▶ | my $self=shift; | ||||||||
|
Subroutine
host: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||
| 63 | 3 | ▶ | return $self->SUPER::host('unix/') if $#_ >-1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 2 | ▶ | if($$self=~ m,^ws+\+unix://unix%2F:?.*$,is) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 2 | return 'unix/'; | |||||||||
| 66 | } | ||||||||||
| 67 | 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 | ▶ | my ($self,$scheme)=@_; | ||||||||
|
Subroutine
set_false_scheme: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 78 | |||||||||||
| 79 | 1 | $KNOWN{$self}=$scheme; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | =head2 URI::ws_Punix-E<gt>scheme | ||||||||||
| 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 | ▶ | my $self=shift; | ||||||||
|
Subroutine
scheme: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 90 | 3 | ▶ | if($#_ >-1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 1 | return $self->SUPER::scheme(@_); | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 2 | ▶ | if(exists $KNOWN{$self}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | 1 | return $KNOWN{$self}; | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | 1 | return $self->SUPER::scheme; | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | =head2 URI::ws_Punix-E<gt>secure | ||||||||||
| 102 | |||||||||||
| 103 | Returns false | ||||||||||
| 104 | |||||||||||
| 105 | =cut | ||||||||||
| 106 | |||||||||||
| 107 | 1 | ▶ | sub secure { 0 } | ||||||||
|
Subroutine
secure: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 108 | |||||||||||
| 109 | 2 | our %KNWON=(); | |||||||||
| 110 | |||||||||||
| 111 | sub DESTROY { | ||||||||||
| 112 | 3 | ▶ | my $self=shift; | ||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||
| 113 | |||||||||||
| 114 | 3 | delete $KNOWN{$self}; | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | =head1 AUTHOR | ||||||||||
| 118 | |||||||||||
| 119 | Michael Shipper <AKALINUX@CPAN.ORG> | ||||||||||
| 120 | |||||||||||
| 121 | =cut | ||||||||||
| 122 | |||||||||||
| 123 | 2 | 1; | |||||||||
| 124 | |||||||||||