Name
SPVM::IO::Dir - Directory Streams
Description
The IO::Dir class in SPVM has methods for directory streams.
Usage
use IO::Dir;
my $dh = IO::Dir->new(".");
while (my $dirent = $dh->read) {
say $dirent->d_name;
}
my $offset = $dh->tell;
$dh->seek($offset);
Details
Porting
This class is a Perl's IO::Dir porting to SPVM.
Implementation
An opened directory stream is automatically closed when the instance is destroyed.
Fields
dir_stream
has dir_stream : Sys::IO::DirStream;
A directory stream.
Class Methods
static method new : IO::Dir ($dir_path : string = undef);
Creates a new IO::Dir object, calls "open" method with the directory path $dir_path, and returns the created object.
If $dir_path is not defined, "open" method is not called.
Exceptions:
Exceptions thrown by "open" method could be thrown.
See Also:
See IO#opendir method if you find a method ported from Perl opendir function.
Instance Methods
open
method open : void ($dir_path : string);
Opens a directory stream given the directory path $dir_path and sets "dir_stream" field to it.
This method calls Sys#opendir method.
Exceptions:
Exceptions thrown by Sys#opendir method could be thrown.
read
method read : Sys::IO::Dirent ();
Reads a directory entry from the directory stream stored in "dir_stream" field and returns it.
This method calls Sys#readdir method.
Exceptions:
Exceptions thrown by Sys#readdir method could be thrown.
seek
method seek : void ($offset : long);
Sets the location in the directory stream stored in "dir_stream" field to the offset $offset.
$offset should be the return value of "tell" method.
This method calls Sys#seekdir method.
Exceptions:
Exceptions thrown by Sys#seekdir method could be thrown.
tell
method tell : long ();
Returns the location in the directory stream stored in "dir_stream" field.
This method calls Sys#telldir method.
Exceptions:
Exceptions thrown by Sys#telldir method could be thrown.
rewind
method rewind : void ();
Resets the position of the directory stream stored in "dir_stream" field.
This method calls Sys#rewinddir method.
Exceptions:
Exceptions thrown by Sys#rewinddir method could be thrown.
close
method close : void ();
Closes the directory stream stored in "dir_stream" field.
This method calls Sys#closedir method.
Exceptions:
Exceptions thrown by Sys#closedir method could be thrown.
opened
method opened : int ();
If the directory stream stored in "dir_stream" is opened, returns 1, otherwise returns 0.
Copyright & License
Copyright (c) 2024 Yuki Kimoto
MIT License