Repository::Simple::Util - Utility methods shared by repository components
use Repository::Simple::Util qw( normalize_path dirname basename ); my $clean_path = normalize_path("/usr", "../messy/../.././///messy/path"); my $dirname = dirname("/foo/bar/baz"); # returns "/foo/bar" my $basename = basename("/foo/bar/baz"); # returns "baz"
The methods here are for use by the content repository and content repository engines internally. Unless you are extending the repository system, you will probably want to avoid the use of these methods.
This method creates a "normal" path out of the given "messy" path, $messy_path. In case the $messy_path is relative, the $current_path gives the absolute path we're working from.
$messy_path
$current_path
It provides the following:
If the messy path is relative, this method merges the messy path and the current path to create an absolute path.
All superfluous "." and ".." elements will be stripped from the path so that the resulting path will be the most concise and direct name for the named file.
Enforces the principle that ".." applied to the root returns the root. This provides security by preventing users from getting to a file outside of the root.
Given a normalized path, this returns the path with the last element stripped. That is, it returns the parent of the given path. If the root path ("/") is given, then the same path is returned.
Given a normalized path, this method returns the last path element of the path. That is, it returns the last name in the path. If the root path ("/") is given, then the same is returned.
Andrew Sterling Hanenkamp, <hanenkamp@cpan.org>
Copyright 2005 Andrew Sterling Hanenkamp <hanenkamp@cpan.org>. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
To install Repository::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Repository::Simple
CPAN shell
perl -MCPAN -e shell install Repository::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.