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         2  
  1         28  
4 1     1   5 use warnings;
  1         2  
  1         39  
5              
6             our $VERSION = '5.19';
7              
8 1     1   373 use parent 'URI::_server';
  1         618  
  1         6  
9              
10 1     1   51 use URI::Escape qw(uri_unescape);
  1         2  
  1         464  
11              
12 2     2 1 3 sub default_port { 110 }
13              
14             #pop://;auth=@:
15              
16             sub user
17             {
18 7     7 0 628 my $self = shift;
19 7         18 my $old = $self->userinfo;
20              
21 7 100       17 if (@_) {
22 4         7 my $new_info = $old;
23 4 100       7 $new_info = "" unless defined $new_info;
24 4         21 $new_info =~ s/^[^;]*//;
25              
26 4         8 my $new = shift;
27 4 100 66     20 if (!defined($new) && !length($new_info)) {
28 1         3 $self->userinfo(undef);
29             } else {
30 3 50       6 $new = "" unless defined $new;
31 3         5 $new =~ s/%/%25/g;
32 3         6 $new =~ s/;/%3B/g;
33 3         10 $self->userinfo("$new$new_info");
34             }
35             }
36              
37 7 100       21 return undef unless defined $old;
38 5         10 $old =~ s/;.*//;
39 5         13 return uri_unescape($old);
40             }
41              
42             sub auth
43             {
44 5     5 0 329 my $self = shift;
45 5         13 my $old = $self->userinfo;
46              
47 5 100       12 if (@_) {
48 3         4 my $new = $old;
49 3 50       7 $new = "" unless defined $new;
50 3         9 $new =~ s/(^[^;]*)//;
51 3         6 my $user = $1;
52 3         13 $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         3 $auth =~ s/;/%3B/g;
59 2         4 $new = ";AUTH=$auth$new";
60             }
61 3         9 $self->userinfo("$user$new");
62            
63             }
64              
65 5 50       11 return undef unless defined $old;
66 5         17 $old =~ s/^[^;]*//;
67 5 100       16 return uri_unescape($1) if $old =~ /;auth=(.*)/i;
68 3         5 return;
69             }
70              
71             1;