File Coverage

blib/lib/URI/_userpass.pm
Criterion Covered Total %
statement 37 38 97.3
branch 21 24 87.5
condition 2 3 66.6
subroutine 5 5 100.0
pod 0 2 0.0
total 65 72 90.2


line stmt bran cond sub pod time code
1             package URI::_userpass;
2              
3 17     17   6366 use strict;
  17         26  
  17         499  
4 17     17   69 use warnings;
  17         28  
  17         719  
5              
6 17     17   79 use URI::Escape qw(uri_unescape);
  17         34  
  17         6355  
7              
8             our $VERSION = '5.35';
9              
10             sub user
11             {
12 42     42 0 64 my $self = shift;
13 42         140 my $info = $self->userinfo;
14 42 100       79 if (@_) {
15 10         20 my $new = shift;
16 10 100       29 my $pass = defined($info) ? $info : "";
17 10         39 $pass =~ s/^[^:]*//;
18              
19 10 50 66     66 if (!defined($new) && !length($pass)) {
20 0         0 $self->userinfo(undef);
21             } else {
22 10 100       22 $new = "" unless defined($new);
23 10         20 $new =~ s/%/%25/g;
24 10         17 $new =~ s/:/%3A/g;
25 10         34 $self->userinfo("$new$pass");
26             }
27             }
28 42 100       81 return undef unless defined $info;
29 29         101 $info =~ s/:.*//;
30 29         99 uri_unescape($info);
31             }
32              
33             sub password
34             {
35 24     24 0 35 my $self = shift;
36 24         61 my $info = $self->userinfo;
37 24 100       54 if (@_) {
38 9         15 my $new = shift;
39 9 50       22 my $user = defined($info) ? $info : "";
40 9         21 $user =~ s/:.*//;
41              
42 9 100       18 if (!defined($new)) {
43 3 100       9 $self->userinfo(length $user ? $user : undef);
44             } else {
45 6 50       12 $new = "" unless defined($new);
46 6         13 $new =~ s/%/%25/g;
47 6         32 $self->userinfo("$user:$new");
48             }
49             }
50 24 100       53 return undef unless defined $info;
51 20 100       94 return undef unless $info =~ s/^[^:]*://;
52 13         37 uri_unescape($info);
53             }
54              
55             1;