NAME

Cwd::Ext - no symlink dereference

SYNOPSIS

Let's imagine that '/home/myself/stuff/music' is a soft link to '/home/myself/documents/music', and our current working directory is '/home/myself'..

use Cwd::Ext ':all';

abs_path_nd('./stuff/music'); # returns /home/myself/stuff/music

abs_path_is_in_nd( '/home/myself/stuff/music', '/home/myself/stuff' ); # returns true, /home/myself/stuff/music

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.

This module does not export by default. You must explicitely import what you want to use.

SUBS

abs_path_nd()

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

abs_path_is_in()

Arguments are child path in question, parent path to test against. Returns resolved abs path of child if yes, false if no.

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.

abs_path_matches_into()

Arg is child abs path, and parent abs path. Does not use Cwd to resolve anything, this just performs a substring match, returns boolean

Does an eval to check if this machine supports symlinks.

CAVEATS

This module is in ALPHA state. Needs feedback.

TODO

I want this to inherit Cwd. So that cwd(), etc are exported. Currently, you have to use Cwd and Cwd::Ext to access both these subs and Cwd subs.

SEE ALSO

Cwd

AUTHOR

Leo Charre leocharre at cpan dot org

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