PONAPI/Server/ConfigReader.pm

filter: Statementstmt 100% 65 / 65 Branchbran 50.0% 7 / 14 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 1 totaltotal 86.6% 91 / 105 CC 11 SCAR 8.1
CC
11
Cov
88%
_set_server_sorting
4.3
_set_server_send_header
3.1
_set_server_respond_to_updates_status
3.1
CRAP 2.2
« PONAPI/DAO/Request/CreateRelationships.pm ↑ Summary PONAPI/DAO/Request/Retrieve.pm »
1 # ABSTRACT: Web-Server - configuration handler
2 package PONAPI::Server::ConfigReader;
3  
4 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Path::Class::Dir;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use YAML::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use PONAPI::DAO;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 class_type 'Path::Class::Dir';
13 coerce 'Path::Class::Dir',
14 from 'Str',
15 9 ▶ via { Path::Class::Dir->new($_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
16  
17 3 has dir => (
18 is => 'ro',
19 isa => 'Path::Class::Dir',
20 coerce => 1,
21 required => 1,
22 );
23  
24 3 has config => (
25 is => 'ro',
26 isa => 'HashRef',
27 lazy => 1,
28 builder => '_build_conf',
29 );
30  
31 sub _build_conf {
32 9 ▶ my $self = shift;
Subroutine _build_conf: called CC=1 SCAR=0.0
33 9 return YAML::XS::Load( scalar $self->dir->file('server.yml')->slurp );
34 }
35  
36 sub read_config {
37 9 ▶ my $self = shift;
Subroutine read_config: called CC=1 SCAR=0.0
Pod undocumented
38  
39 9 $self->_set_server_json_api_version;
40  
41 9 $self->_set_server_sorting;
42 9 $self->_set_server_send_header;
43 9 $self->_set_server_self_link;
44 9 $self->_set_server_relative_links;
45 9 $self->_set_repository;
46 9 $self->_set_server_respond_to_updates_status;
47  
48 9 $self->{'ponapi.mediatype'} = 'application/vnd.api+json';
49  
50 9 return %{$self};
51 }
52  
53 sub _set_server_respond_to_updates_status {
54 9 ▶ my $self = shift;
Subroutine _set_server_respond_to_updates_status: called CC=3 SCAR=11.3
55  
56 9 my $server_update = $self->config->{server}{respond_to_updates_with_200};
57  
58 $self->{'ponapi.respond_to_updates_with_200'} =
59 27 ▶ ( grep { $server_update eq $_ } qw< yes true 1 > ) ? 1 :
Branch: 1 branch
BranchTrueFalseTotal
grep({$server_update eq $_;} 'no', 'false', '0') ? : 9 0 9
60 9 ▶ ( grep { $server_update eq $_ } qw< no false 0 > ) ? 0 :
Branch: 1 branch
BranchTrueFalseTotal
grep({$server_update eq $_;} 'yes', 'true', '1') ? : 0 9 9
61 die "[PONAPI Server] server respond_to_updates_with_200 is misconfigured";
62  
63 }
64  
65 sub _set_server_sorting {
66 9 ▶ my $self = shift;
Subroutine _set_server_sorting: called CC=4 SCAR=14.6
67  
68 my $sort_allowed = $self->config->{server}{sort_allowed}
69 9 ▶ // die "[PONAPI Server] server sorting configuration is missing";
Condition50%1/2
$self->config->{"server"}{"sort_allowed"} // die("[PONAPI Server] server sorting configuration is missing")
l!l
90
MC/DC0%0/1
$self->config->{"server"}{"sort_allowed"} // die("[PONAPI Server] server sorting configuration is missing")
$self->config->{"server"}{"sort_allowed"}
Truth table50%1/2
A
A= $self->config->{"server"}{"sort_allowed"}
Aresult
11
00
70  
71 $self->{'ponapi.sort_allowed'} =
72 27 ▶ ( grep { $sort_allowed eq $_ } qw< yes true 1 > ) ? 1 :
Branch: 1 branch
BranchTrueFalseTotal
grep({$sort_allowed eq $_;} 'no', 'false', '0') ? : 9 0 9
73 9 ▶ ( grep { $sort_allowed eq $_ } qw< no false 0 > ) ? 0 :
Branch: 1 branch
BranchTrueFalseTotal
grep({$sort_allowed eq $_;} 'yes', 'true', '1') ? : 0 9 9
74 die "[PONAPI Server] server sorting is misconfigured";
75 }
76  
77 sub _set_server_json_api_version {
78 9 ▶ my $self = shift;
Subroutine _set_server_json_api_version: called CC=2 SCAR=7.1
79  
80 my $spec_version = $self->config->{server}{spec_version}
81 9 ▶ // die "[PONAPI Server] server JSON API version configuration is missing";
Condition50%1/2
$self->config->{"server"}{"spec_version"} // die("[PONAPI Server] server JSON API version configuration is missing")
l!l
90
MC/DC0%0/1
$self->config->{"server"}{"spec_version"} // die("[PONAPI Server] server JSON API version configuration is missing")
$self->config->{"server"}{"spec_version"}
Truth table50%1/2
A
A= $self->config->{"server"}{"spec_version"}
Aresult
11
00
82  
83 9 $self->{'ponapi.spec_version'} = $spec_version;
84 }
85  
86 sub _set_server_send_header {
87 9 ▶ my $self = shift;
Subroutine _set_server_send_header: called CC=3 SCAR=11.4
88  
89 $self->{'ponapi.spec_version'} = $self->config->{server}{spec_version}
90 9 ▶ // die "[PONAPI Server] server spec version is not configured";
Condition50%1/2
$self->config->{"server"}{"spec_version"} // die("[PONAPI Server] server spec version is not configured")
l!l
90
MC/DC0%0/1
$self->config->{"server"}{"spec_version"} // die("[PONAPI Server] server spec version is not configured")
$self->config->{"server"}{"spec_version"}
Truth table50%1/2
A
A= $self->config->{"server"}{"spec_version"}
Aresult
11
00
91  
92 $self->{'ponapi.send_version_header'} =
93 9 ▶ ( grep { $self->config->{server}{send_version_header} eq $_ } qw< yes true 1 > ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({$self->config->{'server'}{'send_version_header'} eq $_;} 'yes', 'true', '1') ? : 9 0 9
94 }
95  
96 sub _set_server_self_link {
97 9 ▶ my $self = shift;
Subroutine _set_server_self_link: called CC=2 SCAR=7.1
98  
99 $self->{'ponapi.doc_auto_self_link'} =
100 9 ▶ ( grep { $self->config->{server}{send_document_self_link} eq $_ } qw< yes true 1 > ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({$self->config->{'server'}{'send_document_self_link'} eq $_;} 'yes', 'true', '1') ? : 9 0 9
101 }
102  
103 sub _set_server_relative_links {
104 9 ▶ my $self = shift;
Subroutine _set_server_relative_links: called CC=2 SCAR=7.0
105  
106 9 ▶ grep { $self->config->{server}{links_type} eq $_ } qw< relative full >
Branch: 1 branch
BranchTrueFalseTotal
grep {$self->config->{"server"}{"links_type"} eq $_;} "relative", "full" or die "[PONAPI Server] server links_type is misconfigured" 0 9 9
107 or die "[PONAPI Server] server links_type is misconfigured";
108  
109 9 $self->{'ponapi.relative_links'} = $self->config->{server}{links_type};
110 }
111  
112 sub _set_repository {
113 9 ▶ my $self = shift;
Subroutine _set_repository: called CC=1 SCAR=0.0
114 9 $self->{'repository.class'} = $self->config->{repository}{class};
115 9 $self->{'repository.args'} = $self->config->{repository}{args};
116 }
117  
118 3 __PACKAGE__->meta->make_immutable;
119 3 ▶no Moose; 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
120  
121 __END__
122  
123 =pod
124  
125 =encoding UTF-8
126  
127 =head1 NAME
128  
129 PONAPI::Server::ConfigReader - Web-Server - configuration handler
130  
131 =head1 VERSION
132  
133 version 0.003002
134  
135 =head1 AUTHORS
136  
137 =over 4
138  
139 =item *
140  
141 Mickey Nasriachi <mickey@cpan.org>
142  
143 =item *
144  
145 Stevan Little <stevan@cpan.org>
146  
147 =item *
148  
149 Brian Fraser <hugmeir@cpan.org>
150  
151 =back
152  
153 =head1 COPYRIGHT AND LICENSE
154  
155 This software is copyright (c) 2017 by Mickey Nasriachi, Stevan Little, Brian Fraser.
156  
157 This is free software; you can redistribute it and/or modify it under
158 the same terms as the Perl 5 programming language system itself.
159  
160 =cut
« PONAPI/DAO/Request/CreateRelationships.pm ↑ Summary PONAPI/DAO/Request/Retrieve.pm »