@@ -268,41 +268,46 @@ An overview:
268
268
269
269
=head3 IO::Locally role
270
270
271
- The official way to create an C<IO::Path> object is with the C<new> method.
272
- Apart from the C<path> positional, it also takes optional C<:SPEC> and
273
- C<CWD> named parameters. The C<.IO> coercer (which takes the same parameters
274
- as C<.new>) is the syntactic sugar that will most likely be used most often .
271
+ The best way to create an object that does the C<IO::Locally> role, is to use
272
+ the C<.IO> coercer. It takes an optional C<:CWD> parameter to indicate what
273
+ the current directory is supposed to be (for relative paths, defaults to
274
+ C<$*CWD>) .
275
275
276
- my $io = $filename.IO; # current $*SPEC/$*CWD
277
- my $io = $filename.IO(:SPEC(*$SPEC)); # specific IO::SPEC
278
- my $io = $filename.IO(:SPEC(*$SPEC), :CWD($*CWD));
276
+ my $io = $filename.IO; # current directory
277
+ my $io = $filename.IO(:CWD($*CWD)); # same
279
278
280
- which would be the same as :
279
+ These classes consume the IO::Locally role :
281
280
282
- my $io = IO::Path.new($filename);
283
- my $io = IO::Path.new($filename, :SPEC(*$SPEC));
284
- my $io = IO::Path.new($filename, :SPEC(*$SPEC), :CWD($*CWD));
285
-
286
- If you only have filename components to start with, you can also create an
287
- C<IO::Path> object with the C<:volume>, C<:directory> and C<:basename> named
288
- parameters:
289
-
290
- my $io = IO::Path.new( :$volume, :$directory, :$basename );
281
+ IO::Handle # an opened regular file
282
+ IO::File # a regular file
283
+ IO::Dir # a directory
284
+ IO::Local # something else that exists
285
+ IOU # not recognized as something that exists
291
286
292
- The following file test methods are provided:
287
+ The following file test methods are provided by the IO::Locally role, or are
288
+ overridden by a class (e.g. C<.e> is overridden to return C<True> for all but
289
+ the C<IOU> class):
293
290
294
291
r is readable by effective uid/gid
295
292
w is writable by effective uid/gid
293
+ rw is readable and writable by effective uid/gid
296
294
x is executable by effective uid/gid
295
+ rx is readable and executable by effective uid/gid
296
+ wx is writable and executable by effective uid/gid
297
+ rwx is readable, writable and executable by effective uid/gid
297
298
o is owned by effective uid
298
299
299
300
R is readable by real uid/gid
300
301
W is writable by real uid/gid
302
+ RW is readable and writable by real uid/gid
301
303
X is executable by real uid/gid
304
+ RX is readable and executable by real uid/gid
305
+ WX is writable and executable by real uid/gid
306
+ RWX is readable, writable and executable by real uid/gid
302
307
O is owned by real uid
303
308
304
309
e exists
305
- s Size of the $!path of $io in bytes
310
+ s size of the $!path of $io in bytes
306
311
z has zero size (an empty file)
307
312
308
313
f is a plain file
@@ -318,34 +323,20 @@ The following file test methods are provided:
318
323
g has setgid bit set
319
324
k has sticky bit set
320
325
321
- To allow for easy chaining of file tests, there is an C<.all> method that can
322
- be fed the tests to be tried as a C<Parcel> of strings. The value returned
323
- will be the first non-True value, or the final True value.
326
+ A typical use case would be:
324
327
325
- say "rwx" if $io.all: <r w x>;
326
-
327
- if $io.all(<f r w x s>) -> $size {
328
- say "plain file with rwx of $size bytes";
329
- }
330
-
331
- This is mostly handy when passing file tests as parameters between routines
332
- and methods. From a performance point of view, direct use of the methods,
333
- like:
334
-
335
- if $io.f && $io.r && $io.w && $io.x && $io.s -> $size {
328
+ if $io.f && $io.rwx && $io.s -> $size {
336
329
say "plain file with rwx of $size bytes";
337
330
}
338
331
339
- or the smart match method :
332
+ which you can also smart match:
340
333
341
334
given $io {
342
- when :f :r :w :x {
335
+ when :f :rwx {
343
336
say "plain file with rwx of $_.s() bytes";
344
337
}
345
338
}
346
339
347
- is probably faster.
348
-
349
340
These other methods are also provided (in alphabetical order):
350
341
351
342
absolute the absolute, canonical path
0 commit comments