| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::Gnats::Command::LOCK; | 
| 2 | 40 |  |  | 40 |  | 2979 | use parent 'Net::Gnats::Command'; | 
|  | 40 |  |  |  |  | 82 |  | 
|  | 40 |  |  |  |  | 214 |  | 
| 3 | 40 |  |  | 40 |  | 2259 | use strictures; | 
|  | 40 |  |  |  |  | 60 |  | 
|  | 40 |  |  |  |  | 180 |  | 
| 4 |  |  |  |  |  |  | BEGIN { | 
| 5 | 40 |  |  | 40 |  | 3404 | $Net::Gnats::Command::LOCK::VERSION = '0.21'; | 
| 6 |  |  |  |  |  |  | } | 
| 7 | 40 |  |  | 40 |  | 224 | use vars qw($VERSION); | 
|  | 40 |  |  |  |  | 65 |  | 
|  | 40 |  |  |  |  | 2196 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 40 |  |  | 40 |  | 210 | use Net::Gnats::Constants qw(CODE_CMD_ERROR CODE_PR_READY CODE_NONEXISTENT_PR CODE_LOCKED_PR); | 
|  | 40 |  |  |  |  | 58 |  | 
|  | 40 |  |  |  |  | 10276 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 NAME | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | Net::Gnats::Command::LOCK | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | Locks the specified PR, marking the lock with the user name and the | 
| 18 |  |  |  |  |  |  | optional pid. (No checking is done that the user or pid arguments | 
| 19 |  |  |  |  |  |  | are valid or meaningful; they are simply treated as strings.) | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | The EDIT command requires that the PR be locked before it may be | 
| 22 |  |  |  |  |  |  | successfully executed. However, it does not require that the lock is | 
| 23 |  |  |  |  |  |  | owned by the editing session, so the usefulness of the lock is | 
| 24 |  |  |  |  |  |  | simply as an advisory measure. | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | The APPN and REPL commands lock the PR as part of the editing | 
| 27 |  |  |  |  |  |  | process, and they do not require that the PR be locked before they | 
| 28 |  |  |  |  |  |  | are invoked. | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =head1 PROTOCOL | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | LOCK   [pid] | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =head1 RESPONSES | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | The possible responses are: | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | 440 (CODE_CMD_ERROR) | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | Insufficient or too many arguments were specified to the command. | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | 300 (CODE_PR_READY) | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | The lock was successfully obtained; the text of the PR (using the | 
| 45 |  |  |  |  |  |  | standard quoting mechanism for PRs) follows. | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | 400 (CODE_NONEXISTENT_PR) | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | The PR specified does not exist. | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | 430 (CODE_LOCKED_PR) | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | The PR is already locked by another session. | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | 6xx (internal error) | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | The PR lock could not be created, usually because of permissions or | 
| 58 |  |  |  |  |  |  | other filesystem-related issues. | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | =cut | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | my $c = 'LOCK'; | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | sub new { | 
| 65 | 9 |  |  | 9 | 1 | 27 | my ( $class, %options ) = @_; | 
| 66 | 9 |  |  |  |  | 21 | my $self = bless \%options, $class; | 
| 67 | 9 |  |  |  |  | 24 | return $self; | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | sub as_string { | 
| 71 | 13 |  |  | 13 | 1 | 17 | my $self = shift; | 
| 72 | 13 | 100 |  |  |  | 62 | return undef if not defined $self->{pr_number}; | 
| 73 | 9 | 100 |  |  |  | 26 | return undef if not defined $self->{user}; | 
| 74 | 8 |  |  |  |  | 19 | my $command = $c . ' ' . $self->{pr_number} . ' ' . $self->{user}; | 
| 75 | 8 | 100 |  |  |  | 19 | if (defined $self->{pid}) { | 
| 76 | 2 |  |  |  |  | 5 | $command .= ' ' . $self->{pid}; | 
| 77 |  |  |  |  |  |  | } | 
| 78 | 8 |  |  |  |  | 21 | return $command; | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | sub is_ok { | 
| 82 | 9 |  |  | 9 | 0 | 12 | my $self = shift; | 
| 83 | 9 | 100 |  |  |  | 26 | return 0 if not defined $self->response; | 
| 84 | 4 | 50 |  |  |  | 12 | return 1 if $self->response->code == CODE_PR_READY; | 
| 85 | 0 |  |  |  |  |  | return 0; | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | 1; |