File Coverage

blib/lib/Net/Gnats/Command/INPUTDEFAULT.pm
Criterion Covered Total %
statement 30 32 93.7
branch 12 14 85.7
condition 2 3 66.6
subroutine 8 8 100.0
pod 2 3 66.6
total 54 60 90.0


line stmt bran cond sub pod time code
1             package Net::Gnats::Command::INPUTDEFAULT;
2 40     40   164 use parent 'Net::Gnats::Command';
  40         54  
  40         172  
3 40     40   2080 use strictures;
  40         99  
  40         168  
4             BEGIN {
5 40     40   3513 $Net::Gnats::Command::INPUTDEFAULT::VERSION = '0.20';
6             }
7 40     40   189 use vars qw($VERSION);
  40         71  
  40         1533  
8              
9 40     40   190 use Net::Gnats::Constants qw(CODE_INFORMATION CODE_INVALID_FIELD_NAME);
  40         59  
  40         10956  
10              
11             =head1 NAME
12              
13             Net::Gnats::Command::INPUTDEFAULT
14              
15             =head1 DESCRIPTION
16              
17             Like the FDSC and FTYP commands, multiple field names may be listed
18             with the command, and a response line will be returned for each one
19             in the order that the fields appear on the command line.
20              
21             =head1 PROTOCOL
22              
23             INPUTDEFAULT [fields...]
24              
25             =head1 RESPONSES
26              
27             Returns the suggested default value for a field when a PR is
28             initially created. The possible responses are either 410
29             (CODE_INVALID_FIELD_NAME), meaning that the specified field is
30             invalid or nonexistent, or 350 (CODE_INFORMATION) which contains the
31             default value for the field.
32              
33             =cut
34              
35             my $c = 'INPUTDEFAULT';
36              
37             sub new {
38 41     41 1 288 my ( $class, %options ) = @_;
39              
40 41         150 my $self = bless \%options, $class;
41 41         187 $self->{requests_multi} = 0;
42 41 100       147 return $self if not defined $self->{fields};
43              
44 40 50       189 if (ref $self->{fields} eq 'ARRAY') {
45 40 100       55 $self->{requests_multi} = 1 if scalar @{ $self->{fields} } > 1;
  40         166  
46             }
47             else {
48 0         0 $self->{fields} = [ $self->{fields} ];
49             }
50 40         112 return $self;
51             }
52              
53             sub as_string {
54 85     85 1 126 my ($self) = @_;
55 85 100       235 return undef if not defined $self->{fields};
56 84         137 return $c . ' ' . join ( ' ', @{$self->{fields}} );
  84         536  
57             }
58              
59             # this command can take multiple fields, each getting their own response.
60             # so, we check that 'everything' is okay by looking at the parent response.
61             sub is_ok {
62 3     3 0 4 my $self = shift;
63 3 100       6 return 0 if not defined $self->response;
64 2 100 66     8 if ( $self->{requests_multi} == 0 and
65             $self->response->code == CODE_INFORMATION) {
66 1         4 return 1;
67             }
68 1 50       3 return 1 if $self->response->code == CODE_INFORMATION;
69 0           return 0;
70             }
71              
72             1;