File Coverage

blib/lib/URI/pop.pm
Criterion Covered Total %
statement 47 47 100.0
branch 17 20 85.0
condition 2 3 66.6
subroutine 7 7 100.0
pod 1 3 33.3
total 74 80 92.5


line stmt bran cond sub pod time code
1             package URI::pop; # RFC 2384
2              
3 1     1   7 use strict;
  1         16  
  1         32  
4 1     1   5 use warnings;
  1         2  
  1         40  
5              
6             our $VERSION = '5.21';
7              
8 1     1   409 use parent 'URI::_server';
  1         306  
  1         5  
9              
10 1     1   46 use URI::Escape qw(uri_unescape);
  1         2  
  1         451  
11              
12 2     2 1 4 sub default_port { 110 }
13              
14             #pop://;auth=@:
15              
16             sub user
17             {
18 7     7 0 656 my $self = shift;
19 7         19 my $old = $self->userinfo;
20              
21 7 100       18 if (@_) {
22 4         4 my $new_info = $old;
23 4 100       9 $new_info = "" unless defined $new_info;
24 4         13 $new_info =~ s/^[^;]*//;
25              
26 4         18 my $new = shift;
27 4 100 66     18 if (!defined($new) && !length($new_info)) {
28 1         4 $self->userinfo(undef);
29             } else {
30 3 50       7 $new = "" unless defined $new;
31 3         4 $new =~ s/%/%25/g;
32 3         6 $new =~ s/;/%3B/g;
33 3         9 $self->userinfo("$new$new_info");
34             }
35             }
36              
37 7 100       16 return undef unless defined $old;
38 5         12 $old =~ s/;.*//;
39 5         11 return uri_unescape($old);
40             }
41              
42             sub auth
43             {
44 5     5 0 334 my $self = shift;
45 5         12 my $old = $self->userinfo;
46              
47 5 100       12 if (@_) {
48 3         4 my $new = $old;
49 3 50       6 $new = "" unless defined $new;
50 3         10 $new =~ s/(^[^;]*)//;
51 3         5 my $user = $1;
52 3         16 $new =~ s/;auth=[^;]*//i;
53              
54            
55 3         6 my $auth = shift;
56 3 100       7 if (defined $auth) {
57 2         3 $auth =~ s/%/%25/g;
58 2         2 $auth =~ s/;/%3B/g;
59 2         5 $new = ";AUTH=$auth$new";
60             }
61 3         9 $self->userinfo("$user$new");
62            
63             }
64              
65 5 50       9 return undef unless defined $old;
66 5         15 $old =~ s/^[^;]*//;
67 5 100       18 return uri_unescape($1) if $old =~ /;auth=(.*)/i;
68 3         8 return;
69             }
70              
71             1;