Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move IO::FileTestable methods into IO::Path
This addresses issue #97.  The methods and operators are now on IO::Path
anyway (IO::FileTestable no longer exists).
  • Loading branch information
Paul Cochrane committed Jul 24, 2015
1 parent 89bc3de commit fdb37eb
Showing 1 changed file with 111 additions and 2 deletions.
113 changes: 111 additions & 2 deletions lib/Type/IO/Path.pod
Expand Up @@ -316,10 +316,119 @@ deleted. The method form returns C<True> on success, or
L<fails|/routine/fail> with L<X::IO::Unlink> if the operation could not be
completed.
=head1 File Test operators
X<-e> X<-f>
The C<-e> and C<-f> file test operators do not exist in Perl 6. Use instead
C<:e> and C<:f>.
X<-M> X<-A> X<-C>
The C<-M>, C<-A> and C<-C> file test operators do not exist in Perl 6, use
instead the L<modified|/type/IO::FileTestable#method_modified>,
L<accessed|/type/IO::FileTestable#method_accessed> and
L<changed|/type/IO::FileTestable#method_changed> methods instead.
X<:e> X<:d> X<:f> X<:l> X<:r> X<:w> X<:x> X<:s> X<:z>
:e Exists
:d Directory
:f File
:l Symbolic link
:r Readable
:w Writable
:x Executable
:s Size
:z Zero size
Usage:
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 C<dir>,
you can write this:
my $file = "path/to/file".IO;
if $file ~~ :e {
say 'file exists';
}
=head1 File timestamp retrieval
There are also 3 methods for fetching the 3 timestamps of a file (inode),
on Operating Systems where these are available:
=head2 method modified
Return an L<Instant> object representing the timestamp when the file was
last modified.
say "path/to/file".IO.modified; # e.g. Instant:1424089165
To obtain a human-readable form of the timestamp, use a L<DateTime> object:
say DateTime.new("path/to/file".IO.modified); # e.g. 2015-02-16T12:18:50Z
or more readably:
my $modification_instant = "path/to/file".IO.modified;
my $modification_time = DateTime.new($modification_instant);
say $modification_time; # e.g. 2015-02-16T12:18:50Z
=head2 method accessed
Return an L<Instant> object representing the timestamp when the file was
last accessed.
say "path/to/file".IO.accessed; # e.g. Instant:1424353577
To obtain a human-readable form of the timestamp, use a L<DateTime> object:
say DateTime.new("path/to/file".IO.accessed); # e.g. 2015-02-19T13:45:42Z
or more readably:
my $access_instant = "path/to/file".IO.accessed;
my $access_time = DateTime.new($access_instant);
say $access_time; # e.g. 2015-02-19T13:45:42Z
=head2 method changed
Return an L<Instant> object representing the timestamp when the inode was
last changed.
"path/to/file".IO.changed; # e.g. Instant:1424089165
To obtain a human-readable form of the timestamp, use a L<DateTime> object:
say DateTime.new("path/to/file".IO.changed); # e.g. 2015-02-16T12:18:50Z
or more readably:
my $change_instant = "path/to/file".IO.changed;
my $change_time = DateTime.new($chnge_instant);
say $change_time; # e.g. 2015-02-16T12:18:50Z
=head1 Related roles and classes
See also the related role L<IO> and the related classes L<IO::FileTestable>
and L<IO::Handle>.
See also the related role L<IO> and the related class L<IO::Handle>.
=end pod

Expand Down

0 comments on commit fdb37eb

Please sign in to comment.