line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenAPI::Generator::From::Definitions; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
951
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
49
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
45
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
9
|
use Carp qw(croak); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
99
|
|
7
|
2
|
|
|
2
|
|
9
|
use File::Find; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
109
|
|
8
|
2
|
|
|
2
|
|
374
|
use OpenAPI::Generator::Util qw(merge_definitions); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
234
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
BEGIN { |
11
|
|
|
|
|
|
|
|
12
|
2
|
50
|
|
2
|
|
7
|
if (eval { require YAML::XS }) { |
|
2
|
50
|
|
|
|
250
|
|
13
|
0
|
|
|
|
|
0
|
YAML::XS->import('Load'); |
14
|
|
|
|
|
|
|
} |
15
|
2
|
|
|
|
|
237
|
elsif (eval { require YAML }) { |
16
|
0
|
|
|
|
|
0
|
YAML->import('Load'); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
else { |
19
|
2
|
|
|
|
|
489
|
require CPAN::Meta::YAML; |
20
|
2
|
|
|
|
|
5328
|
CPAN::Meta::YAML->import('Load'); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
2
|
50
|
|
|
|
7
|
if (eval { require JSON::XS }) { |
|
2
|
|
|
|
|
373
|
|
24
|
0
|
|
|
|
|
0
|
JSON::XS->import('decode_json') |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else { |
27
|
2
|
|
|
|
|
1189
|
require JSON::PP; |
28
|
2
|
|
|
|
|
24629
|
JSON::PP->import('decode_json'); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
2
|
1
|
7
|
bless {}, shift |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub generate { |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
2
|
1
|
3
|
my($self, $conf) = @_; |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
5
|
my $src = $conf->{src}; |
43
|
|
|
|
|
|
|
|
44
|
2
|
|
|
|
|
3
|
my @files; |
45
|
|
|
|
|
|
|
|
46
|
2
|
100
|
|
|
|
4
|
if ($src) { |
47
|
1
|
|
|
|
|
3
|
$self->_check_src($src); |
48
|
1
|
|
|
|
|
3
|
@files = $self->_src_as_files($src); |
49
|
|
|
|
|
|
|
|
50
|
1
|
50
|
|
|
|
3
|
if (!@files) { |
51
|
0
|
|
|
|
|
0
|
croak "no files found in $src"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
3
|
my @defs = @{ $conf->{definitions} }; |
|
2
|
|
|
|
|
4
|
|
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
5
|
for my $file (@files) { |
58
|
3
|
50
|
|
|
|
2988
|
croak "$file is not readable" unless -r $file; |
59
|
|
|
|
|
|
|
|
60
|
3
|
|
|
|
|
16
|
local $/ = ''; |
61
|
3
|
50
|
|
|
|
84
|
open my $fh, '<', $file or croak "can't open file $file"; |
62
|
3
|
|
|
|
|
49
|
my $content = <$fh>; |
63
|
3
|
|
|
|
|
23
|
close $fh; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
3
|
100
|
|
|
|
14
|
if ($file =~ /\.json$/) { |
67
|
1
|
|
|
|
|
3
|
push @defs, decode_json($content); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
2
|
|
|
|
|
7
|
push @defs, Load($content); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
597
|
merge_definitions(@defs) |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _check_src { |
78
|
|
|
|
|
|
|
|
79
|
1
|
50
|
33
|
1
|
|
32
|
croak "$_[1] is not file or directory" unless(-f $_[1] or -d $_[1]); |
80
|
1
|
50
|
|
|
|
14
|
croak "$_[1] is not readable" unless(-r $_[1]); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _src_as_files { |
84
|
|
|
|
|
|
|
|
85
|
1
|
50
|
|
1
|
|
10
|
return $_[1] if -f $_[1]; |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
2
|
my @files; |
88
|
1
|
100
|
|
4
|
|
104
|
find sub { push @files, $File::Find::name if /\.(yml|yaml|json)$/ }, $_[1]; |
|
4
|
|
|
|
|
171
|
|
89
|
|
|
|
|
|
|
@files |
90
|
1
|
|
|
|
|
6
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1 |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |