line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::HTTP::Spore::Middleware::Mock; |
2
|
|
|
|
|
|
|
$Net::HTTP::Spore::Middleware::Mock::VERSION = '0.08'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Simple Mocker for Spore middlewares |
4
|
|
|
|
|
|
|
|
5
|
18
|
|
|
18
|
|
10062
|
use Moose; |
|
18
|
|
|
|
|
103
|
|
|
18
|
|
|
|
|
134
|
|
6
|
|
|
|
|
|
|
extends 'Net::HTTP::Spore::Middleware'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has tests => ( isa => 'HashRef', is => 'ro', required => 1 ); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub call { |
11
|
24
|
|
|
24
|
0
|
89
|
my ( $self, $req ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
24
|
|
|
|
|
127
|
my $finalized_request = $req->finalize; |
14
|
24
|
|
|
|
|
64
|
foreach my $r ( keys %{ $self->tests } ) { |
|
24
|
|
|
|
|
782
|
|
15
|
29
|
100
|
|
|
|
179
|
next unless $r eq $finalized_request->uri->path; |
16
|
24
|
|
|
|
|
1107
|
my $res = $self->tests->{$r}->($req); |
17
|
23
|
50
|
|
|
|
341
|
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.08 |
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 |