dagolden / Path-Tiny

File path utility
41 stars 59 forks source link

->absolute adds three extra elements to the object? #233

Closed karenetheridge closed 4 years ago

karenetheridge commented 4 years ago

Is it intentional that ->absolute on already-absolute path should add additional elements to the blessed arrayref?

use strict;
use warnings;
use Path::Tiny;
use Cwd 'getcwd';
use Data::Dumper;

my $path = path(getcwd(), 'x', 'y');
print STDERR "### got path ", Dumper($path);

my $newpath = path($path)->absolute('.');
print STDERR "### got new abs path ", Dumper($newpath);

prints:

### blessed into $VAR1 = [
          '/Volumes/amaretto/Users/ether/x/y',
          '/Volumes/amaretto/Users/ether/x/y'
        ];
### got path $VAR1 = bless( [
                 '/Volumes/amaretto/Users/ether/x/y',
                 '/Volumes/amaretto/Users/ether/x/y'
               ], 'Path::Tiny' );
### got new abs path $VAR1 = bless( [
                 '/Volumes/amaretto/Users/ether/x/y',
                 '/Volumes/amaretto/Users/ether/x/y',
                 '',
                 '/Volumes/amaretto/Users/ether/x/',
                 'y'
               ], 'Path::Tiny' );
karenetheridge commented 4 years ago

never mind, it looks like this is by design. I drilled it down to splitpath, called via dirname called via is_absolute.

xdg commented 4 years ago

Glad you figured it out. Caching File::Spec output to avoid repeated calls is a very intentional part of the design. :-)