line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::HTTP::Spore::Middleware::Mock; |
2
|
|
|
|
|
|
|
$Net::HTTP::Spore::Middleware::Mock::VERSION = '0.07'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Simple Mocker for Spore middlewares |
4
|
|
|
|
|
|
|
|
5
|
17
|
|
|
17
|
|
8984
|
use Moose; |
|
17
|
|
|
|
|
97
|
|
|
17
|
|
|
|
|
115
|
|
6
|
|
|
|
|
|
|
extends 'Net::HTTP::Spore::Middleware'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has tests => ( isa => 'HashRef', is => 'ro', required => 1 ); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub call { |
11
|
22
|
|
|
22
|
0
|
69
|
my ( $self, $req ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
22
|
|
|
|
|
109
|
my $finalized_request = $req->finalize; |
14
|
22
|
|
|
|
|
51
|
foreach my $r ( keys %{ $self->tests } ) { |
|
22
|
|
|
|
|
668
|
|
15
|
26
|
100
|
|
|
|
164
|
next unless $r eq $finalized_request->uri->path; |
16
|
22
|
|
|
|
|
975
|
my $res = $self->tests->{$r}->($req); |
17
|
21
|
50
|
|
|
|
252
|
return $res if defined $res; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
1; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
__END__ |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=pod |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=encoding UTF-8 |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 NAME |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Net::HTTP::Spore::Middleware::Mock - Simple Mocker for Spore middlewares |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 VERSION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
version 0.07 |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 SYNOPSIS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $mock_server = { |
40
|
|
|
|
|
|
|
'/path/i/want/to/match' => sub { |
41
|
|
|
|
|
|
|
my $req = shift; |
42
|
|
|
|
|
|
|
... |
43
|
|
|
|
|
|
|
$req->new_response(200, ['Content-Type' => 'text/plain'], 'ok'); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $client = Net::HTTP::Spore->new_from_spec('spec.json'); |
48
|
|
|
|
|
|
|
$client->enable('Mock', tests => $mock_server); |
49
|
|
|
|
|
|
|
my $res = $client->my_rest_method(); |
50
|
|
|
|
|
|
|
is $res->status, 200; |
51
|
|
|
|
|
|
|
is $res->body, 'ok'; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 DESCRIPTION |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 AUTHORS |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=over 4 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item * |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Franck Cuny <franck.cuny@gmail.com> |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item * |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Ash Berlin <ash@cpan.org> |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item * |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Ahmad Fatoum <athreef@cpan.org> |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=back |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Linkfluence. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
78
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |