lib/CPAN/Mini/Inject/Server.pm

filter: Statementstmt 40.2% 29 / 72 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 69.2% 9 / 13 Podpod 100% 3 / 3 totaltotal 42.7% 41 / 96 CC 5 SCAR 18.2
CC
5
Cov
36%
add
20.0
_mcpi
6.0
update
2.0
CRAP 6.2
↑ Summary script/cmis_test_server.pl »
1 package CPAN::Mini::Inject::Server;
2 2 ▶use base 'CGI::Application';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use CGI::Application::Plugin::AutoRunmode;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use CPAN::Mini::Inject;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 CPAN::Mini::Inject::Server - Inject into your CPAN mirror from over there
13  
14 =head1 VERSION
15  
16 Version 0.03
17  
18 =cut
19  
20 2 our $VERSION = '0.03';
21  
22  
23 =head1 SYNOPSIS
24  
25 #under test server
26  
27 use CGI::Application::Dispatch::Server;
28 my $server = CGI::Application::Dispatch::Server->new(
29 class => 'CPAN::Mini::Inject::Server::Dispatch',
30 port => '9000'
31 );
32  
33 $server->run;
34  
35 #under plain cgi
36  
37 #!/usr/bin/perl
38 use FindBin '$Bin';
39 use lib "$Bin/../../rel/path/to/my/perllib";
40 use CPAN::Mini::Inject::Server::Dispatch
41 CPAN::Mini::Inject::Server::Dispatch->dispatch();
42  
43 #Apache and mod perl
44  
45 <location /app>
46 SetHandler perl-script
47 PerlHandler CPAN::Mini::Inject::Server::Dispatch
48 </location>
49  
50 =cut
51  
52 =head1 DESCRIPTION
53  
54 This module is a simple Restish webservice that makes the basic functionality
55 and interface of mcpani (of the CPAN::Mini::Inject package) available from
56 accross a network allowing for remote management of a cpan mirror.
57  
58 The original envisaged use for this module was for a continuous integration
59 platform with distributed build nodes to be able to commit its build artifacts
60 back to a common CPAN repository so that subsequent builds of other modules
61 could use source the new version of the software.
62  
63 =cut
64  
65 =head1 FUNCTIONS
66  
67 =cut
68  
69  
70 ######
71 #
72 # _mcpi
73 #
74 # Accessor for a mini cpan instance
75 #
76 ###
77  
78 0 ▶sub _mcpi {
Subroutine _mcpi: not called CC=2 SCAR=17.9
79 0 my $self = shift;
80  
81 0 ▶ if (not $self->{mcpi})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"mcpi"}) 0 0 0
82 {
83 0 $self->{mcpi} = CPAN::Mini::Inject->new;
84 0 $self->{mcpi}->loadcfg();
85 0 $self->{mcpi}->parsecfg();
86 }
87  
88 0 return $self->{mcpi};
89 } # end of method _mcpi
90  
91  
92 =head2 add
93  
94 Invokes the controller to add a new module to the CPAN::Mini server
95  
96 =cut
97  
98 0 ▶sub add :Runmode {
Subroutine add: not called CC=4 SCAR=30.0
Pod documented
99 0 my $self = shift;
100 0 $self->header_add(-status => '501 Not Implemented');
101  
102 0 my $query = $self->query();
103  
104 0 my $module_name = $query->param('module');
105 0 my $module_author = $query->param('authorid');
106 0 my $module_version = $query->param('version');
107  
108 0 my $module_filename = $query->param('file');
109  
110 0 ▶ if (not $module_filename)
Branch: 1 branch
BranchTrueFalseTotal
unless ($module_filename) 0 0 0
111 {
112 0 $self->header_add(-status => '400 No module archive supplied');
113 0 return;
114 }
115  
116 # check filename ends with tar.gz
117  
118 0 my $bytesread;
119 my $tmp_fh;
120  
121 # -e tmp file here to check we don't bash on it can be racey, just forget
122 # about it
123  
124 0 my $tmp_module_filename = $module_name;
125 0 $tmp_module_filename =~ s/::/-/g;
126 0 $tmp_module_filename = "/tmp/$tmp_module_filename-$module_version.tar.gz";
127  
128 0 ▶ if (not open ($tmp_fh, '>', $tmp_module_filename))
Branch: 1 branch
BranchTrueFalseTotal
unless (open $tmp_fh, ">", $tmp_module_filename) 0 0 0
129 {
130 0 $self->header_add(-status => '500 Internal System Error');
131 0 return;
132 }
133  
134 0 ▶ while ($bytesread = read($module_filename, my $buffer, 1024))
Branch: 1 branch
BranchTrueFalseTotal
if ($bytesread = read($module_filename, my $buffer, 1024)) 0 0 0
135 {
136 0 print $tmp_fh $buffer;
137 }
138  
139 0 close ($tmp_fh);
140  
141  
142 0 my $mcpi = $self->_mcpi();
143 0 $mcpi->add(
144 module => $module_name,
145 authorid => $module_author,
146 version => $module_version,
147 file => $tmp_module_filename,
148 );
149  
150 0 unlink $tmp_module_filename;
151  
152 0 $mcpi->writelist();
153  
154 0 $self->header_add(-status => '202 Module added');
155 0 return;
156 2 ▶} # end of subroutine add
Subroutine BEGIN: called CC=1 SCAR=0.0
157  
158  
159 =head2 update
160  
161 Updates the cpan mirror
162  
163 =cut
164  
165 0 ▶sub update :Runmode {
Subroutine update: not called CC=1 SCAR=6.9
Pod documented
166 0 my $self = shift;
167  
168 0 my $mcpi = $self->_mcpi();
169  
170 0 $mcpi->update_mirror();
171 0 $mcpi->inject();
172  
173 0 $self->header_add(-status => '202 Mirror updated');
174 0 return;
175 2 ▶} # end of subroutine update
Subroutine BEGIN: called CC=1 SCAR=0.0
176  
177  
178 =head2 inject
179  
180 Injects all added modules into the cpan mirror
181  
182 =cut
183  
184 0 ▶sub inject :Runmode {
Subroutine inject: not called CC=1 SCAR=6.9
Pod documented
185 0 my $self = shift;
186  
187 0 my $mcpi = $self->_mcpi();
188  
189 0 $mcpi->inject();
190  
191 0 $self->header_add(-status => '202 Modules injected');
192 0 return;
193 2 ▶} # end of subroutine inject
Subroutine BEGIN: called CC=1 SCAR=0.0
194  
195  
196 =head1 AUTHOR
197  
198 Christopher Mckay, C<< <potatohead at potatolan.com> >>
199  
200 =head1 BUGS
201  
202 Please report any bugs or feature requests to C<bug-cpan-mini-inject-server at rt.cpan.org>, or through
203 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CPAN-Mini-Inject-Server>. I will be notified, and then you'll
204 automatically be notified of progress on your bug as I make changes.
205  
206 =head1 TO DO
207  
208 Need to add logging down to trace levels to this
209  
210 =head1 SUPPORT
211  
212 You can find documentation for this module with the perldoc command.
213  
214 perldoc CPAN::Mini::Inject::Server
215  
216  
217 You can also look for information at:
218  
219 =over 4
220  
221 =item * RT: CPAN's request tracker
222  
223 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CPAN-Mini-Inject-Server>
224  
225 =item * AnnoCPAN: Annotated CPAN documentation
226  
227 L<http://annocpan.org/dist/CPAN-Mini-Inject-Server>
228  
229 =item * CPAN Ratings
230  
231 L<http://cpanratings.perl.org/d/CPAN-Mini-Inject-Server>
232  
233 =item * Search CPAN
234  
235 L<http://search.cpan.org/dist/CPAN-Mini-Inject-Server/>
236  
237 =back
238  
239  
240 =head1 ACKNOWLEDGEMENTS
241  
242  
243 =head1 COPYRIGHT & LICENSE
244  
245 Copyright 2009 Christopher Mckay.
246  
247 This program is free software; you can redistribute it and/or modify it
248 under the terms of either: the GNU General Public License as published
249 by the Free Software Foundation; or the Artistic License.
250  
251 See http://dev.perl.org/licenses/ for more information.
252  
253  
254 =cut
255  
256 2 1; # End of CPAN::Mini::Inject::Server
↑ Summary script/cmis_test_server.pl »