Skip Menu |
Report information
Id: 126262
Status: resolved
Priority: 0/
Queue: perl6

Owner: cpan [at] zoffix.com
Requestors: dean [at] serenevy.net
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: IO::Path.absolute(): String or IO::Path?
Download (untitled) / with headers
text/plain 477b
http://doc.perl6.org/type/IO::Path#method_absolute Says: method absolute (IO::Path:D: $base = ~$*CWD --> IO::Path:D) But IO::Path in Rakudo returns a string. S16 doesn't really commit to an answer, saying just "absolute the absolute, canonical path" Who is correct? Patches included to fix the perl6/doc or else fix the IO-Path module in rakudo/rakudo. Also attached trivial tests for each case for perl6/roast. (of course, only two of these patches should be applied.)
Subject: fix-IO-Path.patch
Download fix-IO-Path.patch
text/plain 837b
diff --git a/src/core/IO/Path.pm b/src/core/IO/Path.pm index 77ab53e..4214e5d 100644 --- a/src/core/IO/Path.pm +++ b/src/core/IO/Path.pm @@ -118,15 +118,17 @@ my class IO::Path is Cool { #?endif proto method absolute(|) { * } - multi method absolute (IO::Path:D:) { $.abspath } + multi method absolute (IO::Path:D:) { IO::Path.new($.abspath) } multi method absolute (IO::Path:D: $CWD) { - self.is-absolute - ?? $.abspath - !! $!SPEC.rel2abs($!path, $CWD); + IO::Path.new( + self.is-absolute + ?? $.abspath + !! $!SPEC.rel2abs($!path, $CWD); + ); } method relative (IO::Path:D: $CWD = $*CWD) { - $!SPEC.abs2rel($.abspath, $CWD); + IO::Path.new($!SPEC.abs2rel($.abspath, $CWD)); } method cleanup (IO::Path:D:) {
Subject: fix-pod.patch
Download fix-pod.patch
text/plain 691b
diff --git a/lib/Type/IO/Path.pod b/lib/Type/IO/Path.pod index 1403ab7..08d7ce5 100644 --- a/lib/Type/IO/Path.pod +++ b/lib/Type/IO/Path.pod @@ -131,13 +131,13 @@ Returns C<True> if the path is a relative path, and C<False> otherwise. =head2 method absolute - method absolute (IO::Path:D: $base = ~$*CWD --> IO::Path:D) + method absolute (IO::Path:D: $base = ~$*CWD --> Str:D) Returns a new C<IO::Path> object that is an absolute path, based on C<$base>. =head2 method relative - method relative (IO::Path:D: $base = ~$*CWD --> IO::Path:D) + method relative (IO::Path:D: $base = ~$*CWD --> Str:D) Returns a new C<IO::Path> object relative to the C<$base> path.
Subject: trivial-tests-as-IO-Path.patch
diff --git a/S16-io/absolute.t b/S16-io/absolute.t new file mode 100644 index 0000000..288ec82 --- /dev/null +++ b/S16-io/absolute.t @@ -0,0 +1,9 @@ +use v6; +use Test; + +plan 1; + +{ + my $dir = IO::Path.new("."); + isa-ok $dir.absolute, IO::Path; +} diff --git a/S16-io/relative.t b/S16-io/relative.t new file mode 100644 index 0000000..a861543 --- /dev/null +++ b/S16-io/relative.t @@ -0,0 +1,9 @@ +use v6; +use Test; + +plan 1; + +{ + my $dir = IO::Path.new("/tmp"); + isa-ok $dir.relative, IO::Path; +}
Subject: trivial-tests-as-Str.patch
diff --git a/S16-io/absolute.t b/S16-io/absolute.t new file mode 100644 index 0000000..288ec82 --- /dev/null +++ b/S16-io/absolute.t @@ -0,0 +1,9 @@ +use v6; +use Test; + +plan 1; + +{ + my $dir = IO::Path.new("."); + isa-ok $dir.absolute, Str; +} diff --git a/S16-io/relative.t b/S16-io/relative.t new file mode 100644 index 0000000..a861543 --- /dev/null +++ b/S16-io/relative.t @@ -0,0 +1,9 @@ +use v6; +use Test; + +plan 1; + +{ + my $dir = IO::Path.new("/tmp"); + isa-ok $dir.relative, Str; +}
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.2k
On Sun, 04 Oct 2015 12:57:26 -0700, duelafn wrote: Show quoted text
> http://doc.perl6.org/type/IO::Path#method_absolute > > Says: method absolute (IO::Path:D: $base = ~$*CWD --> IO::Path:D) > > But IO::Path in Rakudo returns a string. > > S16 doesn't really commit to an answer, saying just "absolute the > absolute, canonical path" > > Who is correct? > > Patches included to fix the perl6/doc or else fix the IO-Path module > in rakudo/rakudo. Also attached trivial tests for each case for > perl6/roast. (of course, only two of these patches should be applied.)
Thank you for the report. The `.absolute`/`.relative` methods are basically a way to fine-tune how to an `IO::Path` is stringified. Since relative `IO::Path`s are relative to their `$!CWD` attribute and not the current `$*CWD` there's no tangible difference between absolute and relative `IO::Path` objects, so returning an `IO::Path` object from these methods is pointless. Someone beat me to it to fix the `IO::Path`/`Str` on return types in the docs, but I've corrected[^1] some errors and expanded[^2] a bit on these two methods in the docs. [1] https://github.com/perl6/doc/commit/ccae74a1502285d8b82697b68a8e26a31ca762d7 [2] https://github.com/perl6/doc/commit/3cf943d86bef3744146e31e106815a00a2a81f4a -- IO grant


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org