Skip to content

Commit ce469ea

Browse files
committed
Some more on IO::Locally
1 parent 715ca5c commit ce469ea

File tree

1 file changed

+28
-37
lines changed

1 file changed

+28
-37
lines changed

S16-io.pod

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -268,41 +268,46 @@ An overview:
268268

269269
=head3 IO::Locally role
270270

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

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
279278

280-
which would be the same as:
279+
These classes consume the IO::Locally role:
281280

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
291286

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):
293290

294291
r is readable by effective uid/gid
295292
w is writable by effective uid/gid
293+
rw is readable and writable by effective uid/gid
296294
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
297298
o is owned by effective uid
298299

299300
R is readable by real uid/gid
300301
W is writable by real uid/gid
302+
RW is readable and writable by real uid/gid
301303
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
302307
O is owned by real uid
303308

304309
e exists
305-
s Size of the $!path of $io in bytes
310+
s size of the $!path of $io in bytes
306311
z has zero size (an empty file)
307312

308313
f is a plain file
@@ -318,34 +323,20 @@ The following file test methods are provided:
318323
g has setgid bit set
319324
k has sticky bit set
320325

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:
324327

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 {
336329
say "plain file with rwx of $size bytes";
337330
}
338331

339-
or the smart match method:
332+
which you can also smart match:
340333

341334
given $io {
342-
when :f :r :w :x {
335+
when :f :rwx {
343336
say "plain file with rwx of $_.s() bytes";
344337
}
345338
}
346339

347-
is probably faster.
348-
349340
These other methods are also provided (in alphabetical order):
350341

351342
absolute the absolute, canonical path

0 commit comments

Comments
 (0)