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   254 use parent 'Net::Gnats::Command';
  40         2550  
  40         239  
3 40     40   2102 use strictures;
  40         65  
  40         205  
4             BEGIN {
5 40     40   8859 $Net::Gnats::Command::LOCK::VERSION = '0.22';
6             }
7 40     40   280 use vars qw($VERSION);
  40         65  
  40         1655  
8              
9 40     40   199 use Net::Gnats::Constants qw(CODE_CMD_ERROR CODE_PR_READY CODE_NONEXISTENT_PR CODE_LOCKED_PR);
  40         64  
  40         11533  
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 28 my ( $class, %options ) = @_;
66 9         17 my $self = bless \%options, $class;
67 9         27 return $self;
68             }
69              
70             sub as_string {
71 13     13 1 21 my $self = shift;
72 13 100       67 return undef if not defined $self->{pr_number};
73 9 100       26 return undef if not defined $self->{user};
74 8         29 my $command = $c . ' ' . $self->{pr_number} . ' ' . $self->{user};
75 8 100       24 if (defined $self->{pid}) {
76 2         4 $command .= ' ' . $self->{pid};
77             }
78 8         29 return $command;
79             }
80              
81             sub is_ok {
82 9     9 0 14 my $self = shift;
83 9 100       32 return 0 if not defined $self->response;
84 4 50       14 return 1 if $self->response->code == CODE_PR_READY;
85 0           return 0;
86             }
87              
88             1;