Skip to content

Commit bd426da

Browse files
authored
Move IO::Path stringification into own I/O section
1 parent de19b02 commit bd426da

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

doc/Language/traps.pod6

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -265,34 +265,6 @@ There are methods that Str inherits from Any that work on iterables like lists.
265265
say "cba".sort; # OUTPUT: «(cba)␤» (what is wrong)
266266
say "cba".comb.sort.join; # OUTPUT: «abc␤»
267267
268-
=head2 IO::Path Stringification
269-
270-
Partly for historical reasons and partly by design, an L<IO::Path> object
271-
L<stringifies|/type/IO::Path#method_Str> without considering its
272-
L«C<CWD> attribute|/type/IO::Path#attribute_CWD», which means if you L<chdir>
273-
and then stringify an L<IO::Path>, the resultant string won't reference
274-
the original filesystem object:
275-
276-
=begin code
277-
with 'foo'.IO {
278-
.Str.say; # OUTPUT: «foo␤»
279-
.relative.say; # OUTPUT: «foo␤»
280-
281-
chdir "/tmp";
282-
.Str.say; # OUTPUT: «foo␤»
283-
.relative.say # OUTPUT: «../home/camelia/foo␤»
284-
}
285-
=end code
286-
287-
The easy way to avoid this issue is to not stringify an L<IO::Path> object at all.
288-
Core routines that work with paths can take an L<IO::Path> object, so you don't
289-
need to stringify the paths.
290-
291-
If you do have a case where you need a stringified version of an L<IO::Path>, use
292-
L<absolute> or L<relative> methods to stringify it into an absolute or relative
293-
path, respectively.
294-
295-
296268
=head1 Operators
297269
298270
Some operators commonly shared among other languages were repurposed in Perl 6 for other, more common, things:
@@ -509,6 +481,35 @@ The nice thing about the distinction here is that it gives the developer the
509481
option of passing pairs as either named or positional arguments, which can be
510482
handy in various instances.
511483
484+
=head1 Input and Output
485+
486+
=head2 IO::Path Stringification
487+
488+
Partly for historical reasons and partly by design, an L<IO::Path> object
489+
L<stringifies|/type/IO::Path#method_Str> without considering its
490+
L«C<CWD> attribute|/type/IO::Path#attribute_CWD», which means if you L<chdir>
491+
and then stringify an L<IO::Path>, the resultant string won't reference
492+
the original filesystem object:
493+
494+
=begin code
495+
with 'foo'.IO {
496+
.Str.say; # OUTPUT: «foo␤»
497+
.relative.say; # OUTPUT: «foo␤»
498+
499+
chdir "/tmp";
500+
.Str.say; # OUTPUT: «foo␤»
501+
.relative.say # OUTPUT: «../home/camelia/foo␤»
502+
}
503+
=end code
504+
505+
The easy way to avoid this issue is to not stringify an L<IO::Path> object at all.
506+
Core routines that work with paths can take an L<IO::Path> object, so you don't
507+
need to stringify the paths.
508+
509+
If you do have a case where you need a stringified version of an L<IO::Path>, use
510+
L<absolute> or L<relative> methods to stringify it into an absolute or relative
511+
path, respectively.
512+
512513
=head1 Exception Handling
513514
514515
=head2 Sunk C<Proc>

0 commit comments

Comments
 (0)