Skip to content

Commit

Permalink
IO::Path: restructure the file test operator section.
Browse files Browse the repository at this point in the history
Update examples, reference .path.
  • Loading branch information
cfa committed Feb 22, 2019
1 parent 39140e3 commit fba25f8
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions doc/Type/IO/Path.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -571,23 +571,10 @@ my $perl-files = gather while @stack {
For most file tests, you can do a smartmatch C<~~> or you can call a method.
You don't need to actually open a filehandle in the traditional way (although
you can) to do a filetest. You can simply append C<.IO> to the filename. For
instance, here is how to check if a file is readable using smartmatch:
instance, here is how to check whether a file is readable using smartmatch:
'/path/to/file'.IO ~~ :r;
L«Smartmatching on Pairs|/type/Pair#method_ACCEPTS» is useful for performing
multiple file tests:
say :d & :x; # OUTPUT: «all(d => True, x => True)␤»
say '/tmp'.IO ~~ :d & :x; # OUTPUT: «True␤»
say '/'.IO ~~ :d & :rw; # OUTPUT: «False␤»
You can, of course, use an already opened filehandle. Here, using the filehandle
C<$fh>, is an example, using the method syntax for the file test:
=for code :preamble<my $fh>
$fh.r
File tests include:
=item C<:d> (L«Directory|/type/IO::Path#method_d»)
Expand All @@ -602,13 +589,23 @@ File tests include:
=item C<:x> (L«Executable|/type/IO::Path#method_x»)
=item C<:z> (L«Zero size|/type/IO::Path#method_z»)
All of these tests can be used as methods (without the colon).
Three tests, however exist only as methods:
L«Smartmatching on Pairs|/type/Pair#method_ACCEPTS» can be used to perform
multiple tests at once:
say :d & :x; # OUTPUT: «all(d => True, x => True)␤»
say '/tmp'.IO ~~ :d & :x; # OUTPUT: «True␤»
say '/'.IO ~~ :d & :rw; # OUTPUT: «False␤»
All of the above tests can be used as methods (without the colon), though method tests
may throw C<X::IO::DoesNotExist> as documented below. Three tests only exist as methods:
L«C<accessed>|#method_accessed», L«C<changed>|#method_changed» and L«C<modified>|#method_modified».
You can also perform file tests on an already opened filehandle by testing against its
L«C<.path>|/type/IO::Handle#method_path» method. For example, given filehandle C<$fh>:
=for code :preamble<my $fh>
$fh.modified;
$fh.accessed;
$fh.changed;
$fh.path ~~ :r;
$fh.path.r; # method form
=head2 method e
Expand Down

0 comments on commit fba25f8

Please sign in to comment.