API-Eulerian
view release on metacpan or search on metacpan
lib/API/Eulerian/EDW/File.pm view on Meta::CPAN
#/usr/bin/env perl
###############################################################################
#
# @file File.pm
#
# @brief API::Eulerian::EDW::File module used to manage local file system.
#
# @author Thorillon Xavier:x.thorillon@eulerian.com
#
# @date 25/11/2021
#
# @version 1.0
#
###############################################################################
#
# Setup perl package name
#
package API::Eulerian::EDW::File;
#
# Enforce compilor rules
#
use strict; use warnings;
#
# Import API::Eulerian::EDW::Status
#
use API::Eulerian::EDW::Status;
#
# @brief Read file content.
#
# @param path - File path.
#
# @return API::Eulerian::EDW::Status
#
sub read
{
my $status = API::Eulerian::EDW::Status->new();
my ( $class, $path ) = @_;
my $data;
my $fd;
# Open file for reading
open $fd, "<", $path or do {
$status->error( 1 );
$status->code( -1 );
$status->msg( "Opening file : $path for reading failed. $!" );
return $status;
};
# Read file content
$data = do { local $/; <$fd> };
# Close file
close $fd;
# Save content
$status->{ data } = $data;
return $status;
}
#
# @brief Test if given path is writable.
#
# @param $class - API::Eulerian::EDW::File class.
# @param $path - Filesystem path.
#
# @return 0 - Path isnt writable.
# @return 1 - Path is writable.
#
sub writable
{
my ( $class, $path ) = @_;
return -w $path;
}
#
# End up perl module properly
#
1;
__END__
=pod
=head1 NAME
API::Eulerian::EDW::File - API::Eulerian::EDW File module.
=head1 DESCRIPTION
This module is used to manage local file system.
=head1 METHODS
=head2 read()
I<Read the content of a given file path.>
=head3 input
=over 4
=item * File path
=back
=head3 output
=over 4
( run in 0.453 second using v1.01-cache-2.11-cpan-39bf76dae61 )