URI/gopher.pm

filter: Statementstmt 96.3% 53 / 55 Branchbran 68.1% 15 / 22 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 12 / 12 Podpod 16.6% 1 / 6 totaltotal 82.0% 82 / 100 CC 14 SCAR 15.6
CC
14
Cov
86%
_gfield
8.2
_gopher_type
6.6
gopher_type
2.0
CRAP 4.8
« URI/_ldap.pm ↑ Summary URI/file/FAT.pm »
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
BranchTrueFalseTotal
if $path =~ s/^(.)//s 7 6 13
39 13 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 12 13
40 1 my $new_type = shift;
41 1 ▶ if (defined($new_type)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new_type) { } 1 0 1
42 1 ▶ Carp::croak("Bad gopher type '$new_type'")
Branch: 1 branch
BranchTrueFalseTotal
unless length $new_type == 1 0 1 1
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
BranchTrueFalseTotal
if length $path 0 0 0
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
BranchTrueFalseTotal
unless defined $gtype 6 7 13
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
BranchTrueFalseTotal
if $path =~ s/^(.)//s 16 6 22
80 22 my @path = split(/\t/, $path, 3);
81 22 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 20 22
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
BranchTrueFalseTotal
@path and not defined $path[-1] and do { pop @path } 0 2 2
Condition33%1/3
@path and not defined $path[-1]
!ll&&!rl&&r
020
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]
ABresult
0X0
100
111
87 2 ▶ for (@path) { $_ = "" unless defined }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 3 3
88 2 $path = $gtype;
89 2 ▶ $path = "1" unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 2 2
90 2 $path .= join("\t", @path);
91 2 $self->path_query($path);
92 }
93 22 $path[$fno];
94 }
95  
96 3 1;
« URI/_ldap.pm ↑ Summary URI/file/FAT.pm »