line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Web::API::Mock::Parser; |
2
|
5
|
|
|
5
|
|
3459
|
use 5.008005; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
238
|
|
3
|
5
|
|
|
5
|
|
29
|
use strict; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
208
|
|
4
|
5
|
|
|
5
|
|
23
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
257
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
3266
|
use utf8; |
|
5
|
|
|
|
|
54
|
|
|
5
|
|
|
|
|
33
|
|
9
|
5
|
|
|
5
|
|
248
|
use B qw(perlstring); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
376
|
|
10
|
5
|
|
|
5
|
|
2825
|
use Text::Markdown::Hoedown; |
|
5
|
|
|
|
|
8180
|
|
|
5
|
|
|
|
|
1257
|
|
11
|
5
|
|
|
5
|
|
2369
|
use Web::API::Mock::Map; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
242
|
|
12
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
13
|
5
|
|
|
|
|
62
|
new => 1, |
14
|
|
|
|
|
|
|
rw => [ qw/map md cb _resource_name _paragraph _url _method _status _content_type _header _body api/ ], |
15
|
5
|
|
|
5
|
|
28
|
); |
|
5
|
|
|
|
|
6
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub create_map { |
18
|
4
|
|
|
4
|
0
|
5525
|
my $self =shift; |
19
|
|
|
|
|
|
|
|
20
|
4
|
|
|
|
|
17
|
$self->_callback(); |
21
|
|
|
|
|
|
|
|
22
|
4
|
|
|
|
|
30
|
my $md = Text::Markdown::Hoedown::Markdown->new(HOEDOWN_EXT_AUTOLINK, 16, $self->cb); |
23
|
|
|
|
|
|
|
|
24
|
4
|
|
|
|
|
72
|
eval { |
25
|
4
|
|
|
|
|
16
|
$md->render($self->md); |
26
|
|
|
|
|
|
|
}; |
27
|
4
|
50
|
|
|
|
162
|
if ( $@ ) { |
28
|
0
|
|
|
|
|
0
|
die "cannot parse markdown. $@"; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
4
|
|
|
|
|
29
|
my $map = Web::API::Mock::Map->new(); |
32
|
4
|
|
|
|
|
46
|
$map->init(); |
33
|
4
|
|
|
|
|
28
|
for my $name ( keys %{$self->api} ) { |
|
4
|
|
|
|
|
14
|
|
34
|
16
|
|
|
|
|
118
|
$map->add_resource( $self->api->{$name}->{url}, { |
35
|
|
|
|
|
|
|
status => $self->api->{$name}->{status}, |
36
|
|
|
|
|
|
|
content_type => $self->api->{$name}->{content_type}, |
37
|
|
|
|
|
|
|
method => $self->api->{$name}->{method}, |
38
|
|
|
|
|
|
|
header => $self->api->{$name}->{header}, |
39
|
|
|
|
|
|
|
body => $self->api->{$name}->{body} |
40
|
|
|
|
|
|
|
}); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
4
|
|
|
|
|
91
|
return $map; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _callback { |
47
|
4
|
|
|
4
|
|
8
|
my $self = shift; |
48
|
|
|
|
|
|
|
|
49
|
4
|
|
|
|
|
17
|
$self->api({}); |
50
|
|
|
|
|
|
|
|
51
|
4
|
|
|
|
|
88
|
my $cb = Text::Markdown::Hoedown::Renderer::Callback->new(); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$cb->blockcode( sub { |
54
|
25
|
50
|
|
25
|
|
173
|
return unless $self->_resource_name; |
55
|
|
|
|
|
|
|
|
56
|
25
|
100
|
|
|
|
134
|
if ( $self->_paragraph =~ /^body/i ) { |
|
|
100
|
|
|
|
|
|
57
|
15
|
|
|
|
|
104
|
$self->_body($_[0]); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
elsif ( $self->_paragraph =~ /^header/i ) { |
60
|
9
|
|
|
|
|
130
|
my @line = split("\n", $_[0]); |
61
|
9
|
|
|
|
|
21
|
for (@line) { |
62
|
11
|
|
|
|
|
33
|
my ($key, $value) = split(':',$_); |
63
|
11
|
|
|
|
|
23
|
chomp $value; |
64
|
11
|
|
|
|
|
42
|
$value =~ s/^ +//g; |
65
|
11
|
|
|
|
|
29
|
$self->_header->{$key} = $value; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else { |
69
|
1
|
|
|
|
|
10
|
$self->_body($_[0]); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
4
|
|
|
|
|
44
|
} ); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# TODO |
75
|
4
|
|
|
0
|
|
21
|
$cb->blockquote( sub {} ); |
|
0
|
|
|
|
|
0
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# TODO |
78
|
4
|
|
|
0
|
|
21
|
$cb->blockhtml( sub {} ); |
|
0
|
|
|
|
|
0
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$cb->header( sub { |
81
|
21
|
|
|
21
|
|
154
|
$self->_add_api(); |
82
|
|
|
|
|
|
|
|
83
|
21
|
|
|
|
|
629
|
my ($method, $url) = split(' ', $_[0]); |
84
|
21
|
|
|
|
|
55
|
$self->_header({}); |
85
|
21
|
|
|
|
|
107
|
$self->_body(''); |
86
|
21
|
|
|
|
|
94
|
$self->_url($url); |
87
|
21
|
|
|
|
|
89
|
$self->_method($method); |
88
|
21
|
|
|
|
|
95
|
$self->_resource_name($_[0]); |
89
|
4
|
|
|
|
|
28
|
} ); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$cb->paragraph( sub { |
92
|
60
|
|
|
60
|
|
448
|
$self->_paragraph($_[0]); |
93
|
4
|
|
|
|
|
32
|
} ); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# TODO |
96
|
4
|
|
|
38
|
|
21
|
$cb->list(sub{}); |
|
38
|
|
|
|
|
203
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$cb->listitem(sub{ |
99
|
58
|
100
|
|
58
|
|
450
|
if ( $_[0] =~ /^response +(\d+) +\((.+?)\)/i ) { |
100
|
17
|
|
|
|
|
51
|
$self->_status($1); |
101
|
17
|
|
|
|
|
123
|
$self->_content_type($2); |
102
|
|
|
|
|
|
|
} |
103
|
4
|
|
|
|
|
21
|
}); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$cb->doc_footer(sub{ |
106
|
4
|
|
|
4
|
|
14
|
$self->_add_api(); |
107
|
4
|
|
|
|
|
34
|
}); |
108
|
|
|
|
|
|
|
|
109
|
4
|
|
|
|
|
18
|
$self->cb($cb); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _add_api { |
113
|
25
|
|
|
25
|
|
32
|
my $self = shift; |
114
|
|
|
|
|
|
|
# APIドキュメント上でコメント等に利用するため |
115
|
|
|
|
|
|
|
# GET,POST,PUT,DELETE以外のメソッドは無視する |
116
|
25
|
100
|
100
|
|
|
51
|
if ( $self->_resource_name && $self->_url && $self->_method && |
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
117
|
|
|
|
|
|
|
$self->_method =~ /^(GET|POST|PUT|DELETE)$/ ) { |
118
|
16
|
|
50
|
|
|
361
|
$self->api->{$self->_resource_name} = { |
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
119
|
|
|
|
|
|
|
content_type => $self->_content_type // '', |
120
|
|
|
|
|
|
|
status => $self->_status // '', |
121
|
|
|
|
|
|
|
url => $self->_url // '', |
122
|
|
|
|
|
|
|
method => $self->_method // '', |
123
|
|
|
|
|
|
|
header => $self->_header // {}, |
124
|
|
|
|
|
|
|
body => $self->_body // '', |
125
|
|
|
|
|
|
|
}; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |