See the IO::Path doc.
For example:
say 'foo'.IO.s; # 3 if 'foo' is an existing file of size 3 bytes
.IO
on a string creates an IO::Path
object corresponding to the filesystem entry corresponding to the path given by the string.
See examples of using junctions to get multiple attributes at the same time at the doc on ACCEPTS
.
I'm not sure if the following is too much. Ignore it if it is. Hopefully it's helpful.
You can discover/explore some of what's available in Perl 6 via its HOW objects (aka Higher Order Workings objects, How Objects Work objects, metaobjects -- whatever you want to call them) which know HOW objects of a particular type work.
say IO::Path.^methods
displays:
(BUILD new is-absolute is-relative parts volume dirname basename extension
Numeric sibling succ pred open watch absolute relative cleanup resolve
parent child add chdir rename copy move chmod unlink symlink link mkdir
rmdir dir slurp spurt lines comb split words e d f s l r w rw x rwx z
modified accessed changed mode ACCEPTS Str gist perl IO SPEC CWD path BUILDALL)
Those are some of the methods available on an IO::Path
object.
(You can get more or less with adverbs, eg. say IO::Path.^methods(:all)
, but the default display aims at giving you the ones you're likely most interested in. The up arrow (^
) means the method call (.methods
) is not sent to the invocant but rather is sent "upwards", up to its HOW object as explained above.)
Here's an example of applying some of them one at a time:
spurt 'foo', 'bar'; # write a three letter string to a file called 'foo'.
for <e d f s l r w rw x rwx z modified accessed changed mode>
-> $method { say 'foo'.IO."$method"() }
The second line does a for
loop over the methods listed by their string names in the <...>
construct. To call a method on an invocant given it's name in a variable $qux
, write ."$qux"(...)
.
stat
portably without the user needing to write system-specific native calls, and so Perl6 can and should provide the same functionality, but it doesn't -- e.g., IO::Path doesn't provide theblocks
field, which I happen to need. One of the great values of perl5 is that it provides POSIX functionality even on non-POSIX systems. The perl6 turkeys broke that. – Suppressive