--- name: IO::Dir runtime: pp source: src/native/IO/Dir/pp.rs --- ```{index} single: IO::Dir; Perl module (pp runtime) ``` # IO::Dir Native implementation of IO::Dir Provides object-oriented directory operations compatible with Perl's IO::Dir. IO::Dir objects are blessed hashrefs. The `__dh_id` key stores the directory handle ID (u64) that maps to an entry in DIRHANDLE_TABLE. # Functions ## new Constructor. With no arguments, returns an unopened IO::Dir object. With a directory name, opens the directory and returns a blessed handle. ```perl use IO::Dir; my $d = IO::Dir->new("/tmp"); my $d = IO::Dir->new(); ``` ## open Opens (or re-opens) a directory on an existing IO::Dir object. Closes any previously opened directory first. Returns 1 on success, undef on failure. ```perl my $d = IO::Dir->new; $d->open("/tmp") or die $!; ``` ## read Reads the next directory entry. Returns the entry name as a string, or undef at end-of-directory. ```perl while (defined(my $entry = $d->read)) { print "$entry\n"; } ``` ## close Closes the directory handle and removes it from DIRHANDLE_TABLE. ```perl $d->close(); ``` ## rewind Resets the directory read position to the beginning. ```perl $d->rewind(); ``` ## seek Sets the directory read position to a given offset (as returned by `tell`). ```perl $d->seek($saved_pos); ``` ## tell Returns the current directory read position, or -1 on error. ```perl my $pos = $d->tell(); ``` ## DESTROY Destructor. Automatically closes the directory handle when the object goes out of scope. ## DIR_UNLINK Exportable constant (value 1). Used by tie-based directory operations.