Skip to content

Commit f585083

Browse files
committed
[IO::Path]: document chmod, contents
1 parent dcc0a7e commit f585083

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

lib/Type/IO/Path.pod

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ windows), a directory, and a basename.
1212
C<IO::Path> supports both purely textual operations, and operations that
1313
access the file system.
1414
15+
The current working directory is available as an IO::Path object in C<$*CWD>.
16+
1517
The behavior of C<IO::Path> is dependent on the operating system it runs on;
1618
to get reproducible behavior across operating systems, you can use one of its
1719
subclasses instead: L<IO::Path::Unix>, L<IO::Path::Win32>,
@@ -20,10 +22,11 @@ L<IO::Path::Cygwin>, L<IO::Path::QNX>.
2022
The rest of this document silently assumes Unix semantics in its examples,
2123
unless when stated otherwise.
2224
25+
2326
=for TODO
2427
2528
document the following methods: is-absolute, is-relative, absolute,
26-
relative, parent, child, copy, chmod, contents
29+
relative, parent, child, copy,
2730
2831
=end for
2932

@@ -102,4 +105,36 @@ as the L<open> function accepts.
102105
Watches the path for modifications. Only implemented in Rakudo with the MoarVM
103106
backend at the moment.
104107

108+
=head2 method contents
109+
110+
method contents(IO::Path:D: Mu :$test = none('.', '..'))
111+
112+
Tries to interpret the path as a directory, and returns a lazy list of
113+
C<IO::Path> objects that match the C<$test> smart-matcher.
114+
115+
By default, the C<.> and C<..> entries (current directory, and parent
116+
directory) are filtered out. To get a list of all files and directories,
117+
simply pass a smart-matcher that always matches, like C<True>:
118+
C<$path.contents(:test(True))>, or shorter: C<$path.contents(:test)>.
119+
120+
An example that lists all files and directories recursively:
121+
122+
sub MAIN($dir = '.') {
123+
my @todo = $dir.path;
124+
while @todo {
125+
for @todo.pop.contents -> $path {
126+
say $path.Str;
127+
@todo.push: $path if $path.d;
128+
}
129+
}
130+
}
131+
132+
=head2 method chmod
133+
134+
method chmod(IO::Path:D: Int:D $mode)
135+
136+
Changes the POSIX permissions of a file to C<$mode>.
137+
138+
$*CWD.chmod(0o700);
139+
105140
=end POD

0 commit comments

Comments
 (0)