line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Shodo::Hanshi; |
2
|
5
|
|
|
5
|
|
24
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
151
|
|
3
|
5
|
|
|
5
|
|
23
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
158
|
|
4
|
5
|
|
|
5
|
|
5456
|
use Text::MicroTemplate qw/render_mt encoded_string/; |
|
5
|
|
|
|
|
15457
|
|
|
5
|
|
|
|
|
1091
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
5
|
|
|
5
|
0
|
17
|
my ($class, %args) = @_; |
8
|
5
|
|
|
|
|
22
|
my $self = bless { template => $args{template} }, $class; |
9
|
5
|
|
|
|
|
18
|
$self; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub render { |
13
|
4
|
|
|
4
|
0
|
9
|
my ($self, $stash) = @_; |
14
|
4
|
|
33
|
|
|
41
|
my $tmpl = $self->{template} || $self->default_template; |
15
|
4
|
|
|
|
|
20
|
my $renderer = render_mt($self->header . $tmpl, $stash); |
16
|
4
|
|
|
|
|
18994
|
return $renderer->as_string(); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub header { |
20
|
4
|
|
|
4
|
0
|
8
|
my $tmpl = <<'END'; |
21
|
|
|
|
|
|
|
? my ($stash) = @_; |
22
|
|
|
|
|
|
|
? no strict qw/refs vars/; |
23
|
|
|
|
|
|
|
? no warnings; |
24
|
|
|
|
|
|
|
? for my $key (keys %$stash) { |
25
|
|
|
|
|
|
|
? if (ref $stash->{$key}) { |
26
|
|
|
|
|
|
|
? ${$key} = $stash->{$key}; |
27
|
|
|
|
|
|
|
? }else{ |
28
|
|
|
|
|
|
|
? ${$key} = encoded_string($stash->{$key}); |
29
|
|
|
|
|
|
|
? } |
30
|
|
|
|
|
|
|
? } |
31
|
|
|
|
|
|
|
? use warnings; |
32
|
|
|
|
|
|
|
? use strict qw/refs subs/; |
33
|
|
|
|
|
|
|
END |
34
|
4
|
|
|
|
|
27
|
return $tmpl; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub default_template { |
38
|
4
|
|
|
4
|
0
|
9
|
my $tmpl = <<'END'; |
39
|
|
|
|
|
|
|
## = $method ?> = $path ?> |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
? if ($description) { |
42
|
|
|
|
|
|
|
= $description ?> |
43
|
|
|
|
|
|
|
? } |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
### Request |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
```json |
48
|
|
|
|
|
|
|
= $method ?> = $path ?>= $query ? '?'.$query : '' ?> |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
= $request_body ?> |
51
|
|
|
|
|
|
|
``` |
52
|
|
|
|
|
|
|
? if ($rule) { |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
### Parameters |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
? for my $name (keys %$rule) { |
57
|
|
|
|
|
|
|
* `= $name ?>` - = $rule->{$name}{documentation} || '' ?> |
58
|
|
|
|
|
|
|
? for my $key (keys %{$rule->{$name}}) { |
59
|
|
|
|
|
|
|
? next if $key eq 'documentation'; |
60
|
|
|
|
|
|
|
? if ($rule->{$name}{$key}) { |
61
|
|
|
|
|
|
|
* = $key ?>: **= $rule->{$name}{$key} || '' ?>** |
62
|
|
|
|
|
|
|
? } |
63
|
|
|
|
|
|
|
? } |
64
|
|
|
|
|
|
|
? } |
65
|
|
|
|
|
|
|
? } |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
### Response |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
```json |
70
|
|
|
|
|
|
|
Status: = $code ?> |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
= $response_body ?> |
73
|
|
|
|
|
|
|
``` |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
--- |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
END |
78
|
4
|
|
|
|
|
18
|
return $tmpl; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |