line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::JSON::RPC::Autodoc; |
2
|
3
|
|
|
3
|
|
93596
|
use 5.008001; |
|
3
|
|
|
|
|
7
|
|
3
|
3
|
|
|
3
|
|
11
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
43
|
|
4
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
53
|
|
5
|
3
|
|
|
3
|
|
1289
|
use File::ShareDir; |
|
3
|
|
|
|
|
13179
|
|
|
3
|
|
|
|
|
124
|
|
6
|
3
|
|
|
3
|
|
2023
|
use Path::Tiny qw/path/; |
|
3
|
|
|
|
|
25688
|
|
|
3
|
|
|
|
|
141
|
|
7
|
3
|
|
|
3
|
|
1420
|
use Text::Xslate; |
|
3
|
|
|
|
|
22572
|
|
|
3
|
|
|
|
|
116
|
|
8
|
3
|
|
|
3
|
|
1131
|
use Test::JSON::RPC::Autodoc::Request; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
958
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "0.12"; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
3
|
|
|
3
|
1
|
356
|
my ($class, %opt) = @_; |
14
|
3
|
100
|
|
|
|
19
|
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
|
|
|
25
|
}, $class; |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
22
|
2
|
|
|
|
|
6
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new_request { |
26
|
4
|
|
|
4
|
1
|
2844
|
my ($self, $label) = @_; |
27
|
|
|
|
|
|
|
my $req = Test::JSON::RPC::Autodoc::Request->new( |
28
|
|
|
|
|
|
|
app => $self->{app}, |
29
|
|
|
|
|
|
|
path => $self->{path}, |
30
|
4
|
|
100
|
|
|
41
|
label => $label || '', |
31
|
|
|
|
|
|
|
); |
32
|
4
|
|
|
|
|
4
|
push @{$self->{requests}}, $req; |
|
4
|
|
|
|
|
10
|
|
33
|
4
|
|
|
|
|
8
|
return $req; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub write { |
37
|
2
|
|
|
2
|
1
|
981
|
my ($self, $filename) = @_; |
38
|
2
|
|
|
|
|
6
|
my $tx = $self->load_tx(); |
39
|
2
|
|
|
|
|
453
|
my $text = $tx->render('template.tx', { requests => $self->{requests} }); |
40
|
2
|
|
|
|
|
13
|
path($self->{document_root}, $filename)->spew_utf8($text); |
41
|
2
|
100
|
|
|
|
2635
|
$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
|
|
|
|
|
2
|
my $tx = $self->load_tx(); |
47
|
|
|
|
|
|
|
my $text = $tx->render('index_part.tx', { |
48
|
|
|
|
|
|
|
requests => $self->{requests}, |
49
|
1
|
|
|
|
|
175
|
path => path($filename), |
50
|
|
|
|
|
|
|
}); |
51
|
1
|
|
|
|
|
6
|
my $path = path($self->{document_root}, $self->{index_file}); |
52
|
1
|
50
|
|
|
|
17
|
$path->remove if -f $path->absolute; |
53
|
1
|
|
|
|
|
55
|
$path->append_utf8($text); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub load_tx { |
57
|
3
|
|
|
3
|
0
|
6
|
my $dir = './share'; |
58
|
3
|
50
|
|
|
|
40
|
$dir = File::ShareDir::dist_dir('Test-JSON-RPC-Autodoc') unless -d $dir; |
59
|
3
|
|
|
|
|
32
|
return Text::Xslate->new( path => $dir ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
__END__ |