Cwd::Ext - extended file path subroutines



NAME

Cwd::Ext - extended file path subroutines


DESCRIPTION

These are some things that feel missing from Cwd.

Questions like, Is a file inside the hierarchy of another? What is the resolved absolute path of a file, without dereferencing symlinks?

Unlike with Cwd, this module is in baby stage. So it is NOT tweaked for OS2, NT, etc etc. This is developed under POSIX.

Nothing is imported by default. You must explicitely import..


SYNOPSIS

   use Cwd::Ext qw(abs_path_is_in_nd abs_path_is_in abs_path_nd);

abs_path_nd()

Works just like Cwd::abs_path , only it does (n)o (s)ymlink (d)ereference.

abs_path_is_in()

Arguments are child path in question, parent path to test against. Returns boolean. Will confess if missing arguments. If either path can't be resolved, warns and returns undef.

Is /home/myself/file1.jpg inside the filesystem hierarchy of /home/myself ?

   my $child  = '/home/myself/file1.jpg';
   my $parent = '/home/myself';
   printf "Does [$child] reside in [$parent]? %s\n",
      
      ( Cwd::Ext::abs_path_is_in($child,$parent) ? 'yes' : 'no' );

If both paths resolve to same place, returns 1 and warns. (Should this be different?)

abs_path_is_in_nd()

Same as abs_path_is_within() but does not resolve symlinks. If either path can't be resolved, warns and returns undef.


CAVEATS

This module is in ALPHA state. Needs feedback.


TODO

I want this to inherit Cwd. So that cwd(), etc are exported.


AUTHOR

Leo Charre leocharre at cpan dot org

Thanks to http://perlmonks.org/?node_id=401112 johngg for resolving paths without resolving symlinks.