@@ -132,6 +132,38 @@ C<IO::Path>.
132
132
"foo/bar".IO.concat-with("../meow") .resolve.relative.say; # OUTPUT: «foo/meow»
133
133
"foo/bar".IO.concat-with("../../") .resolve.relative.say; # OUTPUT: «.»
134
134
135
+ = head2 method child
136
+
137
+ method child(IO::Path:D: Str() $childname --> IO::Path:D)
138
+
139
+ Alias for L « C < .concat-with > |/routine/concat-with» . See also
140
+ L « C < .child-secure > |/routine/child-secure»
141
+
142
+ = head2 method child-secure
143
+
144
+ method child-secure(IO::Path:D: Str() $childname --> IO::Path:D)
145
+
146
+ Same as L « C < .child > |/routine/child» , except it will
147
+ B « fully L < resolve|/routine/resolve > » the resultant path and check that it is in
148
+ fact a child of the invocant. On success, returns the resultant path;
149
+ L « fails|/routine/fail » with C < X::IO::Resolve > if the path could not be
150
+ completely resolved or with C < X::IO::NotAChild > if the resultant path is not
151
+ a child of the invocant.
152
+
153
+ B < Note: > since the path has to be fully resolved, the method can still fail
154
+ with C < X::IO::Resolve > even for paths that would be child paths, if some of
155
+ the directories do not exist yet. The last part of the path does not have to
156
+ exist for the routine to succeed.
157
+
158
+ = for code :skip-test
159
+ my $parent = 'foo'.IO.mkdir;
160
+ say $parent.child-secure: 'bar'; # OUTPUT: «"foo/bar".IO»
161
+ say $parent.child-secure: '../bar'; # Fails with X::IO::NotAChild
162
+ say $parent.child-secure: 'bar/ber'; # Fails with X::IO::Resolve
163
+
164
+ $parent.child('bar').mkdir; # create 'bar' so the call below succeeds
165
+ say $parent.child-secure: 'bar/ber'; # OUTPUT: «"foo/bar/ber".IO»
166
+
135
167
= head2 method extension
136
168
137
169
Defined as:
@@ -300,16 +332,6 @@ Removes the last portion of the path and returns the result as a new C<IO::Path>
300
332
my $io = IO::Path.new( "/etc/passwd" );
301
333
say $io.parent; # OUTPUT: «"/etc".IO»
302
334
303
- = head2 method child
304
-
305
- method child(IO::Path:D: $childname --> IO::Path)
306
-
307
- Appends C < $childname > to the end of the path, adding path separators where
308
- needed and returns the result as a new C < IO::Path > .
309
-
310
- my $io = IO::Path.new( "/bin" );
311
- say $io.child('netstat'); # OUTPUT: «"/bin/netstat".IO»
312
-
313
335
= head2 method resolve
314
336
315
337
method resolve(IO::Path:D: :$completely --> IO::Path)
0 commit comments