Shodo/Hanshi.pm

filter: Statementstmt 100% 21 / 21 Branchbran n/a Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 4 totaltotal 78.3% 29 / 37 CC 2 SCAR 2.4
CC
2
Cov
92%
render
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« Test/Shodo/JSONRPC.pm ↑ Summary
1 package Shodo::Hanshi;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Text::MicroTemplate qw/render_mt encoded_string/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
7 5 my ($class, %args) = @_;
8 5 my $self = bless { template => $args{template} }, $class;
9 5 $self;
10 }
11  
12 4 ▶sub render {
Subroutine render: called CC=2 SCAR=7.4
Pod undocumented
13 4 my ($self, $stash) = @_;
14 4 ▶ my $tmpl = $self->{template} || $self->default_template;
Condition33%1/3
$self->{'template'} || $self->default_template
l!l&&r!l&&!r
040
MC/DC0%0/2
$self->{'template'} || $self->default_template
$self->{'template'} $self->default_template
Truth table33%1/3
A || B
A= $self->{'template'}B= $self->default_template
ABresult
1X1
011
000
15 4 my $renderer = render_mt($self->header . $tmpl, $stash);
16 4 return $renderer->as_string();
17 }
18  
19 4 ▶sub header {
Subroutine header: called CC=1 SCAR=0.0
Pod undocumented
20 4 my $tmpl = <<'END';
21 ? my ($stash) = @_;
22 ? no strict qw/refs vars/;
23 ? no warnings;
24 ? for my $key (keys %$stash) {
25 ? if (ref $stash->{$key}) {
26 ? ${$key} = $stash->{$key};
27 ? }else{
28 ? ${$key} = encoded_string($stash->{$key});
29 ? }
30 ? }
31 ? use warnings;
32 ? use strict qw/refs subs/;
33 END
34 4 return $tmpl;
35 }
36  
37 4 ▶sub default_template {
Subroutine default_template: called CC=1 SCAR=0.0
Pod undocumented
38 4 my $tmpl = <<'END';
39 ## <?= $method ?> <?= $path ?>
40  
41 ? if ($description) {
42 <?= $description ?>
43 ? }
44  
45 ### Request
46  
47 ```json
48 <?= $method ?> <?= $path ?><?= $query ? '?'.$query : '' ?>
49  
50 <?= $request_body ?>
51 ```
52 ? if ($rule) {
53  
54 ### Parameters
55  
56 ? for my $name (keys %$rule) {
57 * `<?= $name ?>` - <?= $rule->{$name}{documentation} || '' ?>
58 ? for my $key (keys %{$rule->{$name}}) {
59 ? next if $key eq 'documentation';
60 ? if ($rule->{$name}{$key}) {
61 * <?= $key ?>: **<?= $rule->{$name}{$key} || '' ?>**
62 ? }
63 ? }
64 ? }
65 ? }
66  
67 ### Response
68  
69 ```json
70 Status: <?= $code ?>
71  
72 <?= $response_body ?>
73 ```
74  
75 ---
76  
77 END
78 4 return $tmpl;
79 }
80  
81 5 1;
« Test/Shodo/JSONRPC.pm ↑ Summary