| 1 | package Net::Gnats::Command::USER; | ||||||||||
| 2 | 40 | ▶ | use parent 'Net::Gnats::Command'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 40 | ▶ | use strictures; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 40 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 40 | $Net::Gnats::Command::USER::VERSION = '0.22'; | |||||||||
| 6 | } | ||||||||||
| 7 | 40 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 40 | ▶ | use Net::Gnats::Constants qw(CODE_INFORMATION CODE_NO_ACCESS CODE_OK); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 <User ID> <Password> | ||||||||||
| 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 | 40 | my $c = 'USER'; | |||||||||
| 40 | |||||||||||
| 41 | 85 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 42 | 85 | my ( $class, %options ) = @_; | |||||||||
| 43 | |||||||||||
| 44 | 85 | my $self = bless \%options, $class; | |||||||||
| 45 | 85 | return $self; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 169 | ▶ | sub as_string { | ||||||||
|
Subroutine
as_string: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 49 | 169 | my ( $self ) = @_; | |||||||||
| 50 | 169 | ▶ | return $c if not defined $self->{username}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 81 | ▶ | return undef if not defined $self->{password}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 80 | return $c . ' ' . $self->{username} . ' ' . $self->{password}; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 43 | ▶ | sub level { | ||||||||
|
Subroutine
level: called CC=2 SCAR=8.7
Pod
undocumented
| |||||||||||
| 56 | 43 | 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 | ▶ | if ( defined $self->{username} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 0 | $self->{db} = @{$self->response->as_list}[0] =~ /Now accessing GNATS database '(.*)'/; | |||||||||
| 72 | 0 | $self->{level} = @{$self->response->as_list}[1] =~ /User access level set to '(.*)'/; | |||||||||
| 73 | } | ||||||||||
| 74 | else { | ||||||||||
| 75 | 43 | $self->{level} = @{$self->response->as_list}[1]; | |||||||||
| 76 | } | ||||||||||
| 77 | 43 | return $self->{level}; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 156 | ▶ | sub is_ok { | ||||||||
|
Subroutine
is_ok: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 81 | 156 | my ($self) = @_; | |||||||||
| 82 | 156 | ▶ | return 0 if not defined $self->response; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 155 | ▶ | return 0 if not defined $self->response->code; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 155 | ▶ | return 0 if $self->response->code == CODE_NO_ACCESS; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 154 | return 1; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 40 | 1; | |||||||||