App-Term-Jump
view release on metacpan or search on metacpan
# ---------------------------------------------------------------------------------------------------
sub create_temporary_directory
{
my ($temporary_directory_root, $template, $allowed_characters_in_directory_name) = @_ ;
$temporary_directory_increment++ ;
my $dir ;
my $number_of_allowed_characters = @{$allowed_characters_in_directory_name} ;
for (1 .. 500)
{
my $template_try = $template =~ s/./$allowed_characters_in_directory_name->[int(rand($number_of_allowed_characters))]/ger ;
my $path = $temporary_directory_root . '_' . $$ . '_' . $temporary_directory_increment . '_' . $template_try ;
if(File::Path::Tiny::mk($path))
{
$dir = $path ;
last ;
}
}
die "Could not create temporary directory '$temporary_directory_root': $!" unless defined $dir ;
return $dir ;
}
# ---------------------------------------------------------------------------------------------------
sub get_directories_and_db
{
my ($yaml) = @_ ;
my %db_paths ;
my $get_db_paths = sub
{
my ($structure, undef, $path) = @_ ;
if('HASH' eq ref $structure)
{
if(exists $structure->{in_db})
{
$path =~ s[\{'(.+?)'\}][$1/]g;
$path = 'TEMPORARY_DIRECTORY/' . $path ;
$path =~ s[/$][] ;
$db_paths{$path} = $structure->{in_db} ;
delete $structure->{in_db} ;
}
}
return(Data::TreeDumper::DefaultNodesToDisplay($structure)) ;
} ;
$yaml = "---\n$yaml\n" ;
my $directory_structure = Load($yaml) ;
DumpTree $directory_structure, 'munged', NO_OUTPUT => 1, FILTER => $get_db_paths ;
#diag "YAML\n$yaml\n";
#diag DumpTree $directory_structure, 'Directories' ;
#diag DumpTree \%db_paths, 'DB' ;
return ($directory_structure, \%db_paths) ;
}
# ---------------------------------------------------------------------------------------------------
1 ;
( run in 1.611 second using v1.01-cache-2.11-cpan-13bb782fe5a )