PONAPI/Server/ConfigReader.pm

filter: Statementstmt 96.7% 59 / 61 Branchbran 50.0% 5 / 10 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 93.7% 15 / 16 Podpod 0.0% 0 / 1 totaltotal 84.5% 82 / 97 CC 9 SCAR 7.5
CC
9
Cov
87%
_set_server_sorting
4.3
_set_server_send_header
3.1
_set_server_json_api_version
2.0
CRAP 2.1
« PONAPI/DAO/Request/Retrieve.pm ↑ Summary PONAPI/DAO/Request/UpdateRelationships.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  
47 9 $self->{'ponapi.mediatype'} = 'application/vnd.api+json';
48  
49 9 return %{$self};
50 }
51  
52 sub _set_server_respond_to_updates_status {
53 0 ▶ my $self = shift;
Subroutine _set_server_respond_to_updates_status: not called CC=1 SCAR=6.9
54  
55 $self->{'ponapi.respond_to_updates_with_200'} =
56 0 $self->config->{server}{respond_to_updates_with_200};
57 }
58  
59 sub _set_server_sorting {
60 9 ▶ my $self = shift;
Subroutine _set_server_sorting: called CC=4 SCAR=14.6
61  
62 my $sort_allowed = $self->config->{server}{sort_allowed}
63 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
64  
65 $self->{'ponapi.sort_allowed'} =
66 27 ▶ ( grep { $sort_allowed eq $_ } qw< yes true 1 > ) ? 1 :
Branch: 1 branch
BranchTrueFalseTotal
grep({$sort_allowed eq $_;} 'no', 'false', '0') ? : 9 0 9
67 9 ▶ ( grep { $sort_allowed eq $_ } qw< no false 0 > ) ? 0 :
Branch: 1 branch
BranchTrueFalseTotal
grep({$sort_allowed eq $_;} 'yes', 'true', '1') ? : 0 9 9
68 die "[PONAPI Server] server sorting is misconfigured";
69 }
70  
71 sub _set_server_json_api_version {
72 9 ▶ my $self = shift;
Subroutine _set_server_json_api_version: called CC=2 SCAR=7.1
73  
74 my $spec_version = $self->config->{server}{spec_version}
75 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
76  
77 9 $self->{'ponapi.spec_version'} = $spec_version;
78 }
79  
80 sub _set_server_send_header {
81 9 ▶ my $self = shift;
Subroutine _set_server_send_header: called CC=3 SCAR=11.4
82  
83 $self->{'ponapi.spec_version'} = $self->config->{server}{spec_version}
84 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
85  
86 $self->{'ponapi.send_version_header'} =
87 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
88 }
89  
90 sub _set_server_self_link {
91 9 ▶ my $self = shift;
Subroutine _set_server_self_link: called CC=2 SCAR=7.1
92  
93 $self->{'ponapi.doc_auto_self_link'} =
94 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
95 }
96  
97 sub _set_server_relative_links {
98 9 ▶ my $self = shift;
Subroutine _set_server_relative_links: called CC=2 SCAR=7.0
99  
100 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
101 or die "[PONAPI Server] server links_type is misconfigured";
102  
103 9 $self->{'ponapi.relative_links'} = $self->config->{server}{links_type};
104 }
105  
106 sub _set_repository {
107 9 ▶ my $self = shift;
Subroutine _set_repository: called CC=1 SCAR=0.0
108 9 $self->{'repository.class'} = $self->config->{repository}{class};
109 9 $self->{'repository.args'} = $self->config->{repository}{args};
110 }
111  
112 3 __PACKAGE__->meta->make_immutable;
113 3 ▶no Moose; 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
114  
115 __END__
116  
117 =pod
118  
119 =encoding UTF-8
120  
121 =head1 NAME
122  
123 PONAPI::Server::ConfigReader - Web-Server - configuration handler
124  
125 =head1 VERSION
126  
127 version 0.002012
128  
129 =head1 AUTHORS
130  
131 =over 4
132  
133 =item *
134  
135 Mickey Nasriachi <mickey@cpan.org>
136  
137 =item *
138  
139 Stevan Little <stevan@cpan.org>
140  
141 =item *
142  
143 Brian Fraser <hugmeir@cpan.org>
144  
145 =back
146  
147 =head1 COPYRIGHT AND LICENSE
148  
149 This software is copyright (c) 2016 by Mickey Nasriachi, Stevan Little, Brian Fraser.
150  
151 This is free software; you can redistribute it and/or modify it under
152 the same terms as the Perl 5 programming language system itself.
153  
154 =cut
« PONAPI/DAO/Request/Retrieve.pm ↑ Summary PONAPI/DAO/Request/UpdateRelationships.pm »