1 | package Sophie::Controller::Maintainers; |
---|
2 | use Moose; |
---|
3 | use namespace::autoclean; |
---|
4 | |
---|
5 | BEGIN {extends 'Catalyst::Controller'; } |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | Sophie::Controller::Maintainers - Catalyst Controller |
---|
10 | |
---|
11 | =head1 DESCRIPTION |
---|
12 | |
---|
13 | Catalyst Controller. |
---|
14 | |
---|
15 | =head1 METHODS |
---|
16 | |
---|
17 | =cut |
---|
18 | |
---|
19 | =head2 maintainers.byrpm ( RPMNAME, [ DISTRIB ] ) |
---|
20 | |
---|
21 | Return the list of maintainers for rpm source name C<RPMNAME>. |
---|
22 | |
---|
23 | The optional C<DISTRIB> filter the result to this specific distribution. |
---|
24 | |
---|
25 | Result example: |
---|
26 | |
---|
27 | [ |
---|
28 | { |
---|
29 | 'owner' => 'rpmmaintainer', |
---|
30 | 'distribution' => 'Mandriva' |
---|
31 | 'vendor' => 'Mandriva' |
---|
32 | } |
---|
33 | ]; |
---|
34 | |
---|
35 | =head2 Url: /maintainers/<RPM>/<DISTRIB> |
---|
36 | |
---|
37 | Return the list of maintainers for source rpm named C<RPM> for distribution |
---|
38 | C<DISTRIB>. |
---|
39 | |
---|
40 | Theses alternatives are supported: |
---|
41 | |
---|
42 | /maintainers?rpm=<RPM>;distrib=<DISTRIB> |
---|
43 | |
---|
44 | /maintainers/<RPM>?distrib=<DISTRIB> |
---|
45 | |
---|
46 | /maintainers/<RPM>/<DISTRIB> |
---|
47 | |
---|
48 | To use JSON (same for AJAX): |
---|
49 | |
---|
50 | /maintainers?rpm=<RPM>;distrib=<DISTRIB>;json=1 |
---|
51 | |
---|
52 | /maintainers/<RPM>?distrib=<DISTRIB>;json=1 |
---|
53 | |
---|
54 | /maintainers/<RPM>/<DISTRIB>?json |
---|
55 | |
---|
56 | =cut |
---|
57 | |
---|
58 | sub byrpm :Path :XMLRPC { |
---|
59 | my ($self, $c, $rpm, $distrib) = @_; |
---|
60 | $rpm ||= $c->req->param('rpm'); |
---|
61 | $distrib ||= $c->req->param('distrib'); |
---|
62 | |
---|
63 | $c->stash->{xmlrpc} = [ map { { $_->get_columns } } |
---|
64 | $c->model('Base::MaintRpm')-> |
---|
65 | search( |
---|
66 | { rpm => $rpm }, |
---|
67 | { select => [ qw(owner) ] }, |
---|
68 | )-> |
---|
69 | search_related('MaintSources')-> |
---|
70 | search_related('MaintDistrib')-> |
---|
71 | search_related('Distribution', |
---|
72 | $distrib ? { |
---|
73 | '-or' => [ |
---|
74 | { shortname => $distrib }, |
---|
75 | { name => $distrib }, |
---|
76 | ], |
---|
77 | } : (), |
---|
78 | )->search({}, |
---|
79 | { |
---|
80 | 'select' => [ qw'me.owner name maintsources.label' ], |
---|
81 | 'as' => [ qw'owner distribution vendor' ], |
---|
82 | } |
---|
83 | )->all ]; |
---|
84 | } |
---|
85 | |
---|
86 | =head2 maintainers.bymaintainer ( MAINT, [ DISTRIB ] ) |
---|
87 | |
---|
88 | Return the list of rpms for maintainer C<MAINT>. |
---|
89 | |
---|
90 | The optional C<DISTRIB> filter the result to this specific distribution. |
---|
91 | |
---|
92 | Result example: |
---|
93 | |
---|
94 | [ |
---|
95 | { |
---|
96 | 'rpm' => 'rpm package', |
---|
97 | 'distribution' => 'Mandriva' |
---|
98 | 'vendor' => 'Mandriva' |
---|
99 | } |
---|
100 | ]; |
---|
101 | |
---|
102 | =cut |
---|
103 | |
---|
104 | |
---|
105 | sub bymaintainer : XMLRPC { |
---|
106 | my ($self, $c, $maint, $distrib) = @_; |
---|
107 | $c->stash->{xmlrpc} = [ map { { $_->get_columns } } |
---|
108 | $c->model('Base::MaintRpm')-> |
---|
109 | search( |
---|
110 | { owner => $maint }, |
---|
111 | { select => [ qw(rpm) ] }, |
---|
112 | )-> |
---|
113 | search_related('MaintSources')-> |
---|
114 | search_related('MaintDistrib')-> |
---|
115 | search_related('Distribution', |
---|
116 | $distrib ? { |
---|
117 | '-or' => [ |
---|
118 | { shortname => $distrib }, |
---|
119 | { name => $distrib }, |
---|
120 | ], |
---|
121 | } : (), |
---|
122 | )->search({}, |
---|
123 | { |
---|
124 | 'select' => [ qw'rpm name label' ], |
---|
125 | 'as' => [ qw'rpm distribution vendor' ], |
---|
126 | } |
---|
127 | )->all ]; |
---|
128 | |
---|
129 | } |
---|
130 | |
---|
131 | =head2 maintainers.search ( MAINT, [ DISTRIB ] ) |
---|
132 | |
---|
133 | Search the database for a maintainer matching C<MAINT>. |
---|
134 | |
---|
135 | The optional C<DISTRIB> filter the result to this specific distribution. |
---|
136 | |
---|
137 | Result example: |
---|
138 | |
---|
139 | [ |
---|
140 | { |
---|
141 | 'owner' => 'maintainer', |
---|
142 | 'distribution' => 'Mandriva' |
---|
143 | 'vendor' => 'Mandriva' |
---|
144 | } |
---|
145 | ]; |
---|
146 | |
---|
147 | =cut |
---|
148 | |
---|
149 | sub search :XMLRPC { |
---|
150 | my ($self, $c, $maint, $distrib) = @_; |
---|
151 | |
---|
152 | $c->stash->{xmlrpc} = [ map { { $_->get_columns } } |
---|
153 | $c->model('Base::MaintRpm')->search( |
---|
154 | { owner => { 'LIKE' => "%$maint%" } } |
---|
155 | )->search_related('MaintSources' |
---|
156 | )->search_related('MaintDistrib' |
---|
157 | )->search_related('Distribution', |
---|
158 | $distrib ? { |
---|
159 | '-or' => [ |
---|
160 | { shortname => $distrib }, |
---|
161 | { name => $distrib }, |
---|
162 | ], |
---|
163 | } : (), |
---|
164 | )->search({}, |
---|
165 | { |
---|
166 | 'select' => [ qw'owner name label' ], |
---|
167 | 'as' => [ qw'owner distribution vendor' ], |
---|
168 | 'group_by' => [ qw'owner name label' ], |
---|
169 | 'order_by' => [ qw'owner name label' ], |
---|
170 | } |
---|
171 | )->all ]; |
---|
172 | } |
---|
173 | |
---|
174 | =head1 AUTHOR |
---|
175 | |
---|
176 | Olivier Thauvin |
---|
177 | |
---|
178 | =head1 LICENSE |
---|
179 | |
---|
180 | This library is free software. You can redistribute it and/or modify |
---|
181 | it under the same terms as Perl itself. |
---|
182 | |
---|
183 | =cut |
---|
184 | |
---|
185 | __PACKAGE__->meta->make_immutable; |
---|
186 | |
---|
187 | 1; |
---|