Zing/Env.pm untested

filter: Statementstmt 0.0% 0 / 64 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 15 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod n/a totaltotal 0.0% 0 / 91 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Zing::Env;
2  
3 use 5.014;
4  
5 use strict;
6 use warnings;
7  
8 use registry 'Zing::Types';
9 use routines;
10  
11 use Data::Object::Class;
12 use Data::Object::ClassHas;
13  
14 use Cwd ();
15 use Sys::Hostname ();
16  
17 our $VERSION = '0.26'; # VERSION
18  
19 # ATTRIBUTES
20  
21 has app => (
22 is => 'ro',
23 isa => 'App',
24 new => 1,
25 );
26  
27 fun new_app($self) {
28 require Zing::App; Zing::App->new(env => $self);
29 }
30  
31 has appdir => (
32 is => 'ro',
33 isa => 'Maybe[Str]',
34 new => 1,
35 );
36  
37 fun new_appdir($self) {
38 $ENV{ZING_APPDIR};
39 }
40  
41 has config => (
42 is => 'ro',
43 isa => 'HashRef[ArrayRef]',
44 new => 1,
45 );
46  
47 fun new_config($self) {
48 my $config = {};
49 for my $KEY (grep /ZING_CONFIG_/, keys %ENV) {
50 $config->{lc($KEY =~ s/ZING_CONFIG_//r)} = [
51 map +($$_[0], $#{$$_[1]} ? $$_[1] : $$_[1][0]),
52 map [$$_[0], [split /\|/, $$_[1]]],
53 map [split /=/], split /,\s*/,
54 $ENV{$KEY} || ''
55 ];
56 }
57 $config;
58 }
59  
60 has debug => (
61 is => 'ro',
62 isa => 'Maybe[Bool]',
63 new => 1,
64 );
65  
66 fun new_debug($self) {
67 $ENV{ZING_DEBUG}
68 }
69  
70 has encoder => (
71 is => 'ro',
72 isa => 'Maybe[Str]',
73 new => 1,
74 );
75  
76 fun new_encoder($self) {
77 $ENV{ZING_ENCODER} || 'Zing::Encoder::Dump'
78 }
79  
80 has handle => (
81 is => 'ro',
82 isa => 'Maybe[Str]',
83 new => 1,
84 );
85  
86 fun new_handle($self) {
87 $ENV{ZING_HANDLE} || $ENV{ZING_NS}
88 }
89  
90 has home => (
91 is => 'ro',
92 isa => 'Maybe[Str]',
93 new => 1,
94 );
95  
96 fun new_home($self) {
97 $ENV{ZING_HOME} || Cwd::getcwd
98 }
99  
100 has host => (
101 is => 'ro',
102 isa => 'Maybe[Str]',
103 new => 1,
104 );
105  
106 fun new_host($self) {
107 $ENV{ZING_HOST} || Sys::Hostname::hostname
108 }
109  
110 has piddir => (
111 is => 'ro',
112 isa => 'Maybe[Str]',
113 new => 1,
114 );
115  
116 fun new_piddir($self) {
117 $ENV{ZING_PIDDIR}
118 }
119  
120 has store => (
121 is => 'ro',
122 isa => 'Maybe[Str]',
123 new => 1,
124 );
125  
126 fun new_store($self) {
127 $ENV{ZING_STORE} || 'Zing::Store::Hash'
128 }
129  
130 has target => (
131 is => 'ro',
132 isa => 'Maybe[Name]',
133 new => 1,
134 );
135  
136 fun new_target($self) {
137 $ENV{ZING_TARGET}
138 }
139  
140 has system => (
141 is => 'ro',
142 isa => 'Name',
143 new => 1,
144 );
145  
146 fun new_system($self) {
147 'zing'
148 }
149  
150 1;
151  
152 =encoding utf8
153  
154 =head1 NAME
155  
156 Zing::Env - Zing Environment
157  
158 =cut
159  
160 =head1 ABSTRACT
161  
162 Zing Environment Abstraction
163  
164 =cut
165  
166 =head1 SYNOPSIS
167  
168 use Zing::Env;
169  
170 my $env = Zing::Env->new;
171  
172 =cut
173  
174 =head1 DESCRIPTION
175  
176 This package provides a L<Zing> environment abstraction to be used by
177 L<Zing::App> and other environment-aware objects.
178  
179 =cut
180  
181 =head1 LIBRARIES
182  
183 This package uses type constraints from:
184  
185 L<Zing::Types>
186  
187 =cut
188  
189 =head1 ATTRIBUTES
190  
191 This package has the following attributes:
192  
193 =cut
194  
195 =head2 app
196  
197 app(App)
198  
199 This attribute is read-only, accepts C<(App)> values, and is optional.
200  
201 =cut
202  
203 =head2 appdir
204  
205 appdir(Maybe[Str])
206  
207 This attribute is read-only, accepts C<(Maybe[Str])> values, and is optional.
208  
209 =cut
210  
211 =head2 config
212  
213 config(HashRef[ArrayRef])
214  
215 This attribute is read-only, accepts C<(HashRef[ArrayRef])> values, and is optional.
216  
217 =cut
218  
219 =head2 debug
220  
221 debug(Maybe[Bool])
222  
223 This attribute is read-only, accepts C<(Maybe[Bool])> values, and is optional.
224  
225 =cut
226  
227 =head2 encoder
228  
229 encoder(Maybe[Str])
230  
231 This attribute is read-only, accepts C<(Maybe[Str])> values, and is optional.
232  
233 =cut
234  
235 =head2 handle
236  
237 handle(Maybe[Str])
238  
239 This attribute is read-only, accepts C<(Maybe[Str])> values, and is optional.
240  
241 =cut
242  
243 =head2 home
244  
245 home(Maybe[Str])
246  
247 This attribute is read-only, accepts C<(Maybe[Str])> values, and is optional.
248  
249 =cut
250  
251 =head2 host
252  
253 host(Maybe[Str])
254  
255 This attribute is read-only, accepts C<(Maybe[Str])> values, and is optional.
256  
257 =cut
258  
259 =head2 piddir
260  
261 piddir(Maybe[Str])
262  
263 This attribute is read-only, accepts C<(Maybe[Str])> values, and is optional.
264  
265 =cut
266  
267 =head2 store
268  
269 store(Maybe[Str])
270  
271 This attribute is read-only, accepts C<(Maybe[Str])> values, and is optional.
272  
273 =cut
274  
275 =head2 system
276  
277 system(Name)
278  
279 This attribute is read-only, accepts C<(Name)> values, and is optional.
280  
281 =cut
282  
283 =head2 target
284  
285 target(Maybe[Name])
286  
287 This attribute is read-only, accepts C<(Maybe[Name])> values, and is optional.
288  
289 =cut
290  
291 =head1 AUTHOR
292  
293 Al Newkirk, C<awncorp@cpan.org>
294  
295 =head1 LICENSE
296  
297 Copyright (C) 2011-2019, Al Newkirk, et al.
298  
299 This is free software; you can redistribute it and/or modify it under the terms
300 of the The Apache License, Version 2.0, as elucidated in the L<"license
301 file"|https://github.com/iamalnewkirk/zing/blob/master/LICENSE>.
302  
303 =head1 PROJECT
304  
305 L<Wiki|https://github.com/iamalnewkirk/zing/wiki>
306  
307 L<Project|https://github.com/iamalnewkirk/zing>
308  
309 L<Initiatives|https://github.com/iamalnewkirk/zing/projects>
310  
311 L<Milestones|https://github.com/iamalnewkirk/zing/milestones>
312  
313 L<Contributing|https://github.com/iamalnewkirk/zing/blob/master/CONTRIBUTE.md>
314  
315 L<Issues|https://github.com/iamalnewkirk/zing/issues>
316  
317 =cut