New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IO::Path.absolute(): String or IO::Path? #4620
Comments
From dean@cs.serenevy.nethttp://doc.perl6.org/type/IO​::Path#method_absolute Says: method absolute (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.) |
From dean@cs.serenevy.netfix-IO-Path.patchdiff --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:) {
|
From dean@cs.serenevy.netfix-pod.patchdiff --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.
|
From dean@cs.serenevy.nettrivial-tests-as-IO-Path.patchdiff --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;
+}
|
From dean@cs.serenevy.nettrivial-tests-as-Str.patchdiff --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;
+}
|
From @zoffixznetOn Sun, 04 Oct 2015 12:57:26 -0700, duelafn wrote:
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] Raku/doc@ccae74a -- IO grant |
The RT System itself - Status changed from 'new' to 'open' |
@zoffixznet - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#126262 (status was 'resolved')
Searchable as RT126262$
The text was updated successfully, but these errors were encountered: