blib/lib/CPAN/Mini/Inject/Remote.pm

filter: Statementstmt 38.1% 32 / 84 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 58.8% 10 / 17 Podpod 100% 4 / 4 totaltotal 34.8% 46 / 132 SCAR 44.2
CC
14
Cov
29%
_find_config
30.0
_initialize
20.0
add
12.0
CRAP 83.1
↑ Summary Build »
1 package CPAN::Mini::Inject::Remote;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 use Params::Validate qw/validate
6 2 ▶ SCALAR/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use YAML::Any qw/LoadFile/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 CPAN::Mini::Inject::Remote - Inject into your CPAN mirror from over here
18  
19 =head1 VERSION
20  
21 Version 0.02
22  
23 =cut
24  
25 2 our $VERSION = '0.02';
26  
27  
28 =head1 SYNOPSIS
29  
30 describe the module, working code example
31  
32 =cut
33  
34 =head1 DESCRIPTION
35  
36 =cut
37  
38 =head1 FUNCTIONS
39  
40 =cut
41  
42 =head2 new
43  
44 Class constructor
45  
46 =cut
47  
48 sub new {
49 0 ▶ my $proto = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
50 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
51 0 my $self = {};
52 0 bless ($self, $class);
53 0 $self->_initialize(@_);
54 0 return $self;
55 } # end of method new
56  
57 ######
58 #
59 # _initialize
60 #
61 # Class properties initator
62 #
63 ###
64  
65 sub _initialize {
66 0 ▶ my $self = shift;
Subroutine _initialize: not called CC=4 SCAR=30.0
67 0 my %args = validate(@_,
68 {
69 config_file => {
70 type => SCALAR,
71 optional => 1,
72 },
73 remote_server => {
74 type => SCALAR,
75 optional => 1,
76 },
77 }
78 );
79  
80 0 ▶ if (not $args{remote_server})
Branch: 1 branch
BranchTrueFalseTotal
if (not $args{'remote_server'}) { } 0 0 0
81 {
82 0 ▶ if (not $args{config_file})
Branch: 2 branches
BranchTrueFalseTotal
if (not $args{'config_file'}) { } 0 0 0
elsif (not -r $args{'config_file'}) { } 0 0 0
83 {
84 0 $args{config_file} = $self->_find_config();
85 }
86 elsif (not -r $args{config_file})
87 {
88 0 croak "Supplied config file is not readable";
89 }
90  
91 0 my $config = LoadFile($args{config_file});
92  
93 0 $self->{remote_server} = $config->{remote_server};
94 }
95 else
96 {
97 0 $self->{remote_server} = $args{remote_server};
98 }
99  
100 # get rid of any trailing slash as it will break things
101 0 $self->{remote_server} =~ s/\/$//;
102  
103 } # end of method _initialize
104  
105  
106 ######
107 #
108 # _find_config
109 #
110 # Attempts to find the config from a number of locations
111 #
112 # locations are:-
113 # argument passed in
114 # specified in $ENV{MCPANI_REMOTE_CONFIG},
115 # $ENV{HOME}/.mcpani_remote
116 # /usr/local/etc/mcpani_remote
117 # /etc/mcpani_remote
118 #
119 ###
120  
121 sub _find_config {
122 0 ▶ my $self = shift;
Subroutine _find_config: not called CC=5 SCAR=34.0
123 0 my %args = validate(@_,
124 {
125  
126 }
127 );
128  
129 my @config_locations = (
130 $ENV{MCPANI_REMOTE_CONFIG},
131 (
132 defined $ENV{HOME}
133 0 ▶ ? File::Spec->catfile( $ENV{HOME}, qw/.mcpani_remote/)
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'HOME'} ? : 0 0 0
134 : ()
135 ),
136 File::Spec->catfile(
137 File::Spec->rootdir(),
138 qw/usr local etc mcpani_remote/
139 ),
140 File::Spec->catfile(
141 File::Spec->rootdir(),
142 qw/etc mcpani_remote/
143 ),
144 );
145  
146 0 for my $file ( @config_locations) {
147 0 ▶ next unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 0 0
148 0 ▶ next unless -r $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $file 0 0 0
149  
150 0 return $file;
151 }
152  
153 0 croak "No config file was found that existed";
154 } # end of method _load_config
155  
156  
157 ######
158 #
159 # _useragent
160 #
161 # loads up the user agent if one exists
162 #
163 ###
164  
165 sub _useragent {
166 0 ▶ my $self = shift;
Subroutine _useragent: not called CC=2 SCAR=17.9
167 0 my %args = validate(@_,
168 {
169  
170 }
171 );
172  
173 0 ▶ if (not $self->{useragent})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"useragent"}) 0 0 0
174 {
175 0 $self->{useragent} = LWP::UserAgent->new;
176 }
177  
178 0 return $self->{useragent};
179 } # end of method _useragent
180  
181  
182 =head2 add
183  
184 Calls the add function on the remote server
185  
186 =cut
187  
188 sub add {
189 0 ▶ my $self = shift;
Subroutine add: not called CC=3 SCAR=24.8
Pod documented
190 0 my %args = validate(@_,
191 {
192 module_name => {
193 type => SCALAR,
194 },
195 author_id => {
196 type => SCALAR,
197 },
198 version => {
199 type => SCALAR,
200 },
201 file_name => {
202 type => SCALAR,
203 },
204 }
205 );
206  
207 0 ▶ if (not -r $args{file_name})
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $args{"file_name"}) 0 0 0
208 {
209 0 croak "Module file is not readable";
210 }
211  
212  
213 0 my $ua = $self->_useragent();
214  
215 my $response = $ua->request(POST $self->{remote_server}.'/add',
216 Content_Type => 'form-data',
217 Content => [
218 module => $args{module_name},
219 authorid => $args{author_id},
220 version => $args{version},
221 0 file => [$args{file_name}],
222 ]
223 );
224  
225 0 ▶ if (not $response->is_success())
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
226 {
227 0 croak 'Add failed. ' . Dumper($response);
228 }
229  
230 0 return;
231 } # end of method add
232  
233  
234 =head2 update
235  
236 Calls the update function on the remote server
237  
238 =cut
239  
240 sub update {
241 0 ▶ my $self = shift;
Subroutine update: not called CC=2 SCAR=17.9
Pod documented
242 0 my %args = validate(@_,
243 {
244  
245 }
246 );
247  
248 0 my $ua = $self->_useragent();
249  
250 0 my $response = $ua->request(POST $self->{remote_server}.'/update');
251  
252 0 ▶ if (not $response->is_success())
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
253 {
254 0 croak 'Update failed. ' . Dumper($response);
255 }
256  
257 0 return;
258 } # end of method update
259  
260  
261 =head2 inject
262  
263 Calls the inject function on the remote server
264  
265 =cut
266  
267 sub inject {
268 0 ▶ my $self = shift;
Subroutine inject: not called CC=2 SCAR=17.9
Pod documented
269 0 my %args = validate(@_,
270 {
271  
272 }
273 );
274
275 0 my $ua = $self->_useragent();
276  
277 0 my $response = $ua->request(POST $self->{remote_server}.'/inject');
278  
279 0 ▶ if (not $response->is_success())
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
280 {
281 0 croak 'Inject failed. ' . Dumper($response);
282 }
283  
284 0 return;
285 } # end of method inject
286  
287  
288 =head1 AUTHOR
289  
290 Christopher Mckay, C<< <potatohead at potatolan.com> >>
291  
292 =head1 BUGS
293  
294 Please report any bugs or feature requests to C<bug-cpan-mini-inject-remote at rt.cpan.org>, or through
295 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CPAN-Mini-Inject-Remote>. I will be notified, and then you'll
296 automatically be notified of progress on your bug as I make changes.
297  
298 =head1 TODO
299  
300 Fix up error messages, they currently contain $response dumps
301  
302 =head1 SUPPORT
303  
304 You can find documentation for this module with the perldoc command.
305  
306 perldoc CPAN::Mini::Inject::Remote
307  
308  
309 You can also look for information at:
310  
311 =over 4
312  
313 =item * RT: CPAN's request tracker
314  
315 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CPAN-Mini-Inject-Remote>
316  
317 =item * AnnoCPAN: Annotated CPAN documentation
318  
319 L<http://annocpan.org/dist/CPAN-Mini-Inject-Remote>
320  
321 =item * CPAN Ratings
322  
323 L<http://cpanratings.perl.org/d/CPAN-Mini-Inject-Remote>
324  
325 =item * Search CPAN
326  
327 L<http://search.cpan.org/dist/CPAN-Mini-Inject-Remote/>
328  
329 =back
330  
331  
332 =head1 ACKNOWLEDGEMENTS
333  
334  
335 =head1 COPYRIGHT & LICENSE
336  
337 Copyright 2009 Christopher Mckay.
338  
339 This program is free software; you can redistribute it and/or modify it
340 under the terms of either: the GNU General Public License as published
341 by the Free Software Foundation; or the Artistic License.
342  
343 See http://dev.perl.org/licenses/ for more information.
344  
345  
346 =cut
347  
348 2 1; # End of CPAN::Mini::Inject::Remote
↑ Summary Build »