Generator/From/Definitions.pm

filter: Statementstmt 98.0% 49 / 50 Branchbran 62.5% 10 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 13 / 13 Podpod 100% 2 / 2 totaltotal 87.2% 75 / 86 SCAR 24.2
CC
11
Cov
87%
generate
6.1
_check_src
5.4
_src_as_files
2.0
CRAP 11.3
« Generator/Util.pm ↑ Summary Generator.pm »
1 package OpenAPI::Generator::From::Definitions;
2  
3 2 ▶use 5.012;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use JSON::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use OpenAPI::Generator::Util qw(merge_definitions);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub new {
14  
15 1 ▶ bless {}, shift
Subroutine new: called CC=1 SCAR=0.0
Pod documented
16 }
17  
18 sub generate {
19  
20 1 ▶ my($self, $conf) = @_;
Subroutine generate: called CC=6 SCAR=18.1
Pod documented
21  
22 1 my $src = $conf->{src};
23 1 $self->_check_src($src);
24 1 my @files = $self->_src_as_files($src);
25  
26 1 ▶ if (!@files) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@files) 0 1 1
27 0 croak "no files found in $src";
28 }
29  
30 1 my @defs = @{ $conf->{definitions} };
31  
32 1 for my $file (@files) {
33 3 ▶ croak "$file is not readable" unless -r $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $file 0 3 3
34  
35 3 local $/ = '';
36 3 ▶ open my $fh, '<', $file or croak "can't open file $file";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or croak("can't open file $file") 0 3 3
37 3 my $content = <$fh>;
38 3 close $fh;
39  
40  
41 3 ▶ if ($file =~ /\.json$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.json$/u) { } 1 2 3
42 1 push @defs, JSON::PP::decode_json($content);
43 }
44 else {
45 2 push @defs, YAML::Load($content);
46 }
47 }
48  
49 1 merge_definitions(@defs)
50 }
51  
52 sub _check_src {
53  
54 1 ▶ croak "$_[1] is not file or directory" unless(-f $_[1] or -d $_[1]);
Subroutine _check_src: called CC=4 SCAR=16.9
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_[1] or -d $_[1] 0 1 1
Condition33%1/3
-f $_[1] or -d $_[1]
l!l&&r!l&&!r
010
MC/DC0%0/2
-f $_[1] or -d $_[1]
-f $_[1] -d $_[1]
Truth table33%1/3
A or B
A= -f $_[1]B= -d $_[1]
ABresult
1X1
011
000
55 1 ▶ croak "$_[1] is not readable" unless(-r $_[1]);
Branch: 1 branch
BranchTrueFalseTotal
unless -r $_[1] 0 1 1
56 }
57  
58 sub _src_as_files {
59  
60 1 ▶ return $_[1] if -f $_[1];
Subroutine _src_as_files: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
if -f $_[1] 0 1 1
61  
62 1 my @files;
63 1 ▶ find sub { push @files, $File::Find::name if /\.(yml|yaml|json)$/ }, $_[1];
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if /\.(yml|yaml|json)$/u 3 1 4
64 @files
65 1 }
66  
67 2 1
68  
69 __END__
« Generator/Util.pm ↑ Summary Generator.pm »