| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::Gnats::Command::USER; | 
| 2 | 40 |  |  | 40 |  | 203 | use parent 'Net::Gnats::Command'; | 
|  | 40 |  |  |  |  | 72 |  | 
|  | 40 |  |  |  |  | 215 |  | 
| 3 | 40 |  |  | 40 |  | 2102 | use strictures; | 
|  | 40 |  |  |  |  | 74 |  | 
|  | 40 |  |  |  |  | 212 |  | 
| 4 |  |  |  |  |  |  | BEGIN { | 
| 5 | 40 |  |  | 40 |  | 9107 | $Net::Gnats::Command::USER::VERSION = '0.22'; | 
| 6 |  |  |  |  |  |  | } | 
| 7 | 40 |  |  | 40 |  | 195 | use vars qw($VERSION); | 
|  | 40 |  |  |  |  | 65 |  | 
|  | 40 |  |  |  |  | 1528 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 40 |  |  | 40 |  | 209 | use Net::Gnats::Constants qw(CODE_INFORMATION CODE_NO_ACCESS CODE_OK); | 
|  | 40 |  |  |  |  | 95 |  | 
|  | 40 |  |  |  |  | 17335 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 NAME | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | Net::Gnats::Command::USER | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | Specifies the userid and password for database access. Either both a | 
| 18 |  |  |  |  |  |  | username and password must be specified, or they both may be | 
| 19 |  |  |  |  |  |  | omitted; in the latter case, the current access level is returned. | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | =head1 PROTOCOL | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | USER | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | =head1 RESPONSES | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | The possible server responses are: | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | 350 (CODE_INFORMATION) The current access level is specified. | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | 422 (CODE_NO_ACCESS) A matching username and password could not be | 
| 32 |  |  |  |  |  |  | found. | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | 210 (CODE_OK) A matching username and password was found, and the | 
| 35 |  |  |  |  |  |  | login was successful. | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | =cut | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | my $c = 'USER'; | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | sub new { | 
| 42 | 85 |  |  | 85 | 1 | 277 | my ( $class, %options ) = @_; | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 85 |  |  |  |  | 218 | my $self = bless \%options, $class; | 
| 45 | 85 |  |  |  |  | 438 | return $self; | 
| 46 |  |  |  |  |  |  | } | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | sub as_string { | 
| 49 | 169 |  |  | 169 | 1 | 327 | my ( $self ) = @_; | 
| 50 | 169 | 100 |  |  |  | 1050 | return $c if not defined $self->{username}; | 
| 51 | 81 | 100 |  |  |  | 398 | return undef if not defined $self->{password}; | 
| 52 | 80 |  |  |  |  | 3629 | return $c . ' ' . $self->{username} . ' ' . $self->{password}; | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | sub level { | 
| 56 | 43 |  |  | 43 | 0 | 104 | my ($self) = @_; | 
| 57 |  |  |  |  |  |  | # get response.  if username is specified, we will get a database | 
| 58 |  |  |  |  |  |  | # for the first content string.  if not specified, we simply get the | 
| 59 |  |  |  |  |  |  | # level from the second result. | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | # Examples: | 
| 62 |  |  |  |  |  |  | # USER madmin madmin | 
| 63 |  |  |  |  |  |  | # 210-Now accessing GNATS database 'default' | 
| 64 |  |  |  |  |  |  | # 210 User access level set to 'admin' | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | # user | 
| 67 |  |  |  |  |  |  | # 351-The current user access level is: | 
| 68 |  |  |  |  |  |  | # 350 admin | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 43 | 50 |  |  |  | 196 | if ( defined $self->{username} ) { | 
| 71 | 0 |  |  |  |  | 0 | $self->{db}    = @{$self->response->as_list}[0] =~ /Now accessing GNATS database '(.*)'/; | 
|  | 0 |  |  |  |  | 0 |  | 
| 72 | 0 |  |  |  |  | 0 | $self->{level} = @{$self->response->as_list}[1] =~ /User access level set to '(.*)'/; | 
|  | 0 |  |  |  |  | 0 |  | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  | else { | 
| 75 | 43 |  |  |  |  | 86 | $self->{level} = @{$self->response->as_list}[1]; | 
|  | 43 |  |  |  |  | 191 |  | 
| 76 |  |  |  |  |  |  | } | 
| 77 | 43 |  |  |  |  | 225 | return $self->{level}; | 
| 78 |  |  |  |  |  |  | } | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | sub is_ok { | 
| 81 | 156 |  |  | 156 | 0 | 270 | my ($self) = @_; | 
| 82 | 156 | 100 |  |  |  | 456 | return 0 if not defined $self->response; | 
| 83 | 155 | 50 |  |  |  | 447 | return 0 if not defined $self->response->code; | 
| 84 | 155 | 100 |  |  |  | 493 | return 0 if $self->response->code == CODE_NO_ACCESS; | 
| 85 | 154 |  |  |  |  | 752 | return 1; | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | 1; |