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   178 use parent 'Net::Gnats::Command';
  40         59  
  40         211  
3 40     40   2315 use strictures;
  40         62  
  40         186  
4             BEGIN {
5 40     40   3277 $Net::Gnats::Command::EDIT::VERSION = '0.21';
6             }
7 40     40   213 use vars qw($VERSION);
  40         67  
  40         2077  
8              
9 40     40   221 use Net::Gnats::Constants qw(CODE_SEND_PR CODE_OK CODE_GNATS_LOCKED CODE_NONEXISTENT_PR CODE_SEND_PR);
  40         66  
  40         9601  
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 12 my ( $class, %options ) = @_;
59              
60 5         14 my $self = bless \%options, $class;
61 5 100       25 $self->{pr_number} = '-1' if not defined $self->{pr_number};
62 5         14 return $self;
63             }
64              
65             sub as_string {
66 8     8 1 9 my ($self) = @_;
67 8 50       19 return undef if not defined $self->{pr_number};
68 8 100       22 return undef if not defined $self->{pr};
69 6         20 return $c . ' ' . $self->{pr_number};
70             }
71              
72             sub is_ok {
73 5     5 0 6 my ($self) = @_;
74             # returned undef because command could not be run
75 5 100       20 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;