line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::JSON::RPC::Autodoc; |
2
|
3
|
|
|
3
|
|
89539
|
use 5.008001; |
|
3
|
|
|
|
|
6
|
|
3
|
3
|
|
|
3
|
|
11
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
44
|
|
4
|
3
|
|
|
3
|
|
8
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
54
|
|
5
|
3
|
|
|
3
|
|
1161
|
use File::ShareDir; |
|
3
|
|
|
|
|
13512
|
|
|
3
|
|
|
|
|
225
|
|
6
|
3
|
|
|
3
|
|
2291
|
use Path::Tiny qw/path/; |
|
3
|
|
|
|
|
25506
|
|
|
3
|
|
|
|
|
161
|
|
7
|
3
|
|
|
3
|
|
1653
|
use Text::Xslate; |
|
3
|
|
|
|
|
22200
|
|
|
3
|
|
|
|
|
125
|
|
8
|
3
|
|
|
3
|
|
1203
|
use Test::JSON::RPC::Autodoc::Request; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
892
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "0.14"; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
3
|
|
|
3
|
1
|
396
|
my ($class, %opt) = @_; |
14
|
3
|
100
|
|
|
|
18
|
my $app = $opt{app} or die 'app parameter must not be null!'; |
15
|
|
|
|
|
|
|
my $self = bless { |
16
|
|
|
|
|
|
|
app => $app, |
17
|
|
|
|
|
|
|
document_root => $opt{document_root} || 'docs', |
18
|
|
|
|
|
|
|
path => $opt{path} || '/', |
19
|
|
|
|
|
|
|
requests => [], |
20
|
|
|
|
|
|
|
index_file => $opt{index_file} || undef, |
21
|
2
|
|
50
|
|
|
26
|
}, $class; |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
22
|
2
|
|
|
|
|
6
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new_request { |
26
|
4
|
|
|
4
|
1
|
2848
|
my ($self, $label) = @_; |
27
|
|
|
|
|
|
|
my $req = Test::JSON::RPC::Autodoc::Request->new( |
28
|
|
|
|
|
|
|
app => $self->{app}, |
29
|
|
|
|
|
|
|
path => $self->{path}, |
30
|
4
|
|
100
|
|
|
45
|
label => $label || '', |
31
|
|
|
|
|
|
|
); |
32
|
4
|
|
|
|
|
5
|
push @{$self->{requests}}, $req; |
|
4
|
|
|
|
|
8
|
|
33
|
4
|
|
|
|
|
7
|
return $req; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub write { |
37
|
2
|
|
|
2
|
1
|
999
|
my ($self, $filename) = @_; |
38
|
2
|
|
|
|
|
7
|
my $tx = $self->load_tx(); |
39
|
2
|
|
|
|
|
466
|
my $text = $tx->render('template.tx', { requests => $self->{requests} }); |
40
|
2
|
|
|
|
|
20
|
path($self->{document_root}, $filename)->spew_utf8($text); |
41
|
2
|
100
|
|
|
|
2692
|
$self->append_to_index($filename) if $self->{index_file}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub append_to_index { |
45
|
1
|
|
|
1
|
0
|
3
|
my ($self, $filename) = @_; |
46
|
1
|
|
|
|
|
4
|
my $tx = $self->load_tx(); |
47
|
|
|
|
|
|
|
my $text = $tx->render('index_part.tx', { |
48
|
|
|
|
|
|
|
requests => $self->{requests}, |
49
|
1
|
|
|
|
|
192
|
path => path($filename), |
50
|
|
|
|
|
|
|
}); |
51
|
1
|
|
|
|
|
6
|
my $path = path($self->{document_root}, $self->{index_file}); |
52
|
1
|
|
|
|
|
20
|
$path->append_utf8($text); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub load_tx { |
56
|
3
|
|
|
3
|
0
|
4
|
my $dir = './share'; |
57
|
3
|
50
|
|
|
|
40
|
$dir = File::ShareDir::dist_dir('Test-JSON-RPC-Autodoc') unless -d $dir; |
58
|
3
|
|
|
|
|
29
|
return Text::Xslate->new( path => $dir ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
__END__ |