File Coverage

blib/lib/Net/Gnats/Command/EDIT.pm
Criterion Covered Total %
statement 24 25 96.0
branch 8 10 80.0
condition n/a
subroutine 8 8 100.0
pod 2 3 66.6
total 42 46 91.3


line stmt bran cond sub pod time code
1             package Net::Gnats::Command::EDIT;
2 40     40   167 use parent 'Net::Gnats::Command';
  40         58  
  40         179  
3 40     40   2125 use strictures;
  40         60  
  40         168  
4             BEGIN {
5 40     40   3025 $Net::Gnats::Command::EDIT::VERSION = '0.20';
6             }
7 40     40   236 use vars qw($VERSION);
  40         60  
  40         1965  
8              
9 40     40   195 use Net::Gnats::Constants qw(CODE_SEND_PR CODE_OK CODE_GNATS_LOCKED CODE_NONEXISTENT_PR CODE_SEND_PR);
  40         68  
  40         8650  
10              
11             =head1 NAME
12              
13             Net::Gnats::Command::EDIT
14              
15             =head1 DESCRIPTION
16              
17             Verifies the replacement text for PR. If the command is successful,
18             the contents of PR are completely replaced with the supplied text. The
19             PR must previously have been locked with the LOCK command.
20              
21             =head1 PROTOCOL
22              
23             EDIT [PR NUMBER]
24             [PR CONTENTS]
25              
26             =head1 RESPONSES
27              
28             The possible responses are:
29              
30             431 (CODE_GNATS_LOCKED)
31              
32             The database has been locked, and no PRs may be updated until the lock
33             is cleared.
34              
35             433 (CODE_PR_NOT_LOCKED)
36              
37             The PR was not previously locked with the LOCK command.
38              
39             400 (CODE_NONEXISTENT_PR)
40              
41             The specified PR does not currently exist. The SUBM command should be
42             used to create new PRs.
43              
44             211 (CODE_SEND_PR)
45              
46             The client should now transmit the replacement PR text using the
47             normal PR quoting mechanism. After the PR has been sent, the server
48             will respond with either 200 (CODE_OK) indicating that the edit was
49             successful, or one or more error codes listing problems either with
50             the replacement PR text or errors encountered while updating the PR
51             file or index.
52              
53             =cut
54              
55             my $c = 'EDIT';
56              
57             sub new {
58 5     5 1 14 my ( $class, %options ) = @_;
59              
60 5         18 my $self = bless \%options, $class;
61 5 100       44 $self->{pr_number} = '-1' if not defined $self->{pr_number};
62 5         18 return $self;
63             }
64              
65             sub as_string {
66 8     8 1 11 my ($self) = @_;
67 8 50       20 return undef if not defined $self->{pr_number};
68 8 100       25 return undef if not defined $self->{pr};
69 6         26 return $c . ' ' . $self->{pr_number};
70             }
71              
72             sub is_ok {
73 5     5 0 5 my ($self) = @_;
74             # returned undef because command could not be run
75 5 100       18 return 0 if not defined $self->response;
76              
77 3 50       9 return 1 if $self->response->code == CODE_OK;
78 0           return 0;
79             }
80              
81              
82             1;