From fe5fb68a82036dfafdb515295020dd29ddf84f3d Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 13 Aug 2007 15:26:50 +0000 Subject: symlink resolver, per aiutare la cache dei template git-svn-id: svn://luxion/repos/WebCoso/trunk@272 fcb26f47-9200-0410-b104-b98ab5b095f3 --- lib/Path/ResolveSymlinks.pm | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/Path/ResolveSymlinks.pm (limited to 'lib') diff --git a/lib/Path/ResolveSymlinks.pm b/lib/Path/ResolveSymlinks.pm new file mode 100644 index 0000000..695122a --- /dev/null +++ b/lib/Path/ResolveSymlinks.pm @@ -0,0 +1,39 @@ +package Path::ResolveSymlinks; +use strict; +use warnings; +use Cwd 'abs_path'; +use Path::Class; +use Carp; + +sub resolve_symlinks { + my ($name)=@_; + + my ($dir,$file); + if (-d $name) { + $dir=dir($name); + } + elsif (-f $name) { + $file=file($name); + $dir=$file->parent; + $file=$file->basename; + } + else { + croak "$name is neither a file nor a directory"; + } + + $dir=dir(abs_path($dir));warn "dir: $dir\n"; + return $dir unless defined $file; + + $file=$dir->file($file);warn "file: $file\n"; + return $file unless -l $file; + + my $dest=file(readlink $file);warn "dest: $dest\n"; + if ($dest->is_absolute) { + return resolve_symlinks($dest); + } + else { + return resolve_symlinks($dir->file($dest)); + } +} + +1; -- cgit v1.2.3