Sweet::File
use Sweet::File; my $file1 = Sweet::File->new( dir => '/path/to/dir', name => 'foo', ); my $file2 = Sweet::File->new(path => '/path/to/file');
Instance of Sweet::Dir. If not provided, depends on "path".
Defaults to utf8.
utf8
A string containing the file name. If not provided, depends on "path".
Instance of Path::Class::File. If not provided, depends on "dir" and "name".
Append lines to a file.
my @lines = ('first appended line', 'second appended line'); $file->append(\@lines);
Copy file to a directory.
$file->copy_to_dir($dir);
Coerces path to Sweet::Dir.
$file->copy_to_dir('/path/to/dir');
Coerces ArrayRef to Sweet::Dir.
ArrayRef
$file->copy_to_dir(['/path/to', 'dir']);
The negation of the -e flag in natural language.
-e
Removes file, using File::Remove.
$file->erase
The -z flag in natural language.
-z
$file->has_zero_size
The -f flag in natural language.
-f
$file->is_a_plain_file
The -x flag in natural language.
-x
$file->is_executable
The -w flag in natural language.
-w
$file->is_writable
Returns the nth line.
my $line1 = $file->line(0); my $line2 = $file->line(1); my $line3 = $file->line(2);
for my $line ( $file->lines ) { $line =~ s/foo/bar/; say $line; }
Move file to a directory.
$file->move_to_dir($dir);
It is just a shortcut to
$file->copy_to_dir($dir) && $file->erase;
say $file->num_lines if $file->is_a_plain_file;
Get first line splitted on pipe.
my @parts = $file->split_line->('|')->(0);
Split lines on comma.
my $splitted_line = $file->split_line->(','); my @parts0 = $splitted_line->(0); my @parts1 = $splitted_line->(1);
Write lines to a brand new file.
my @lines = ('first line', 'second line'); my $file = Sweet::File->new( name => 'brand_new_file.txt', dir => $dir, lines => \@lines, ); $file->write;
The "lines" builder. To be overridden in subclasses, if needed. It opens a filehandle, put it in an array, chomp it and returns the array reference.
The "dir" builder. To be overridden in subclasses, if needed.
The "name" builder. To be overridden in subclasses, if needed.
The "extension" builder. To be overridden in subclasses, if needed.
The "path" builder. To be overridden in subclasses, if needed.
To install Sweet::Home, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sweet::Home
CPAN shell
perl -MCPAN -e shell install Sweet::Home
For more information on module installation, please visit the detailed CPAN module installation guide.