File Coverage

blib/lib/Net/Gnats/Command/LOCK.pm
Criterion Covered Total %
statement 26 27 96.3
branch 9 10 90.0
condition n/a
subroutine 8 8 100.0
pod 2 3 66.6
total 45 48 93.7


line stmt bran cond sub pod time code
1             package Net::Gnats::Command::LOCK;
2 40     40   2525 use parent 'Net::Gnats::Command';
  40         72  
  40         183  
3 40     40   2078 use strictures;
  40         47  
  40         160  
4             BEGIN {
5 40     40   2827 $Net::Gnats::Command::LOCK::VERSION = '0.20';
6             }
7 40     40   173 use vars qw($VERSION);
  40         53  
  40         1508  
8              
9 40     40   177 use Net::Gnats::Constants qw(CODE_CMD_ERROR CODE_PR_READY CODE_NONEXISTENT_PR CODE_LOCKED_PR);
  40         62  
  40         9133  
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 21 my ( $class, %options ) = @_;
66 9         16 my $self = bless \%options, $class;
67 9         19 return $self;
68             }
69              
70             sub as_string {
71 13     13 1 14 my $self = shift;
72 13 100       62 return undef if not defined $self->{pr_number};
73 9 100       23 return undef if not defined $self->{user};
74 8         22 my $command = $c . ' ' . $self->{pr_number} . ' ' . $self->{user};
75 8 100       21 if (defined $self->{pid}) {
76 2         3 $command .= ' ' . $self->{pid};
77             }
78 8         24 return $command;
79             }
80              
81             sub is_ok {
82 9     9 0 10 my $self = shift;
83 9 100       24 return 0 if not defined $self->response;
84 4 50       10 return 1 if $self->response->code == CODE_PR_READY;
85 0           return 0;
86             }
87              
88             1;