Package My::Page; use File::Basename; #... sub _create_path { my $self = shift; my (undef, $directories, undef) = fileparse( $self->url, '\.\w+' ); my $path = $self->config->get('base_path'); chdir $path; for (split('/', $directories)) { next unless $_; $path .= "/$_"; if (-e && ! -d) { $self->log_error("$path already exists and is not a directory."); return; } if (-l) { $self->log_error("$path already exists and is a symlink."); return; } unless (-e && -d || mkdir $path) { $self->log_error("failed to mkdir $path: $!"); return; } unless (chdir $path) { $self->log_error("failed to chdir to $path: $!"); return; } } return 1; }