Skip to content
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

Closed
p6rt opened this issue Oct 4, 2015 · 8 comments
Closed

IO::Path.absolute(): String or IO::Path? #4620

p6rt opened this issue Oct 4, 2015 · 8 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Oct 4, 2015

Migrated from rt.perl.org#126262 (status was 'resolved')

Searchable as RT126262$

@p6rt
Copy link
Author

p6rt commented Oct 4, 2015

From dean@cs.serenevy.net

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.)

@p6rt
Copy link
Author

p6rt commented Oct 4, 2015

From dean@cs.serenevy.net

fix-IO-Path.patch
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:) {

@p6rt
Copy link
Author

p6rt commented Oct 4, 2015

From dean@cs.serenevy.net

fix-pod.patch
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.
 

@p6rt
Copy link
Author

p6rt commented Oct 4, 2015

From dean@cs.serenevy.net

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;
+}

@p6rt
Copy link
Author

p6rt commented Oct 4, 2015

From dean@cs.serenevy.net

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;
+}

@p6rt
Copy link
Author

p6rt commented Mar 24, 2017

From @zoffixznet

On Sun, 04 Oct 2015 12​:57​:26 -0700, duelafn wrote​:

http://doc.perl6.org/type/IO&#8203;::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] Raku/doc@ccae74a
[2] Raku/doc@3cf943d

-- IO grant

@p6rt
Copy link
Author

p6rt commented Mar 24, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Mar 24, 2017

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Mar 24, 2017
@p6rt p6rt added the IO label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant