Suffit/Const.pm

filter: Statementstmt 75.0% 54 / 72 Branchbran 50.0% 7 / 14 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 28.0% 7 / 25 Podpod n/a totaltotal 58.8% 70 / 119 CC 3 SCAR 2.8
CC
3
Cov
69%
BEGIN
3.2
__ANON__
1.1
__ANON__
1.1
CRAP 1.3
« Suffit/Cache.pm ↑ Summary Suffit.pm »
1 package WWW::Suffit::Const;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use feature ':5.16';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =encoding utf8
7  
8 =head1 NAME
9  
10 WWW::Suffit::Const - The Suffit constants
11  
12 =head1 SYNOPSIS
13  
14 use WWW::Suffit::Const;
15  
16 =head1 DESCRIPTION
17  
18 This module contains constants definitions
19  
20 =head2 TAGS
21  
22 =over 8
23  
24 =item B<:DIR>
25  
26 Exports FHS DIR constants
27  
28 See L<See https://www.pathname.com/fhs/pub/fhs-2.3.html>,
29 L<http://www.gnu.org/software/autoconf/manual/html_node/Installation-Directory-Variables.html>,
30 L<Sys::Path>
31  
32 =item B<:GENERAL>
33  
34 Exports common constants
35  
36 =item B<:SESSION>
37  
38 Exports session and token constants
39  
40 =item B<:SECURITY>
41  
42 Exports security and cryptography constants
43  
44 =item B<:MIME>
45  
46 Exports MIME constants
47  
48 =item B<:MISC>
49  
50 Exports miscellaneous constants
51  
52 =item B<:DICTS>
53  
54 Exports dictionaries
55  
56 =item B<:SERVER>
57  
58 Exports server constants
59  
60 =back
61  
62 =head1 HISTORY
63  
64 See C<Changes> file
65  
66 =head1 TO DO
67  
68 See C<TODO> file
69  
70 =head1 SEE ALSO
71  
72 L<WWW::Suffit>
73  
74 =head1 AUTHOR
75  
76 Serż Minus (Sergey Lepenkov) L<https://www.serzik.com> E<lt>abalama@cpan.orgE<gt>
77  
78 =head1 COPYRIGHT
79  
80 Copyright (C) 1998-2026 D&D Corporation
81  
82 =head1 LICENSE
83  
84 This program is distributed under the terms of the Artistic License Version 2.0
85  
86 See the C<LICENSE> file or L<https://opensource.org/license/artistic-2-0> for details
87  
88 =cut
89  
90 1 ▶use base qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
91  
92 1 ▶use Config qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 1 ▶use File::Spec qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
94  
95 1 ▶use constant {
Subroutine BEGIN: called CC=3 SCAR=11.7
96 1 ▶ DEFAULT_URL => 'http://localhost',
Branch: 2 branches
BranchTrueFalseTotal
-t STDOUT ? : 0 1 1
$> == 0 ? : 0 1 1
97  
98 # System constants
99 IS_TTY => (-t STDOUT) ? 1 : 0,
100 IS_ROOT => ($> == 0) ? 1 : 0,
101  
102 # Date and time formats (see strftime(3))
103 DATE_FORMAT => '%Y-%m-%d', # POSIX::strftime(DATE_FORMAT, localtime($t))
104 TIME_FORMAT => '%H:%M:%S', # POSIX::strftime(TIME_FORMAT, localtime($t))
105 DATETIME_FORMAT => '%Y-%m-%dT%H:%M:%S', # POSIX::strftime(DATETIME_FORMAT, localtime($t))
106 DATE_TIME_FORMAT => '%Y-%m-%d %H:%M:%S', # POSIX::strftime(DATE_TIME_FORMAT, localtime($t))
107  
108 # Session
109 SESSION_EXPIRATION => 3600, # 1 hour
110 SESSION_EXPIRE_MAX => 86400 * 30, # 30 days
111 TOKEN_HEADER_NAME => 'X-Token',
112 TOKEN_EXPIRATION => 86400, # 1 day (for session and access tokens only)
113 TOKEN_EXPIRE_MAX => 86400 * 30, # 30 days (for session and access tokens only)
114 TOKEN_FILE_FORMAT => 'token-%s.tkn',
115  
116 # Files
117 AUTHDBFILE => 'suffit-auth.db',
118  
119 # Security and Cryptography
120 DEFAULT_SECRET => 'Suffit!AP1$ecret%String_r.673-@w',
121 PRIVATEKEYFILE => 'rsa-private.key',
122 PUBLICKEYFILE => 'rsa-public.key',
123 DIGEST_ALGORITHMS => [qw/MD5 SHA1 SHA224 SHA256 SHA384 SHA512/],
124 DEFAULT_ALGORITHM => 'SHA256',
125  
126 # JWT/JTI
127 JWT_REGEXP => qr/^[A-Za-z0-9_-]{2,}(?:\.[A-Za-z0-9_-]{2,}){2}$/,
128 JTI_REGEXP => qr/[a-zA-Z0-9\-_]{8,64}/,
129  
130 # Misc
131 USERNAME_REGEXP => qr/(?![_.\-])(?!.*[_.\-]{2,})[a-zA-Z0-9_.\-]+(?<![_.\-])/,
132 EMAIL_REGEXP => qr/^[a-zA-Z0-9.!#$%&'*+\/\=?^_`{|}~\-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/,
133  
134 # MIME Content Types
135 CONTENT_TYPE_HTML => "text/html; charset=utf-8",
136 CONTENT_TYPE_TXT => "text/plain; charset=utf-8",
137 CONTENT_TYPE_JSON => "application/json",
138  
139 # Server
140 SERVER_UPGRADE_TIMEOUT => 30,
141 SERVER_TIMEOUT => 60,
142 SERVER_MAX_CLIENTS => 1000, # See Mojo::Server::Prefork
143 SERVER_MAX_REQUESTS => 100, # See Mojo::Server::Prefork
144 SERVER_MAX_MESSAGE_SIZE => 16*1024*1024, # '16MiB' See MOJO_MAX_MESSAGE_SIZE
145 SERVER_ACCEPTS => 0, # See Mojo::Server::Prefork
146 SERVER_SPARE => 2, # See Mojo::Server::Prefork
147 SERVER_WORKERS => 4, # See Mojo::Server::Prefork
148  
149 # Dictionaries
150 HTTP_METHODS => [qw/
151 CONNECT OPTIONS HEAD GET
152 POST PUT PATCH DELETE
153 TRACE
154 ANY MULTI
155 /],
156 AUTHZ_PROVIDERS => [qw[
157 Default
158 User/Group
159 Host
160 Env
161 Header
162 ]],
163 AUTHZ_ENTITIES => {
164 # Provider Entities
165 'Default' => [qw/Allow Deny/], # allowed granted denied
166 'User/Group' => [qw/User Group Valid-User/],
167 'Host' => [qw/Host IP/],
168 'Env' => [qw/LANG LOGNAME MOJO_MODE USER USERNAME USR1 USR2 USR3/],
169 'Header' => [qw/Accept Host User-Agent X-Token X-Auth X-OWL-Auth X-Usr1 X-Usr2 X-Usr3/],
170 },
171 AUTHZ_OPERATOTS => [
172 {name => 'eq', operator => '==', title => 'equal to'},
173 {name => 'ne', operator => '!=', title => 'not equal'},
174 {name => 'gt', operator => '>', title => 'greater than'},
175 {name => 'lt', operator => '<', title => 'less than'},
176 {name => 'ge', operator => '>=', title => 'greater than or equal to'},
177 {name => 'le', operator => '<=', title => 'less than or equal to'},
178 {name => 're', operator => '=~', title => 'regexp match'},
179 {name => 'rn', operator => '!~', title => 'regexp not match'},
180 ],
181  
182 1 };
183  
184 # Named groups of exports
185 1 our %EXPORT_TAGS = (
186 'GENERAL' => [qw/
187 IS_TTY IS_ROOT
188 DEFAULT_URL
189 DATE_FORMAT TIME_FORMAT DATETIME_FORMAT DATE_TIME_FORMAT
190 /],
191 'SESSION' => [qw/
192 SESSION_EXPIRATION SESSION_EXPIRE_MAX
193 TOKEN_HEADER_NAME TOKEN_EXPIRATION TOKEN_EXPIRE_MAX TOKEN_FILE_FORMAT
194 /],
195 'SECURITY' => [qw/
196 DEFAULT_SECRET
197 PRIVATEKEYFILE PUBLICKEYFILE DIGEST_ALGORITHMS DEFAULT_ALGORITHM
198 /],
199 'MIME' => [qw/
200 CONTENT_TYPE_HTML CONTENT_TYPE_TXT CONTENT_TYPE_JSON
201 /],
202 'MISC' => [qw/
203 USERNAME_REGEXP EMAIL_REGEXP
204 JWT_REGEXP JTI_REGEXP
205 /],
206 'DICTS' => [qw/
207 HTTP_METHODS
208 AUTHZ_PROVIDERS AUTHZ_ENTITIES AUTHZ_OPERATOTS
209 /],
210 'SERVER' => [qw/
211 SERVER_TIMEOUT SERVER_UPGRADE_TIMEOUT
212 SERVER_MAX_CLIENTS SERVER_MAX_REQUESTS
213 SERVER_MAX_MESSAGE_SIZE
214 SERVER_ACCEPTS SERVER_SPARE SERVER_WORKERS
215 /],
216 'DIR' => [qw/
217 PREFIX LOCALSTATEDIR SYSCONFDIR SRVDIR
218 BINDIR SBINDIR DATADIR DOCDIR LOCALEDIR MANDIR LOCALBINDIR
219 CACHEDIR LOGDIR SPOOLDIR RUNDIR LOCKDIR SHAREDSTATEDIR WEBDIR
220 /],
221 'FILE' => [qw/
222 AUTHDBFILE
223 /],
224 );
225  
226 # Items to export into callers namespace by default
227 # (move infrequently used names to @EXPORT_OK below)
228 our @EXPORT = (
229 1 @{$EXPORT_TAGS{GENERAL}},
230 );
231  
232 # Other items we are prepared to export if requested
233 our @EXPORT_OK = (
234 1 map {@{$_}} values %EXPORT_TAGS
235 );
236  
237 # Correct tags: makes lowercase tags as aliases of original uppercase tags
238 1 foreach my $k (keys %EXPORT_TAGS) {
239 9 ▶ next if exists $EXPORT_TAGS{(lc($k))};
Branch: 1 branch
BranchTrueFalseTotal
if exists $WWW::Suffit::Const::EXPORT_TAGS{lc $k} 0 9 9
240 9 ▶ $EXPORT_TAGS{(lc($k))} = $EXPORT_TAGS{$k} if $k =~ /^[A-Z_]+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^[A-Z_]+$/u 9 0 9
241 }
242  
243 #
244 # Filesystem Hierarchy Standard
245 #
246 # See http://www.gnu.org/software/autoconf/manual/html_node/Installation-Directory-Variables.html
247 # See https://www.pathname.com/fhs/pub/fhs-2.3.html
248 #
249 1 ▶my $prefix = $Config::Config{'prefix'} // '';
Condition50%1/2
$Config::Config{"prefix"} // ""
l!l
10
MC/DC0%0/1
$Config::Config{"prefix"} // ""
$Config::Config{"prefix"}
Truth table50%1/2
A
A= $Config::Config{"prefix"}
Aresult
11
00
250 1 ▶my $bindir = $Config::Config{'bin'} // File::Spec->catdir($prefix, 'bin');
Condition33%1/3
$Config::Config{"bin"} // "File::Spec"->catdir($prefix, "bin")
l!l&&r!l&&!r
100
MC/DC0%0/2
$Config::Config{"bin"} // "File::Spec"->catdir($prefix, "bin")
$Config::Config{"bin"} "File::Spec"->catdir($prefix, "bin")
Truth table33%1/3
A // B
A= $Config::Config{"bin"}B= "File::Spec"->catdir($prefix, "bin")
ABresult
1X1
011
000
251 1 ▶my $localstatedir = $prefix eq '/usr' ? '/var' : File::Spec->catdir($prefix, 'var');
Branch: 1 branch
BranchTrueFalseTotal
$prefix eq '/usr' ? : 0 1 1
252 1 ▶my $sysconfdir = $prefix eq '/usr' ? '/etc' : File::Spec->catdir($prefix, 'etc');
Branch: 1 branch
BranchTrueFalseTotal
$prefix eq '/usr' ? : 0 1 1
253 1 ▶my $srvdir = $prefix eq '/usr' ? '/srv' : File::Spec->catdir($prefix, 'srv');
Branch: 1 branch
BranchTrueFalseTotal
$prefix eq '/usr' ? : 0 1 1
254  
255 # Root dirs
256 0 ▶*PREFIX = sub { $prefix }; # prefix /usr
Subroutine __ANON__: not called CC=1 SCAR=1.2
257 0 ▶*LOCALSTATEDIR = sub { $localstatedir }; # localstatedir /var
Subroutine __ANON__: not called CC=1 SCAR=1.2
258 0 ▶*SYSCONFDIR = sub { $sysconfdir }; # sysconfdir /etc
Subroutine __ANON__: not called CC=1 SCAR=1.2
259 0 ▶*SRVDIR = sub { $srvdir }; # srvdir /srv
Subroutine __ANON__: not called CC=1 SCAR=1.2
260  
261 # Prefix related dirs
262 0 ▶*BINDIR = sub { $bindir }; # bindir /usr/bin
Subroutine __ANON__: not called CC=1 SCAR=1.2
263 0 ▶*SBINDIR = sub { state $sbindir = File::Spec->catdir($prefix, 'sbin') }; # sbindir /usr/sbin
Subroutine __ANON__: not called CC=1 SCAR=1.2
264 0 ▶*DATADIR = sub { state $datadir = File::Spec->catdir($prefix, 'share') }; # datadir /usr/share
Subroutine __ANON__: not called CC=1 SCAR=1.2
265 0 ▶*DOCDIR = sub { state $docdir = File::Spec->catdir($prefix, 'share', 'doc') }; # docdir /usr/share/doc
Subroutine __ANON__: not called CC=1 SCAR=1.2
266 0 ▶*LOCALEDIR = sub { state $localedir = File::Spec->catdir($prefix, 'share', 'locale') }; # localedir /usr/share/locale
Subroutine __ANON__: not called CC=1 SCAR=1.2
267 0 ▶*MANDIR = sub { state $mandir = File::Spec->catdir($prefix, 'share', 'man') }; # mandir /usr/share/man
Subroutine __ANON__: not called CC=1 SCAR=1.2
268 0 ▶*LOCALBINDIR = sub { state $localbindir = File::Spec->catdir($prefix, 'local', 'bin') };# localbindir /usr/local/bin
Subroutine __ANON__: not called CC=1 SCAR=1.2
269  
270 # Local State related Dirs
271 0 ▶*CACHEDIR = sub { state $cachedir = File::Spec->catdir($localstatedir, 'cache') }; # cachedir /var/cache
Subroutine __ANON__: not called CC=1 SCAR=1.2
272 0 ▶*LOGDIR = sub { state $logdir = File::Spec->catdir($localstatedir, 'log') }; # logdir /var/log
Subroutine __ANON__: not called CC=1 SCAR=1.2
273 0 ▶*SPOOLDIR = sub { state $spooldir = File::Spec->catdir($localstatedir, 'spool') }; # spooldir /var/spool
Subroutine __ANON__: not called CC=1 SCAR=1.2
274 0 ▶*RUNDIR = sub { state $rundir = File::Spec->catdir($localstatedir, 'run') }; # rundir /var/run
Subroutine __ANON__: not called CC=1 SCAR=1.2
275 0 ▶*LOCKDIR = sub { state $lockdir = File::Spec->catdir($localstatedir, 'lock') }; # lockdir /var/lock
Subroutine __ANON__: not called CC=1 SCAR=1.2
276 0 ▶*SHAREDSTATEDIR = sub { state $sharedstatedir = File::Spec->catdir($localstatedir, 'lib') }; # sharedstatedir /var/lib
Subroutine __ANON__: not called CC=1 SCAR=1.2
277 0 ▶*WEBDIR = sub { state $webdir = File::Spec->catdir($localstatedir, 'www') }; # webdir /var/www
Subroutine __ANON__: not called CC=1 SCAR=1.2
278  
279 1 1;
280  
281 __END__
« Suffit/Cache.pm ↑ Summary Suffit.pm »