general.pm

filter: Statementstmt 24.6% 32 / 130 Branchbran 2.2% 1 / 44 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 38.8% 7 / 18 Podpod 50.0% 6 / 12 totaltotal 22.0% 46 / 209 CC 24 SCAR 30.4
CC
24
Cov
19%
time_event_mysql
72.0
delimiter_dir
20.0
os_server_info
12.0
CRAP 20.9
↑ Summary general/file/read.pm »
1 package NKTI::general;
2
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 1 require Exporter;
9
10 1 our @ISA = qw(Exporter);
11
12 # Items to export into callers namespace by default. Note: do not export.
13 # names by default without a very good reason. Use EXPORT_OK instead.
14 # Do not simply export all your public functions/methods/constants.
15
16 # This allows declaration use NKTI::general ':all';
17 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
18 # will save memory.
19 1 our %EXPORT_TAGS = ( 'all' => [ qw( cetak cetak_r cetak_pre ) ]);
20 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
21 1 our @EXPORT = qw(cetak cetak_r cetak_pre);
22
23 # ABSTRACT: [DEPRECATED] The Part of CellBIS The Simple Web Framework
24 1 our $VERSION = '0.17';
25
26 # Create Subroutine for Get OS Server Information :
27 # ------------------------------------------------------------------------
28 0 ▶sub os_server_info {
Subroutine os_server_info: not called CC=3 SCAR=24.8
Pod undocumented
29 # ----------------------------------------------------------------
30 # Prepare to get Operating System Information :
31 # ----------------------------------------------------------------
32 0 my $server_signature = lc $ENV{'SERVER_SIGNATURE'};
33 # ----------------------------------------------------------------
34 # Scalar for placing result :
35 # ----------------------------------------------------------------
36 0 my $data = undef;
37
38 # Check IF $server_signature match "Win32" :
39
40 0 ▶ if ($server_signature =~ m/win32/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($server_signature =~ /win32/) { } 0 0 0
elsif ($server_signature =~ /unix|debian|ubuntu|centos/) { } 0 0 0
41 0 $data = 'mswin';
42 }
43
44 # Check IF $server_signature match "unix" :
45
46 elsif ($server_signature =~ m/unix|debian|ubuntu|centos/) {
47 0 $data = 'unix';
48 }
49
50 # Check IF $server_signature match unknown :
51
52 else {
53 0 $data = 'other';
54 }
55
56 # Return Result :
57 # ----------------------------------------------------------------
58 0 return $data;
59 }
60 # End of Create Subroutine for Get OS Server Information
61 # ===========================================================================================================
62
63 # Create Subroutine for get OS Client Information :
64 # ------------------------------------------------------------------------
65 0 ▶sub os_info {
Subroutine os_info: not called CC=3 SCAR=20.8
Pod undocumented
66
67 # Define self :
68 # ----------------------------------------------------------------
69 0 my $self = shift;
70
71 # Using Modules :
72 # ----------------------------------------------------------------
73 0 my $check_modules = $self->try_module('HTTP::BrowserDetect');
74 0 ▶ unless ($check_modules) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($check_modules) 0 0 0
75 1 ▶ use HTTP::BrowserDetect;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 }
77
78 # Prepare to get OS Client Information :
79 # ----------------------------------------------------------------
80 0 my $user_agent = $ENV{'HTTP_USER_AGENT'};
81 0 my $ua = HTTP::BrowserDetect->new($user_agent);
82
83 # Scalar for placing result :
84 # ----------------------------------------------------------------
85 0 my $data = '';
86
87 # Check IF $ua->os_string is true :
88 # ----------------------------------------------------------------
89 0 ▶ if ($ua->os_string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ua->os_string) { } 0 0 0
90 0 $data .= lc $ua->os_string;
91 }
92 # End of check IF $ua->os_string is true.
93 # =================================================================
94
95 # Check IF $ua->os_string is false :
96 # ----------------------------------------------------------------
97 else {
98 0 $data .= 'unknown';
99 }
100 # End of check IF $ua->os_string is false.
101 # =================================================================
102
103 # Return Result :
104 # ----------------------------------------------------------------
105 0 return $data;
106 }
107 # End of Create Subroutine for get OS Client Information
108 # ===========================================================================================================
109
110 # Create Subroutine for Get Browser Information :
111 # ------------------------------------------------------------------------
112 1 ▶sub browser_info {
Subroutine browser_info: called CC=2 SCAR=7.1
Pod undocumented
113
114 # Prepare to get Browser Information :
115 # ----------------------------------------------------------------
116 1 my $browser = $ENV{'HTTP_USER_AGENT'};
117 1 my $ua = HTTP::BrowserDetect->new($browser);
118
119 # Scalar for placing result :
120 # ----------------------------------------------------------------
121 1 my $data = '';
122
123 # Check IF $ua->browser_string is true :
124 # ----------------------------------------------------------------
125 1 ▶ if ($ua->browser_string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ua->browser_string) { } 0 1 1
126 0 $data .= lc $ua->browser_string;
127 }
128 # End of check IF $ua->browser_string is true.
129 # =================================================================
130
131 # Check IF $ua->browser_string is false :
132 # ----------------------------------------------------------------
133 else {
134 1 $data .= 'unknown';
135 }
136 # End of check IF $ua->browser_string is false.
137 # =================================================================
138
139 # Return Data :
140 # ----------------------------------------------------------------
141 1 return $data;
142 }
143 # End of Create Subroutine for Get Browser Information
144 # ===========================================================================================================
145
146 # Create Subroutine for Delimiter Directory :
147 # ------------------------------------------------------------------------
148 0 ▶sub delimiter_dir {
Subroutine delimiter_dir: not called CC=4 SCAR=30.0
Pod undocumented
149
150 # Run Subroutine "os_server_info()" :
151 # ----------------------------------------------------------------
152 0 my $self = shift;
153 0 my $os_information = $self->os_server_info();
154
155 # Scalar for placing result :
156 # ----------------------------------------------------------------
157 0 my $data = '';
158
159 # Switch for conditions $os_information :
160 # ----------------------------------------------------------------
161 0 ▶ if ($os_information == 'mswin') {
Branch: 3 branches
BranchTrueFalseTotal
if ($os_information == 'mswin') { } 0 0 0
elsif ($os_information == 'unix') { } 0 0 0
elsif ($os_information == 'other') { } 0 0 0
162 0 $data = '\\';
163 } elsif ($os_information == 'unix') {
164 0 $data = '/';
165 } elsif ($os_information == 'other') {
166 0 $data = '/';
167 } else {
168 0 $data = '/';
169 }
170 # End of switch for conditions $os_information.
171 # ================================================================
172
173 # Return Result :
174 # ----------------------------------------------------------------
175 0 return $data;
176 }
177 # End of Create Subroutine for Delimiter Directory
178 # ===========================================================================================================
179
180 # Create Subroutine for get database config :
181 # ------------------------------------------------------------------------
182 0 ▶sub get_dbconfig_php {
Subroutine get_dbconfig_php: not called CC=2 SCAR=12.6
Pod documented
183
184 # Define arguments subroutine :
185 # ----------------------------------------------------------------
186 0 my ($self, $dirloc, $file_loc) = @_;
187
188 # Using Modules :
189 # ----------------------------------------------------------------
190 0 my $check_modules = $self->try_module('NKTI::general::file::read');
191 0 ▶ unless ($check_modules) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($check_modules) 0 0 0
192 1 ▶ use NKTI::general::file::read;
Subroutine BEGIN: called CC=1 SCAR=0.0
193 }
194
195 # Define scalar for location file Database Config :
196 # ----------------------------------------------------------------
197 0 my $file_dbconfig = $dirloc . $file_loc;
198
199 # Run subroutine for get database config :
200 # ----------------------------------------------------------------
201 0 my $get_dbconfig = NKTI::general::file::read->new($file_dbconfig, 'dbconf');
202
203 # Return Result :
204 # ----------------------------------------------------------------
205 0 return $get_dbconfig;
206 }
207 # End of Create Subroutine for get database config
208 # ===========================================================================================================
209
210 # Subroutine for get protocols :
211 # ------------------------------------------------------------------------
212 0 ▶sub get_protocol {
Subroutine get_protocol: not called CC=3 SCAR=24.8
Pod documented
213
214 # Prepare to get Protocol used :
215 # ----------------------------------------------------------------
216 #my $get_protocol = (defined $ENV{'HTTPS'} || $ENV{'SERVER_PORT'} == '443') ? "https:" : "http:";
217 0 my $get_protocol = undef;
218 0 ▶ if (defined $ENV{'HTTPS'} || $ENV{'SERVER_PORT'} == '443') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{'HTTPS'} or $ENV{'SERVER_PORT'} == '443') { } 0 0 0
Condition0%0/3
defined $ENV{"HTTPS"} or $ENV{"SERVER_PORT"} == 443
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $ENV{"HTTPS"} or $ENV{"SERVER_PORT"} == 443
defined $ENV{"HTTPS"} $ENV{"SERVER_PORT"} == 443
Truth table0%0/3
A or B
A= defined $ENV{"HTTPS"}B= $ENV{"SERVER_PORT"} == 443
ABresult
1X1
011
000
219 0 $get_protocol = 'https:';
220 } else {
221 0 $get_protocol = 'http:';
222 }
223
224 # Return Result :
225 # ----------------------------------------------------------------
226 0 return $get_protocol;
227 }
228 # End of Subroutine for get protocols.
229 # ===========================================================================================================
230
231 # Subroutine for check IF module is exists :
232 # ------------------------------------------------------------------------
233 0 ▶sub try_module {
Subroutine try_module: not called CC=2 SCAR=17.9
Pod undocumented
234
235 # Define parameter module :
236 # ----------------------------------------------------------------
237 0 my ($self, $module_name) = @_;
238
239 0 eval("use $module_name");
240
241 # Check IF eval is true :
242 # Jika module belum diload.
243 # ----------------------------------------------------------------
244 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
245 #print "\$@ = $@\n";
246 0 return(0);
247 }
248
249 # Check IF eval is false :
250 # Jika module Telah diload.
251 # ----------------------------------------------------------------
252 else {
253 0 return(1);
254 }
255 }
256 # End of Subroutine for check IF module is exists
257 # ===========================================================================================================
258
259 # Subroutine for define time for Event MySQL :
260 # ------------------------------------------------------------------------
261 0 ▶sub time_event_mysql {
Subroutine time_event_mysql: not called CC=8 SCAR=42.8
Pod documented
262 # ----------------------------------------------------------------
263 # Define parameter Subroutine :
264 # ----------------------------------------------------------------
265 0 my ($self, $time_event) = @_;
266 # ----------------------------------------------------------------
267 # Define scalar for place result :
268 # ----------------------------------------------------------------
269 0 my %data = ();
270 0 my $get_num = undef;
271
272 # For $time_event =~ /Y/ :
273 # --------------------------------------------------------------------
274 0 ▶ if ($time_event =~ m/Y/) {
Branch: 7 branches
BranchTrueFalseTotal
if ($time_event =~ /Y/) { } 0 0 0
elsif ($time_event =~ /M/) { } 0 0 0
elsif ($time_event =~ /W/) { } 0 0 0
elsif ($time_event =~ /D/) { } 0 0 0
elsif ($time_event =~ /H/) { } 0 0 0
elsif ($time_event =~ /m/) { } 0 0 0
elsif ($time_event =~ /d/) { } 0 0 0
275 0 $get_num = $time_event =~ s/\D//g;
276 0 $data{'event'} = '(CURRENT_TIMESTAMP + INTERVAL '.$get_num.' YEAR)';
277 0 $data{'time'} = $time_event;
278 0 $data{'unit'} = 'YEAR';
279 }
280 # End of For $time_event =~ /Y/.
281 # ====================================================================
282
283 # For $time_event =~ /M/ :
284 # --------------------------------------------------------------------
285 elsif ($time_event =~ m/M/) {
286 0 $get_num = $time_event =~ s/\D//g;
287 0 $data{'event'} = '(CURRENT_TIMESTAMP + INTERVAL '.$get_num.' MONTH)';
288 0 $data{'time'} = $time_event;
289 0 $data{'unit'} = 'MONTH';
290 }
291 # End of for $time_event =~ /M/.
292 # ====================================================================
293
294 # For $time_event =~ /W/ :
295 # --------------------------------------------------------------------
296 elsif ($time_event =~ m/W/) {
297 0 $get_num = $time_event =~ s/\D//g;
298 0 $data{'event'} = '(CURRENT_TIMESTAMP + INTERVAL '.$get_num.' WEEK)';
299 0 $data{'time'} = $time_event;
300 0 $data{'unit'} = 'WEEK';
301 }
302 # End of for $time_event =~ /W/.
303 # ====================================================================
304
305 # For $time_event =~ /D/ :
306 # --------------------------------------------------------------------
307 elsif ($time_event =~ m/D/) {
308 0 $get_num = $time_event =~ s/\D//g;
309 0 $data{'event'} = '(CURRENT_TIMESTAMP + INTERVAL '.$get_num.' DAY)';
310 0 $data{'time'} = $time_event;
311 0 $data{'unit'} = 'DAY';
312 }
313 # End of For $time_event =~ /D/.
314 # ====================================================================
315
316 # For $time_event =~ /H/ :
317 # --------------------------------------------------------------------
318 elsif ($time_event =~ m/H/) {
319 0 $get_num = $time_event =~ s/\D//g;
320 0 $data{'event'} = '(CURRENT_TIMESTAMP + INTERVAL '.$get_num.' HOUR)';
321 0 $data{'time'} = $time_event;
322 0 $data{'unit'} = 'HOUR';
323 }
324 # End of For $time_event =~ /H/.
325 # ====================================================================
326
327 # For $time_event =~ /m/ :
328 # --------------------------------------------------------------------
329 elsif ($time_event =~ m/m/) {
330 0 $get_num = $time_event =~ s/\D//g;
331 0 $data{'event'} = '(CURRENT_TIMESTAMP + INTERVAL '.$get_num.' MINUTE)';
332 0 $data{'time'} = $time_event;
333 0 $data{'unit'} = 'MINUTE';
334 }
335 # End of For $time_event =~ /m/.
336 # ====================================================================
337
338 # For $time_event =~ /d/ :
339 # --------------------------------------------------------------------
340 elsif ($time_event =~ m/d/) {
341 0 $get_num = $time_event =~ s/\D//g;
342 0 $data{'event'} = '(CURRENT_TIMESTAMP + INTERVAL '.$get_num.' SECOND)';
343 0 $data{'time'} = $time_event;
344 0 $data{'unit'} = 'SECOND';
345 }
346 # End of For $time_event =~ /d/.
347 # ====================================================================
348
349 # Default Case :
350 # --------------------------------------------------------------------
351 else {
352 0 $data{'event'} = 'CURRENT_TIMESTAMP';
353 0 $data{'time'} = '';
354 0 $data{'unit'} = '';
355 }
356 # End of case $time_event == /d/.
357 # ====================================================================
358
359 # Return Result :
360 # ----------------------------------------------------------------
361 0 return \%data;
362 }
363 # End of Subroutine for define time for Event MySQL
364 # ===========================================================================================================
365
366 # Subroutine for Define format DATETIME MySQL :
367 # ------------------------------------------------------------------------
368 0 ▶sub datetime_mysql {
Subroutine datetime_mysql: not called CC=1 SCAR=6.9
Pod undocumented
369 # ----------------------------------------------------------------
370 # Define parameter subroutine :
371 # ----------------------------------------------------------------
372 0 my ($self, $timestamp, $timezone) = @_;
373 # ----------------------------------------------------------------
374 # Define scalar for place result :
375 # ----------------------------------------------------------------
376 0 my $data = undef;
377 # ----------------------------------------------------------------
378 # Set DateTime and TimeZone :
379 # ----------------------------------------------------------------
380 0 my $dt = DateTime->from_epoch(
381 epoch => $timestamp,
382 time_zone => $timezone
383 );
384 # ----------------------------------------------------------------
385 # Get DateTime Format :
386 # ----------------------------------------------------------------
387 0 my $date_define = $dt->ymd;
388 0 my $time_define = $dt->hms;
389 # ----------------------------------------------------------------
390 # Place date reuslt :
391 # ----------------------------------------------------------------
392 0 $data = $date_define.' '.$time_define;
393 # ----------------------------------------------------------------
394 # Return result :
395 # ----------------------------------------------------------------
396 0 return $data;
397 }
398 # End of Subroutine for Define format DATETIME MySQL
399 # ===========================================================================================================
400
401 # Subroutine for Print data with newline :
402 # ------------------------------------------------------------------------
403 0 ▶sub cetak {
Subroutine cetak: not called CC=1 SCAR=6.9
Pod documented
404 # ----------------------------------------------------------------
405 # Define parameter subroutine :
406 # ----------------------------------------------------------------
407 0 my ($data) = @_;
408 # ----------------------------------------------------------------
409 # Print Data :
410 # ----------------------------------------------------------------
411 0 print "$data \n";
412 }
413 # End of Subroutine for Print data with newline
414 # ===========================================================================================================
415
416 # Subroutine for Print ref :
417 # ------------------------------------------------------------------------
418 0 ▶sub cetak_r {
Subroutine cetak_r: not called CC=3 SCAR=24.8
Pod documented
419 # ----------------------------------------------------------------
420 # Check Parameter Subroutine :
421 # ----------------------------------------------------------------
422 0 ▶ if (keys(@_) eq 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys @_ eq 1) 0 0 0
423 # ----------------------------------------------------------------
424 # Print Dumper :
425 # ----------------------------------------------------------------
426 0 print Dumper $_[0];
427 }
428 0 ▶ if (keys(@_) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys @_ > 1) 0 0 0
429 # ----------------------------------------------------------------
430 # Print Dumper :
431 # ----------------------------------------------------------------
432 0 print Dumper \@_;
433 }
434 }
435 # End of Subroutine for Print ref.
436 # ===========================================================================================================
437
438 # Subroutine for print ref with pre tag HTML :
439 # ------------------------------------------------------------------------
440 0 ▶sub cetak_pre {
Subroutine cetak_pre: not called CC=3 SCAR=24.8
Pod documented
441 # ----------------------------------------------------------------
442 # Check Parameter Subroutine :
443 # ----------------------------------------------------------------
444 0 ▶ if (keys(@_) eq 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys @_ eq 1) 0 0 0
445 # ----------------------------------------------------------------
446 # Print Dumper :
447 # ----------------------------------------------------------------
448 0 print "<pre>";
449 0 print Dumper $_[0];
450 0 print "</pre>";
451 }
452 0 ▶ if (keys(@_) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys @_ > 1) 0 0 0
453 # ----------------------------------------------------------------
454 # Print Dumper :
455 # ----------------------------------------------------------------
456 0 print Dumper \@_;
457 }
458 }
459 # End of Subroutine for print ref with pre tag HTML
460 # ===========================================================================================================
461 1 1;
462 __END__
↑ Summary general/file/read.pm »