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   204 use parent 'Net::Gnats::Command';
  40         67  
  40         252  
3 40     40   2099 use strictures;
  40         75  
  40         209  
4             BEGIN {
5 40     40   9104 $Net::Gnats::Command::LIST::VERSION = '0.22';
6             }
7 40     40   216 use vars qw($VERSION);
  40         70  
  40         1625  
8              
9 40     40   216 use Net::Gnats::Constants qw(CODE_TEXT_READY CODE_INVALID_LIST);
  40         68  
  40         18070  
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 430 my ( $class, %options ) = @_;
75 133         265 my $self = bless \%options, $class;
76 133         434 return $self;
77             }
78              
79             sub as_string {
80 279     279 1 393 my $self = shift;
81 279 100       855 return undef if not defined $self->{subcommand};
82 277         1170 return $c . ' ' . $self->{subcommand};
83             }
84              
85             sub is_ok {
86 8     8 0 12 my $self = shift;
87 8 50       22 return 0 if not defined $self->response;
88 8 50       21 return 1 if $self->response->code == CODE_TEXT_READY;
89 0         0 return 0;
90             }
91              
92             sub formatted {
93 10     10 0 17 my $self = shift;
94 10 50       26 return [] if not defined $self->response;
95 10 50       27 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         13 foreach my $row (@{ $self->response->as_list }) {
  10         28  
101 14         48 my @parts = split ':', $row;
102 14         22 push @{ $result}, { map { @{ $keynames }[$_] =>
  50         59  
  50         171  
103 14         22 $parts[$_] } 0..( scalar @{$keynames} - 1) };
  14         29  
104             }
105 10         46 return $result;
106             }
107              
108             1;