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