blib/lib/Web/API/Mock/Parser.pm

filter: Statementstmt 98.6% 74 / 75 Branchbran 83.3% 10 / 12 Conditioncond 66.6% 14 / 21 MC/DCmcdc 30.0% 3 / 10 Subroutinesub 89.4% 17 / 19 Podpod 0.0% 0 / 1 totaltotal 85.5% 118 / 138 SCAR 29.0
CC
18
Cov
91%
_add_api
13.4
__ANON__
5.0
create_map
3.0
CRAP 18.3
↑ Summary blib/lib/Web/API/Mock.pm »
1 package Web::API::Mock::Parser;
2 5 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 our $VERSION = "0.01";
7  
8 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use B qw(perlstring);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Text::Markdown::Hoedown;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Web::API::Mock::Map;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 use Class::Accessor::Lite (
13 5 new => 1,
14 rw => [ qw/map md cb _resource_name _paragraph _url _method _status _content_type _header _body api/ ],
15 5 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 sub create_map {
18 4 ▶ my $self =shift;
Subroutine create_map: called CC=3 SCAR=11.1
Pod undocumented
19  
20 4 $self->_callback();
21  
22 4 my $md = Text::Markdown::Hoedown::Markdown->new(HOEDOWN_EXT_AUTOLINK, 16, $self->cb);
23  
24 4 eval {
25 4 $md->render($self->md);
26 };
27 4 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
28 0 die "cannot parse markdown. $@";
29 }
30  
31 4 my $map = Web::API::Mock::Map->new();
32 4 $map->init();
33 4 for my $name ( keys %{$self->api} ) {
34 $map->add_resource( $self->api->{$name}->{url}, {
35 status => $self->api->{$name}->{status},
36 content_type => $self->api->{$name}->{content_type},
37 method => $self->api->{$name}->{method},
38 header => $self->api->{$name}->{header},
39 body => $self->api->{$name}->{body}
40 16 });
41 }
42  
43 4 return $map;
44 }
45  
46 sub _callback {
47 4 ▶ my $self = shift;
Subroutine _callback: called CC=1 SCAR=0.0
48  
49 4 $self->api({});
50  
51 4 my $cb = Text::Markdown::Hoedown::Renderer::Callback->new();
52  
53 $cb->blockcode( sub {
54 25 ▶ return unless $self->_resource_name;
Subroutine __ANON__: called CC=5 SCAR=16.1
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_resource_name 0 25 25
55  
56 25 ▶ if ( $self->_paragraph =~ /^body/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_paragraph =~ /^body/i) { } 15 10 25
elsif ($self->_paragraph =~ /^header/i) { } 9 1 10
57 15 $self->_body($_[0]);
58 }
59 elsif ( $self->_paragraph =~ /^header/i ) {
60 9 my @line = split("\n", $_[0]);
61 9 for (@line) {
62 11 my ($key, $value) = split(':',$_);
63 11 chomp $value;
64 11 $value =~ s/^ +//g;
65 11 $self->_header->{$key} = $value;
66 }
67 }
68 else {
69 1 $self->_body($_[0]);
70 }
71  
72 4 } );
73  
74 # TODO
75 4 ▶ $cb->blockquote( sub {} );
Subroutine __ANON__: not called CC=1 SCAR=0.0
76  
77 # TODO
78 4 ▶ $cb->blockhtml( sub {} );
Subroutine __ANON__: not called CC=1 SCAR=0.0
79  
80 $cb->header( sub {
81 21 ▶ $self->_add_api();
Subroutine __ANON__: called CC=1 SCAR=0.0
82  
83 21 my ($method, $url) = split(' ', $_[0]);
84 21 $self->_header({});
85 21 $self->_body('');
86 21 $self->_url($url);
87 21 $self->_method($method);
88 21 $self->_resource_name($_[0]);
89 4 } );
90  
91 $cb->paragraph( sub {
92 60 ▶ $self->_paragraph($_[0]);
Subroutine __ANON__: called CC=1 SCAR=0.0
93 4 } );
94  
95 # TODO
96 4 ▶ $cb->list(sub{});
Subroutine __ANON__: called CC=1 SCAR=0.0
97  
98 $cb->listitem(sub{
99 58 ▶ if ( $_[0] =~ /^response +(\d+) +\((.+?)\)/i ) {
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^response +(\d+) +\((.+?)\)/i) 17 41 58
100 17 $self->_status($1);
101 17 $self->_content_type($2);
102 }
103 4 });
104  
105 $cb->doc_footer(sub{
106 4 ▶ $self->_add_api();
Subroutine __ANON__: called CC=1 SCAR=0.0
107 4 });
108  
109 4 $self->cb($cb);
110 }
111  
112 sub _add_api {
113 25 ▶ my $self = shift;
Subroutine _add_api: called CC=11 SCAR=25.9
114 # APIドキュメント上でコメント等に利用するため
115 # GET,POST,PUT,DELETE以外のメソッドは無視する
116 25 ▶ if ( $self->_resource_name && $self->_url && $self->_method &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_resource_name and $self->_url and $self->_method and $self->_method =~ /^(GET|POST|PUT|DELETE)$/) 16 9 25
Condition88%8/9
$self->_resource_name and $self->_url and $self->_method and $self->_method =~ /^(GET|POST|PUT|DELETE)$/
!ll&&!rl&&r
6316
$self->_resource_name and $self->_url and $self->_method
!ll&&!rl&&r
6019
$self->_resource_name and $self->_url
!ll&&!rl&&r
4219
MC/DC75%3/4
$self->_resource_name and $self->_url and $self->_method and $self->_method =~ /^(GET|POST|PUT|DELETE)$/
$self->_resource_name $self->_url $self->_method $self->_method =~ /^(GET|POST|PUT|DELETE)$/
Truth table80%4/5
A and B and C and D
A= $self->_resource_nameB= $self->_urlC= $self->_methodD= $self->_method =~ /^(GET|POST|PUT|DELETE)$/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
117 $self->_method =~ /^(GET|POST|PUT|DELETE)$/ ) {
118 16 ▶ $self->api->{$self->_resource_name} = {
Condition50%6/12
$self->_content_type // ""
l!l
160
$self->_status // ""
l!l
160
$self->_url // ""
l!l
160
$self->_method // ""
l!l
160
$self->_header // {}
l!l
160
$self->_body // ""
l!l
160
MC/DC0%0/1
$self->_content_type // ""
$self->_content_type
MC/DC0%0/1
$self->_status // ""
$self->_status
MC/DC0%0/1
$self->_url // ""
$self->_url
MC/DC0%0/1
$self->_method // ""
$self->_method
MC/DC0%0/1
$self->_header // {}
$self->_header
MC/DC0%0/1
$self->_body // ""
$self->_body
Truth table50%1/2
A
A= $self->_content_type
Aresult
11
00
Truth table50%1/2
A
A= $self->_status
Aresult
11
00
Truth table50%1/2
A
A= $self->_url
Aresult
11
00
Truth table50%1/2
A
A= $self->_method
Aresult
11
00
Truth table50%1/2
A
A= $self->_header
Aresult
11
00
Truth table50%1/2
A
A= $self->_body
Aresult
11
00
119 content_type => $self->_content_type // '',
120 status => $self->_status // '',
121 url => $self->_url // '',
122 method => $self->_method // '',
123 header => $self->_header // {},
124 body => $self->_body // '',
125 };
126 }
127 }
128  
129 5 1;
↑ Summary blib/lib/Web/API/Mock.pm »