# New Ticket Created by [email protected]
# Please include the string: [perl #126262]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=126262 >
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.)
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:) {
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.
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;
+}
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;
+}