Generator/Util.pm

filter: Statementstmt 90.7% 39 / 43 Branchbran 77.2% 17 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 87.3% 62 / 71 SCAR 26.0
CC
13
Cov
86%
merge_definitions
13.9
BEGIN
1.0
BEGIN
1.0
CRAP 13.4
« Generator/From/Definitions.pm ↑ Summary Generator.pm »
1 package OpenAPI::Generator::Util;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our @EXPORT_OK = qw(
10 merge_definitions
11 );
12  
13 sub merge_definitions {
14  
15 3 ▶ my(@definitions) = @_;
Subroutine merge_definitions: called CC=13 SCAR=26.3
Pod documented
16  
17 3 ▶ croak 'no definitions to merge' unless @definitions;
Branch: 1 branch
BranchTrueFalseTotal
unless @definitions 0 3 3
18  
19 3 ▶ if (scalar @definitions == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @definitions == 1) 1 2 3
20 1 return $definitions[0];
21 }
22  
23 2 my %common_def = (
24 paths => {},
25 components => {
26 schemas => {},
27 securitySchemes => {},
28 parameters => {}
29 },
30 );
31  
32 2 for my $def (@definitions) {
33  
34 # paths
35 6 ▶ while (my($path, $path_schema) = each %{$def->{paths}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$def{"paths"};}) 8 6 14
36 8 ▶ while (my($method, $method_schema) = each %{$path_schema}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$path_schema;}) 8 8 16
37 8 ▶ if (exists $common_def{paths}{$path}{$method}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $common_def{"paths"}{$path}{$method}) 0 8 8
38 0 croak "$method $path duplicates";
39 }
40 8 $common_def{paths}{$path}{$method} = $method_schema;
41 }
42 }
43  
44 # comp param
45 6 ▶ while (my($param, $param_schema) = each %{$def->{components}{parameters}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$def{"components"}{"parameters"};}) 5 6 11
46 5 ▶ if (exists $common_def{components}{parameters}{$param}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $common_def{"components"}{"parameters"}{$param}) 0 5 5
47 0 croak "param $param duplicates"
48 }
49 5 $common_def{components}{parameters}{$param} = $param_schema;
50 }
51  
52 # comp schemas
53 6 ▶ while (my($comp, $comp_schema) = each %{$def->{components}{schemas}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$def{"components"}{"schemas"};}) 5 6 11
54 5 ▶ if (exists $common_def{components}{schemas}{$comp}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $common_def{"components"}{"schemas"}{$comp}) 0 5 5
55 0 croak "schema $comp duplicates"
56 }
57 5 $common_def{components}{schemas}{$comp} = $comp_schema;
58 }
59  
60 # comp security
61 6 ▶ while (my($security, $security_schema) = each %{$def->{components}{securitySchemes}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$def{"components"}{"securitySchemes"};}) 5 6 11
62 5 ▶ if (exists $common_def{components}{securitySchemes}{$security}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $common_def{"components"}{"securitySchemes"}{$security}) 0 5 5
63 0 croak "security $security duplicates"
64 }
65 5 $common_def{components}{securitySchemes}{$security} = $security_schema;
66 }
67 }
68  
69 2 return \%common_def;
70 }
71  
72 3 1
73  
74 __END__
« Generator/From/Definitions.pm ↑ Summary Generator.pm »