GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Test2::Harness::Util::File(3) User Contributed Perl Documentation Test2::Harness::Util::File(3)

Test2::Harness::Util::File - Utility class for manipulating a file.

This is a utility class for file operations. This also serves as a base class for several file helpers.

    use Test2::Harness::Util::File;

    my $f = Test2::Harness::Util::File->new(name => '/path/to/file');

    $f->write($content);

    my $fh = $f->open_file('<');

    # Read, throw exception if it cannot read
    my $content = $f->read();

    # Try to read, but do not throw an exception if it cannot be read.
    my $content_or_undef = $f->maybe_read();

    my $line1 = $f->read_line();
    my $line2 = $f->read_line();
    ...

$filename = $f->name;
Get the filename. Must also be provided during construction.
$bool = $f->done;
True if read_line() has read every line.

$decoded = $f->decode($encoded)
This is a no-op, it returns the argument unchanged. This is called by "read" and "read_line". Subclasses can override this if the file contains encoded data.
$encoded = $f->encode($decoded)
This is a no-op, it returns the argument unchanged. This is called by "write". Subclasses can override this if the file contains encoded data.
$bool = $f->exists()
Check if the file exists
$content = $f->maybe_read()
This will read the file if it can and return the content (all lines joined together as a single string). If the file cannot be read, or does not exist this will return undef.
$fh = $f->open_file()
$fh = $f->open_file($mode)
Open a handle to the file. If no $mode is provided '<' is used.
$content = $f->read()
This will read the file if it can and return the content (all lines joined together as a single string). If the file cannot be read, or does not exist this will throw an exception.
$line = $f->read_line()
Read a single line from the file, subsequent calls will read the next line and so on until the end of the file is reached. Reset with the "reset()" method.
$f->reset()
Reset the internal line iterator used by "read_line()".
$f->write($content)
This is an atomic-write. First $content will be written to a temporary file using '>' mode. Then the temporary file will be renamed to the desired file name. Under the hood this uses "write_file_atomic()" from Test2::Harness::Util.

The source code repository for Test2-Harness can be found at http://github.com/Test-More/Test2-Harness/.

Chad Granum <exodist@cpan.org>

Chad Granum <exodist@cpan.org>

Copyright 2020 Chad Granum <exodist7@gmail.com>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://dev.perl.org/licenses/

2022-03-23 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.