Render/HTMLForms.pm

filter: Statementstmt 100% 41 / 41 Branchbran 86.3% 19 / 22 Conditioncond 88.8% 16 / 18 MC/DCmcdc 80.0% 8 / 10 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 6 totaltotal 87.8% 94 / 107 SCAR 28.9
CC
18
Cov
94%
parameter
15.1
operation_footer
3.0
operation_header
2.1
CRAP 18.1
« Render/reStructuredText.pm ↑ Summary Render.pm »
1 package OpenAPI::Render::HTMLForms;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.2.0'; # VERSION
7  
8 1 ▶use CGI qw(-nosticky -utf8 h1 h2 h3 p input filefield popup_menu legend submit start_div end_div start_fieldset end_fieldset start_form end_form start_html end_html);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use parent qw(OpenAPI::Render);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub header
13 {
14 1 ▶ my( $self ) = @_;
Subroutine header: called CC=1 SCAR=0.0
Pod undocumented
15 return start_html( -title => $self->{api}{info}{title} . ' v' .
16 $self->{api}{info}{version},
17 1 -script =>
18 '
19  
20 function replace_url_parameters( form ) {
21 var url = form.getAttribute( "action" );
22 var inputs = form.getElementsByTagName( "input" );
23 for( var i = 0; i < inputs.length; i++ ) {
24 var data_in_path = inputs[i].getAttribute( "data-in-path" );
25 if( data_in_path ) {
26 url = url.replace( "{" + inputs[i].name + "}", inputs[i].value );
27 inputs[i].disabled = "disabled";
28 }
29 }
30 form.setAttribute( "action", url );
31 }
32  
33 ' );
34 }
35  
36 sub footer
37 {
38 1 ▶ return end_html;
Subroutine footer: called CC=1 SCAR=0.0
Pod undocumented
39 }
40  
41 sub path_header
42 {
43 3 ▶ my( $self, $path ) = @_;
Subroutine path_header: called CC=1 SCAR=0.0
Pod undocumented
44 3 return h1( $path );
45 }
46  
47 sub operation_header
48 {
49 10 ▶ my( $self, $path, $operation ) = @_;
Subroutine operation_header: called CC=2 SCAR=7.2
Pod undocumented
50 return start_form( -action => $self->{base_url} . $path,
51 -method => $operation ) .
52 start_fieldset .
53 legend( uc( $operation ) .
54 ( $self->{api}{paths}{$path}{$operation}{description}
55 10 ▶ ? ': ' . $self->{api}{paths}{$path}{$operation}{description} : '' ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'api'}{'paths'}{$path}{$operation}{'description'} ? : 10 0 10
56 }
57  
58 sub operation_footer
59 {
60 10 ▶ my( $self, $path, $operation ) = @_;
Subroutine operation_footer: called CC=3 SCAR=11.0
Pod undocumented
61  
62 10 my %submit_options;
63 10 ▶ if( $operation eq 'get' || $operation eq 'post' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($operation eq 'get' or $operation eq 'post') { } 5 5 10
Condition100%3/3
$operation eq "get" or $operation eq "post"
l!l&&r!l&&!r
325
MC/DC100%2/2
$operation eq "get" or $operation eq "post"
$operation eq "get" $operation eq "post"
Truth table100%3/3
A or B
A= $operation eq "get"B= $operation eq "post"
ABresult
1X1
011
000
64 5 $submit_options{-onclick} = 'replace_url_parameters( this.form )';
65 } else {
66 $submit_options{-name} =
67 5 sprintf 'Submit Query (cannot be handled for %s)',
68 uc $operation;
69 5 $submit_options{-disabled} = 'disabled';
70 }
71  
72 10 return submit( %submit_options ) . end_fieldset . end_form;
73 }
74  
75 sub parameter
76 {
77 74 ▶ my( $self, $parameter ) = @_;
Subroutine parameter: called CC=15 SCAR=27.2
Pod undocumented
78 74 my @parameter;
79 74 ▶ return @parameter if $parameter->{'x-is-pattern'};
Branch: 1 branch
BranchTrueFalseTotal
if $parameter->{"x-is-pattern"} 6 68 74
80  
81 push @parameter,
82 h3( $parameter->{name} ),
83 68 ▶ $parameter->{description} ? p( $parameter->{description} ) : ();
Branch: 1 branch
BranchTrueFalseTotal
$parameter->{'description'} ? : 31 37 68
84 68 ▶ if( $parameter->{schema} && $parameter->{schema}{enum} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($parameter->{'schema'} and $parameter->{'schema'}{'enum'}) { } 6 62 68
elsif ($parameter->{'schema'}{'type'} and $parameter->{'schema'}{'type'} eq 'object' or $parameter->{'schema'}{'format'} and $parameter->{'schema'}{'format'} eq 'binary') { } 36 26 62
Condition100%3/3
$parameter->{"schema"} and $parameter->{"schema"}{"enum"}
!ll&&!rl&&r
1616
MC/DC100%2/2
$parameter->{"schema"} and $parameter->{"schema"}{"enum"}
$parameter->{"schema"} $parameter->{"schema"}{"enum"}
Truth table100%3/3
A and B
A= $parameter->{"schema"}B= $parameter->{"schema"}{"enum"}
ABresult
0X0
100
111
85 6 my @values = @{$parameter->{schema}{enum}};
86 6 ▶ if( !$parameter->{required} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parameter->{"required"}) 6 0 6
87 6 unshift @values, '';
88 }
89 push @parameter,
90 popup_menu( -name => $parameter->{name},
91 -values => \@values,
92 6 ▶ ($parameter->{in} eq 'path'
Branch: 1 branch
BranchTrueFalseTotal
$parameter->{'in'} eq 'path' ? : 0 6 6
93 ? ( '-data-in-path' => 1 ) : ()) );
94 ▶ } elsif( ($parameter->{schema}{type} &&
Condition88%8/9
$parameter->{"schema"}{"type"} and $parameter->{"schema"}{"type"} eq "object" or $parameter->{"schema"}{"format"} and $parameter->{"schema"}{"format"} eq "binary"
l!l&&r!l&&!r
63026
$parameter->{"schema"}{"type"} and $parameter->{"schema"}{"type"} eq "object"
!ll&&!rl&&r
1556
$parameter->{"schema"}{"format"} and $parameter->{"schema"}{"format"} eq "binary"
!ll&&!rl&&r
26030
MC/DC75%3/4
$parameter->{"schema"}{"type"} and $parameter->{"schema"}{"type"} eq "object" or $parameter->{"schema"}{"format"} and $parameter->{"schema"}{"format"} eq "binary"
$parameter->{"schema"}{"type"} $parameter->{"schema"}{"type"} eq "object" $parameter->{"schema"}{"format"} $parameter->{"schema"}{"format"} eq "binary"
Truth table57%4/7
A and B or C and D
A= $parameter->{"schema"}{"type"}B= $parameter->{"schema"}{"type"} eq "object"C= $parameter->{"schema"}{"format"}D= $parameter->{"schema"}{"format"} eq "binary"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
95 $parameter->{schema}{type} eq 'object') ||
96 ($parameter->{schema}{format} &&
97 $parameter->{schema}{format} eq 'binary') ) {
98 push @parameter,
99 36 filefield( -name => $parameter->{name} );
100 } else {
101 push @parameter,
102 input( { -type => 'text',
103 -name => $parameter->{name},
104 ($parameter->{in} eq 'path'
105 ? ( '-data-in-path' => 1 ) : ()),
106 (exists $parameter->{example}
107 ? ( -placeholder => $parameter->{example} )
108 : ()),
109 ($parameter->{in} eq 'path' || $parameter->{required}
110 26 ▶ ? ( -required => 'required' ) : ()) } );
Branch: 3 branches
BranchTrueFalseTotal
$parameter->{'in'} eq 'path' ? : 17 9 26
exists $parameter->{'example'} ? : 23 3 26
$parameter->{'in'} eq 'path' || $parameter->{'required'} ? : 17 9 26
Condition66%2/3
$parameter->{"in"} eq "path" or $parameter->{"required"}
l!l&&r!l&&!r
1709
MC/DC50%1/2
$parameter->{"in"} eq "path" or $parameter->{"required"}
$parameter->{"in"} eq "path" $parameter->{"required"}
Truth table66%2/3
A or B
A= $parameter->{"in"} eq "path"B= $parameter->{"required"}
ABresult
1X1
011
000
111 }
112 68 return @parameter;
113 }
114  
115 1 1;
« Render/reStructuredText.pm ↑ Summary Render.pm »