| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CPAN::Faker::HTTPD; |
|
2
|
|
|
|
|
|
|
{ |
|
3
|
|
|
|
|
|
|
$CPAN::Faker::HTTPD::VERSION = '0.002'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Run a bogus CPAN web server for testing |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
177378
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
42
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
37
|
|
|
10
|
1
|
|
|
1
|
|
2276
|
use Test::Fake::HTTPD; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use HTTP::Message::PSGI; |
|
12
|
|
|
|
|
|
|
use Plack::App::File; |
|
13
|
|
|
|
|
|
|
use File::Temp; |
|
14
|
|
|
|
|
|
|
use Moose; |
|
15
|
|
|
|
|
|
|
use namespace::clean -except => 'meta'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
extends 'CPAN::Faker'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has '+dest' => ( |
|
20
|
|
|
|
|
|
|
is => 'ro', |
|
21
|
|
|
|
|
|
|
isa => 'Str', |
|
22
|
|
|
|
|
|
|
required => 0, |
|
23
|
|
|
|
|
|
|
default => sub { File::Temp::tempdir( CLEANUP => 1 ) }, |
|
24
|
|
|
|
|
|
|
); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has 'httpd' => ( |
|
27
|
|
|
|
|
|
|
is => 'ro', |
|
28
|
|
|
|
|
|
|
isa => 'Test::Fake::HTTPD', |
|
29
|
|
|
|
|
|
|
handles => [qw(port host_post endpoint)], |
|
30
|
|
|
|
|
|
|
default => sub { Test::Fake::HTTPD->new }, |
|
31
|
|
|
|
|
|
|
); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'server' => ( |
|
34
|
|
|
|
|
|
|
is => 'ro', |
|
35
|
|
|
|
|
|
|
isa => 'Plack::Component', |
|
36
|
|
|
|
|
|
|
handles => { serve => 'call' }, |
|
37
|
|
|
|
|
|
|
default => sub { Plack::App::File->new( root => $_[0]->dest ) }, |
|
38
|
|
|
|
|
|
|
); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has 'app' => ( |
|
41
|
|
|
|
|
|
|
is => 'ro', |
|
42
|
|
|
|
|
|
|
isa => 'CodeRef', |
|
43
|
|
|
|
|
|
|
default => sub { |
|
44
|
|
|
|
|
|
|
my $self = shift; |
|
45
|
|
|
|
|
|
|
return sub { $self->serve($_[0]->to_psgi) }, |
|
46
|
|
|
|
|
|
|
}, |
|
47
|
|
|
|
|
|
|
); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub BUILD { |
|
50
|
|
|
|
|
|
|
my $self = shift; |
|
51
|
|
|
|
|
|
|
$self->httpd->run( $self->app ); |
|
52
|
|
|
|
|
|
|
}; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |
|
58
|
|
|
|
|
|
|
=pod |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 NAME |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
CPAN::Faker::HTTPD - Run a bogus CPAN web server for testing |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 VERSION |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
version 0.002 |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
use CPAN::Faker::HTTPD; |
|
71
|
|
|
|
|
|
|
use LWP::Simple; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $cpan = CPAN::Faker::HTTPD->new({ source => './eg' }); |
|
74
|
|
|
|
|
|
|
$cpan->make_cpan; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $uri = $cpan->endpoint; |
|
77
|
|
|
|
|
|
|
$uri->path( '/authors/id/P/PS/PSHANGOV/Miril-0.008.tar.gz' ); |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $content = LWP::Simple::get( $uri ); |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$cpan->make_cpan; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This module is a subclass of L<CPAN::Faker> that additionally supplies a |
|
86
|
|
|
|
|
|
|
running webserver (via L<Test::Fake::HTTPD>). It is useful for testing code |
|
87
|
|
|
|
|
|
|
that interacts with remote CPAN mirrors. |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 METHODS |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 port |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Port number of the running server. The port is dynamically determined by |
|
94
|
|
|
|
|
|
|
L<Test::Fake::HTTPD> during initialization. If you need to specify the port |
|
95
|
|
|
|
|
|
|
number explicitly, you will have to create a L<Test::Fake::HTTPD> object |
|
96
|
|
|
|
|
|
|
with the respective options manually, and pass it to L<CPAN::Faker::HTTPD> |
|
97
|
|
|
|
|
|
|
as the C<httpd> parameter on construction. |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
See L<Test::Fake::HTTPD> for details. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
-head2 host_port |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Host and port of the running server. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
See L<Test::Fake::HTTPD> for details. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 endpoint |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
L<URI> object for the full address of the running server (e.g. |
|
110
|
|
|
|
|
|
|
C<http://127.0.0.1:{port}>). |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
See L<Test::Fake::HTTPD> for details. |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 httpd |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
An instance of L<Test::Fake::HTTPD>. Can be overriden during construction. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
See L<Test::Fake::HTTPD> for details. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 server |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Plack application that will handle the serving of files. The default is |
|
123
|
|
|
|
|
|
|
an instance of L<Plack::App::File>, which will simply serve any static |
|
124
|
|
|
|
|
|
|
files under the fake CPAN. Can be overriden during construction. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 app |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Coderef that will be passed to L<Test::Fake::HTTPD/run>. It converts the |
|
129
|
|
|
|
|
|
|
L<HTTP::Request> object to a L<PSGI> environment hash before transferring |
|
130
|
|
|
|
|
|
|
control on to the L</server>. Can be overriden during construction. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 dest |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Directory in which to construct the CPAN instance. Same as in L<CPAN::Faker>, |
|
135
|
|
|
|
|
|
|
but not required any more. If not supplied, a temporary directory will be |
|
136
|
|
|
|
|
|
|
used, as presumably it is the repository uri rather than the repository path |
|
137
|
|
|
|
|
|
|
that users of this module will test against. |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
See L<CPAN::Faker> for details. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 make_cpan |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
See L<CPAN::Faker/make_cpan>. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 add_author |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
See L<CPAN::Faker/add_author> |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 index_package |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
See L<CPAN::Faker/index_package>. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 write_author_index |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
See L<CPAN::Faker/write_author_index>. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 write_package_index |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
See L<CPAN::Faker/write_package_index>. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 write_modlist_index |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
See L<CPAN::Faker/write_modlist_index>. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 write_perms_index |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
See L<CPAN::Faker/write_perms_index>. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 add_dist |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
See L<CPAN::Faker/add_dist>. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=over |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item L<CPAN::Faker> |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item L<Test::Fake::HTTPD> |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=back |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 AUTHOR |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Peter Shangov <pshangov@yahoo.com> |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Venda, Inc.. |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
192
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |
|
195
|
|
|
|
|
|
|
|