role IO::FileTestable

Common role for paths that can be tested for filesystem metadata

role IO::FileTestable does IO { }


File Test operators

-e :-f

-f Does not exist in Perl 6. See :e, :f.

-M -A -C

-M Does not exist in Perl 6. See C<modified>.
-A Does not exist in Perl 6. See C<accessed>.
-C Does not exist in Perl 6. See C<changed>.

:e :d :f :l :r :w :x :s :z

:e Exists
:d Directory
:f File
:l Symbolic link
:r Readable
:w Writable
:x Executable
:s Size
:z Zero size


If you have a string - a path to something in the filesystem:

if "path/to/file".IO ~~ :e {
    say 'file exists';
my $file = "path/to/file";
if $file.IO ~~ :e {
    say 'file exists';

Instead of the colonpair syntax, you can use method calls too:

if 'path/to/file'.IO.e {
    say 'file exists';

If you already have an IO object in $file, either by creating one yourself, or by getting it from another subroutine, such as dir, you can write this:

my $file = "path/to/file".IO;
if $file ~~ :e {
    say 'file exists';

There are also 3 methods for fetching the 3 timestamps of a file (inode), on Operating Systems where these are available:

method modified

Timestamp when the file was last modified.


method accessed

Timestamp when the file was last accessed.


method changed

Timestamp when the inode was last changed.


Type graph

Below you should see a clickable image showing the type relations for IO::FileTestable that links to the documentation pages for the related types. If not, try the PNG version instead.

perl6-type-graph IO::FileTestable IO::FileTestable IO IO IO::FileTestable->IO