| 1 | package URI::gopher; # <draft-murali-url-gopher>, Dec 4, 1996 | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | our $VERSION = '5.40'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use parent 'URI::_server'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use URI::Escape qw(uri_unescape); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # A Gopher URL follows the common internet scheme syntax as defined in | ||||||||||||||||||||||||||||
| 13 | # section 4.3 of [RFC-URL-SYNTAX]: | ||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||
| 15 | # gopher://<host>[:<port>]/<gopher-path> | ||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||
| 17 | # where | ||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||
| 19 | # <gopher-path> := <gopher-type><selector> | | ||||||||||||||||||||||||||||
| 20 | # <gopher-type><selector>%09<search> | | ||||||||||||||||||||||||||||
| 21 | # <gopher-type><selector>%09<search>%09<gopher+_string> | ||||||||||||||||||||||||||||
| 22 | # | ||||||||||||||||||||||||||||
| 23 | # <gopher-type> := '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | ||||||||||||||||||||||||||||
| 24 | # '8' | '9' | '+' | 'I' | 'g' | 'T' | ||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||
| 26 | # <selector> := *pchar Refer to RFC 1808 [4] | ||||||||||||||||||||||||||||
| 27 | # <search> := *pchar | ||||||||||||||||||||||||||||
| 28 | # <gopher+_string> := *uchar Refer to RFC 1738 [3] | ||||||||||||||||||||||||||||
| 29 | # | ||||||||||||||||||||||||||||
| 30 | # If the optional port is omitted, the port defaults to 70. | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 4 | ▶ | sub default_port {70} | ||||||||||||||||||||||||||
|
Subroutine
default_port: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 13 | ▶ | sub _gopher_type { | ||||||||||||||||||||||||||
|
Subroutine
_gopher_type: called CC=6 SCAR=18.9
| |||||||||||||||||||||||||||||
| 35 | 13 | my $self = shift; | |||||||||||||||||||||||||||
| 36 | 13 | my $path = $self->path_query; | |||||||||||||||||||||||||||
| 37 | 13 | $path =~ s,^/,,; | |||||||||||||||||||||||||||
| 38 | 13 | ▶ | my $gtype = $1 if $path =~ s/^(.)//s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 13 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 1 | my $new_type = shift; | |||||||||||||||||||||||||||
| 41 | 1 | ▶ | if (defined($new_type)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 1 | ▶ | Carp::croak("Bad gopher type '$new_type'") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | unless length($new_type) == 1; | ||||||||||||||||||||||||||||
| 44 | 1 | substr($path, 0, 0) = $new_type; | |||||||||||||||||||||||||||
| 45 | 1 | $self->path_query($path); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | else { | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | Carp::croak("Can't delete gopher type when selector is present") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | if length($path); | ||||||||||||||||||||||||||||
| 50 | 0 | $self->path_query(undef); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 13 | return $gtype; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 13 | ▶ | sub gopher_type { | ||||||||||||||||||||||||||
|
Subroutine
gopher_type: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 13 | my $self = shift; | |||||||||||||||||||||||||||
| 58 | 13 | my $gtype = $self->_gopher_type(@_); | |||||||||||||||||||||||||||
| 59 | 13 | ▶ | $gtype = "1" unless defined $gtype; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 13 | $gtype; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 5 | ▶ | sub gtype { goto &gopher_type } # URI::URL compatibility | ||||||||||||||||||||||||||
|
Subroutine
gtype: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 11 | ▶ | sub selector { shift->_gfield(0, @_) } | ||||||||||||||||||||||||||
|
Subroutine
selector: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | 10 | ▶ | sub search { shift->_gfield(1, @_) } | ||||||||||||||||||||||||||
|
Subroutine
search: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | 1 | ▶ | sub string { shift->_gfield(2, @_) } | ||||||||||||||||||||||||||
|
Subroutine
string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 22 | ▶ | sub _gfield { | ||||||||||||||||||||||||||
|
Subroutine
_gfield: called CC=8 SCAR=21.1
| |||||||||||||||||||||||||||||
| 70 | 22 | my $self = shift; | |||||||||||||||||||||||||||
| 71 | 22 | my $fno = shift; | |||||||||||||||||||||||||||
| 72 | 22 | my $path = $self->path_query; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # not according to spec., but many popular browsers accept | ||||||||||||||||||||||||||||
| 75 | # gopher URLs with a '?' before the search string. | ||||||||||||||||||||||||||||
| 76 | 22 | $path =~ s/\?/\t/; | |||||||||||||||||||||||||||
| 77 | 22 | $path = uri_unescape($path); | |||||||||||||||||||||||||||
| 78 | 22 | $path =~ s,^/,,; | |||||||||||||||||||||||||||
| 79 | 22 | ▶ | my $gtype = $1 if $path =~ s,^(.),,s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 22 | my @path = split(/\t/, $path, 3); | |||||||||||||||||||||||||||
| 81 | 22 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # modify | ||||||||||||||||||||||||||||
| 84 | 2 | my $new = shift; | |||||||||||||||||||||||||||
| 85 | 2 | $path[$fno] = $new; | |||||||||||||||||||||||||||
| 86 | 2 | ▶ | pop(@path) while @path && !defined($path[-1]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@path and not defined $path[-1]
MC/DC0%0/2
@path and not defined $path[-1]
@path
not defined $path[-1]
Truth table33%1/3
A and not(B)
A= @pathB= not defined $path[-1]
| |||||||||||||||||||||||||||||
| 87 | 2 | ▶ | for (@path) { $_ = "" unless defined } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 2 | $path = $gtype; | |||||||||||||||||||||||||||
| 89 | 2 | ▶ | $path = "1" unless defined $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 2 | $path .= join("\t", @path); | |||||||||||||||||||||||||||
| 91 | 2 | $self->path_query($path); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 22 | $path[$fno]; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 3 | 1; | |||||||||||||||||||||||||||