File Coverage

blib/lib/Net/Gnats/Command/LIST.pm
Criterion Covered Total %
statement 36 37 97.3
branch 6 10 60.0
condition n/a
subroutine 9 9 100.0
pod 2 4 50.0
total 53 60 88.3


line stmt bran cond sub pod time code
1             package Net::Gnats::Command::LIST;
2 40     40   164 use parent 'Net::Gnats::Command';
  40         54  
  40         179  
3 40     40   2022 use strictures;
  40         48  
  40         273  
4             BEGIN {
5 40     40   2895 $Net::Gnats::Command::LIST::VERSION = '0.20';
6             }
7 40     40   248 use vars qw($VERSION);
  40         59  
  40         1578  
8              
9 40     40   181 use Net::Gnats::Constants qw(CODE_TEXT_READY CODE_INVALID_LIST);
  40         59  
  40         14274  
10              
11             =head1 NAME
12              
13             Net::Gnats::Command::LIST
14              
15             =head1 DESCRIPTION
16              
17              
18             Describes various aspects of the database. The lists are returned as
19             a list of records, one per line. Each line may contain a number of
20             colon-separated fields.
21              
22             Possible values for list type include
23              
24             Categories : Describes the legal categories for the database.
25              
26             Submitters : Describes the set of submitters for the database.
27              
28             Responsible : Lists the names in the responsible administrative
29             file, including their full names and email addresses.
30              
31             States
32              
33             Lists the states listed in the state administrative file, including
34             the state type (usually blank for most states; the closed state has
35             a special type).
36              
37             FieldNames Lists the entire set of PR fields.
38              
39             InitialInputFields : Lists the fields that should be present when a
40             PR is initially entered.
41              
42             InitialRequiredFields : Lists fields that have to be present and
43             nonempty when a PR is initially entered (fields containing only
44             blank characters such as spaces or newlines are considered empty.)
45              
46             Databases : Lists the set of databases.
47              
48             =head1 PROTOCOL
49              
50             LIST [list type]
51              
52             =head1 RESPONSES
53              
54             The possible responses are:
55              
56             301 (CODE_TEXT_READY) Normal response, followed by the records
57             making up the list as described above.
58              
59             416 (CODE_INVALID_LIST) The requested list does not exist.
60              
61             =cut
62              
63             my $c = 'LIST';
64              
65             my $s = { databases => ['name', 'desc', 'path'],
66             categories => ['name', 'desc', 'contact', 'notify'],
67             submitters => ['name', 'desc', 'contract', 'response',
68             'contact', 'othernotify'],
69             responsible => ['name', 'realname', 'email'],
70             states => ['name', 'type', 'desc'],
71             };
72              
73             sub new {
74 133     133 1 351 my ( $class, %options ) = @_;
75 133         327 my $self = bless \%options, $class;
76 133         329 return $self;
77             }
78              
79             sub as_string {
80 279     279 1 289 my $self = shift;
81 279 100       817 return undef if not defined $self->{subcommand};
82 277         899 return $c . ' ' . $self->{subcommand};
83             }
84              
85             sub is_ok {
86 8     8 0 10 my $self = shift;
87 8 50       23 return 0 if not defined $self->response;
88 8 50       17 return 1 if $self->response->code == CODE_TEXT_READY;
89 0         0 return 0;
90             }
91              
92             sub formatted {
93 10     10 0 16 my $self = shift;
94 10 50       25 return [] if not defined $self->response;
95 10 50       30 return [] if $self->response->code != CODE_TEXT_READY;
96              
97 10         28 my $keynames = $s->{lc $self->{subcommand}};
98              
99 10         14 my $result = [];
100 10         14 foreach my $row (@{ $self->response->as_list }) {
  10         20  
101 14         62 my @parts = split ':', $row;
102 14         24 push @{ $result}, { map { @{ $keynames }[$_] =>
  50         41  
  50         143  
  14         31  
103 14         17 $parts[$_] } 0..( scalar @{$keynames} - 1) };
104             }
105 10         50 return $result;
106             }
107              
108             1;