Reactor/Utils.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 58 CC 6 SCAR 25.0
CC
6
Cov
0%
dir_path_check
20.0
dir_path_make
12.0
perl_package_to_file
2.0
CRAP 12.2
1 ##############################################################################
2 ##
3 ## Web::Reactor application machinery
4 ## Copyright (c) 2013-2022 Vladi Belperchinov-Shabanski "Cade"
5 ## <cade@noxrun.com> <cade@bis.bg> <cade@cpan.org>
6 ## http://cade.noxrun.com
7 ##
8 ## LICENSE: GPLv2
9 ## https://github.com/cade-vs/perl-web-reactor
10 ##
11 ##############################################################################
12 package Web::Reactor::Utils;
13 use strict;
14 use Exporter;
15  
16 our @ISA = qw( Exporter );
17  
18 our @EXPORT = qw(
19
20 perl_package_to_file
21  
22 dir_path_make
23 dir_path_check
24
25 );
26  
27 sub perl_package_to_file
28 {
29 my $s = shift;
30 $s =~ s/::/\//g;
31 $s .= '.pm';
32 return $s;
33 }
34  
35 ##############################################################################
36 #
37 #
38 #
39  
40 sub dir_path_make
41 {
42 my $path = shift;
43 my %opt = @_;
44  
45 my $mask = $opt{ 'MASK' } || oct('700');
46
47 my $abs;
48  
49 $path =~ s/\/+$/\//o;
50 $abs = '/' if $path =~ s/^\/+//o;
51  
52 my @path = split /\/+/, $path;
53  
54 $path = $abs;
55 for my $p ( @path )
56 {
57 $path .= "$p/";
58 next if -d $path;
59  
60 mkdir( $path, $mask ) or return 0;
61 }
62 return 1;
63 }
64  
65 sub dir_path_check
66 {
67 my $dir = shift;
68 my %opt = @_;
69  
70 dir_path_make( $dir, $opt{ 'MASK' } ) unless -d $dir;
71 if( ! -d $dir )
72 {
73 die "check_dir: cannot find dir $dir\n" if $opt{ 'FATAL' };
74 return undef;
75 }
76 return $dir;
77 }
78  
79  
80 ##############################################################################
81 1;
82 ###EOF########################################################################