Mode

NAME

IO::Path::Mode - Augment Raku's IO::Path with a .mode() method to get the file mode

SYNOPSIS


use IO::Path::Mode;

my $mode = "some-file".IO.mode;

say $mode.set-user-id ?? 'setuid' !! 'not setuid';

say $mode.user.execute ?? 'executable' !! 'not executable';

say $mode.file-type == IO::Path::Mode::File ?? 'plain file' !! 'something else';

...


Or part of "ls -al" :


use IO::Path::Mode;

for ".".IO.dir -> $f {
    say $f.mode.Str, "   ", $f.Str;
}

DESCRIPTION

This augments the type IO::Path to provide a mode method that allows you to get at the file permissions (or mode.) It follows the POSIX model pf user, group and other permissions and consequently may not make a meaningful result on e.g. Windows (although the underlying calls appear to return something approximating the correct answer.)

If you have a more recent rakudo that provides a mode method, it will replace that method with one that returns an IO::Path::Mode object rather than an IntStr, this is a transitional arrangement and will be deprecated in a future release in favour of a different method name.

It relies on some non-specified functionality in the VM so may probably only work with Rakudo on MoarVM.

Loading this module will augment IO::Path with a mode method which returns an IO::Path::Mode object representing the mode of the file. The methods documented below are those of the IO::Path::Mode.

This is mostly provided as some relief for not having the functionality directly exposed in Rakudo and as a discussion board for the best way of implementing the functionality going forward.

METHODS

method mode

method mode() returns IO::Path::Mode

This returns the numeric mode of the file as would be returned by stat

method gist

method gist() returns Str

This returns the mode of the file as an octal string (e.g 100755 )

method Int

method Int()

Returns the mode as an Int, for the convenience of programmers. That is to say it can be coerced to an Int.

method Numeric

method Numeric()

This returns the mode as an Int it may be useful if a smart match against a numeric value is required.

method Str

method Str()

This returns the file mode as a string representing the file permissions as described by POSIX ls.

method file-type

method file-type() returns FileType

This returns the file type part of the mode as returned by stat. An enum is provided for the documented types:

  • Socket

  • SymbolicLink

  • File

  • Block

  • Directory

  • Character

  • FIFO

Some systems may document other types than POSIX of course.

method set-user-id

method set-user-id() returns Bool

returns a Bool to indicate whether the setuid bit is set for the file, the exact meaning may differ if the file-type is not File.

method set-group-id

method set-group-id() returns Bool

returns a Bool to indicate whether the setguid is set for the file. The meaning may differ if the file-type is not File.

method sticky

method sticky() returns Bool

This is a Bool that indicates whether the "sticky bit" is set on the file, traditionally this would indicate that the text segment of an executable should be kept in memory but it may be used for different purposes on different platforms and file types.

method user

method user() returns Permissions

This returns the set of permissions that the "owner" of the file has, represented as an Int with the role Permissions that has the following methods:

method execute

Returns a Bool to indicate the execute permission

method write

Returns a Bool to indicate the write permission

method read

Returns a Bool to indicate the read permission

method group

method group() returns Permissions

This provides the permissions of the "group" of the file in the same manner as user.

method other

method other() returns Permissions

This provides the permissions of all other users to the file in the same manner as user.

IO::Path::Mode v0.0.9

Augment IO::Path with a .mode() method to get the file mode

Authors

  • Jonathan Stowe

License

Artistic-2.0

Dependencies

Test Dependencies

Provides

  • IO::Path::Mode

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.