Skip to content

Commit 4090446

Browse files
committed
[io grant] Improve chmod docs
- Split sub and method forms, as they're very different. - Remove $*CWD example; bad form without `temp`ing it first. - Add examples for chmoding dirs too - Add examples with an octal in a string
1 parent d436f3c commit 4090446

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

doc/Type/IO.pod6

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ you do not need to change process's current directory:
8181
temp $*CWD;
8282
&*chdir('/tmp');
8383
84+
=head2 sub chmod
85+
86+
sub chmod(Int() $mode, *@filenames --> List)
87+
88+
Coerces all C<@filenames> to L«C<IO::Path>|/type/IO::Path» and calls
89+
L«C<IO::Path.chmod>|/type/IO::Path#method_chmod» with C<$mode> on them.
90+
Returns a L«C<List>|/type/List» containing a subset of C<@filenames> for which
91+
C<chmod> was successfully executed.
92+
93+
chmod 0o755, <myfile1 myfile2>; # make two files executable by the owner
94+
8495
=head2 sub indir
8596
8697
Defined as:

doc/Type/IO/Path.pod6

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -528,32 +528,29 @@ contents you will have to do something more complex.
528528
529529
See also L<rmtree in File::Directory::Tree|https://github.com/labster/p6-file-directory-tree>.
530530
531-
=head2 routine chmod
531+
=head2 method chmod
532532
533-
sub chmod($mode, *@filenames --> List)
534-
method chmod(IO::Path:D: $mode --> Bool)
533+
method chmod(IO::Path:D: Int() $mode --> Bool)
535534
536-
Changes the POSIX permissions of a file (or in the subroutine form, any number
537-
of files) to C<$mode>.
538-
539-
The subroutine form returns the names of the files for which setting the new
540-
mode was successful. The method form returns True on success, and otherwise
535+
Changes the POSIX permissions of a file or directory to C<$mode>.
536+
Returns C<True> on success; on failure,
541537
L<fails|/routine/fail> with L<X::IO::Chmod>.
542538
543539
The mode is expected as an integer following the L<standard numeric notation|
544540
https://en.wikipedia.org/wiki/File_system_permissions#Numeric_notation>, and is
545541
best written as an octal number:
546542
547543
=for code :skip-test
548-
chmod 0o755, "myfile1", "myfile2"; # make two files executable by the owner
549-
"myfile".IO.chmod(0o444); # make a file read-only
550-
$*CWD.chmod(0o544); # make the working directory read-only
544+
'myfile'.IO.chmod(0o444); # make a file read-only
545+
'somedir'.IO.chmod(0o777); # set 0777 permissions on a directory
551546
552547
Make sure you I<don't> accidentally pass the intended octal digits as a decimal
553548
number (or string containing a decimal number):
554549
555550
=for code :skip-test
556-
chmod '0444', 'myfile'; # BAD!!! (interpreted as mode 0o674)
551+
chmod '0444', 'myfile'; # BAD!!! (interpreted as mode 0o674)
552+
chmod '0o444', 'myfile'; # OK (an octal in a string)
553+
chmod 0o444, 'myfile'; # Also OK (an octal literal)
557554
558555
=head2 routine rename
559556

0 commit comments

Comments
 (0)