App-MBUtiny
view release on metacpan or search on metacpan
lib/App/MBUtiny/Storage.pm view on Meta::CPAN
package App::MBUtiny::Storage; # $Id: Storage.pm 121 2019-07-01 19:51:50Z abalama $
use strict;
use utf8;
=encoding utf-8
=head1 NAME
App::MBUtiny::Storage - App::MBUtiny storage class
=head1 VIRSION
Version 1.00
=head1 SYNOPSIS
use App::MBUtiny::Storage;
my $storage = new App::MBUtiny::Storage(
name => $name, # Backup name
host => $host, # Host config section
path => "/tmp/mbutiny/files", # Where is located backup archive
);
print $storage->error unless $storage->status;
=head1 DESCRIPTION
App::MBUtiny storage class
Storage - is a directory on disk, a remote FTP/SFTP/ HTTP server
or CLI process that simulates storage functional.
=head2 new
my $storage = new App::MBUtiny::Storage(
name => $name, # Backup name
host => $host, # Host config section
path => "/tmp/mbutiny/files", # Where is located backup archive
fixup => sub {
my $strg = shift; # Storage object
my $oper = shift // 'noop'; # Operation name
my @args = @_;
return 1;
},
validate => sub {
my $strg = shift; # storage object
my $file = shift; # fetched file name
return 1;
},
);
Returns storage object
=head2 cleanup
$storage->cleanup();
Flushes errors and the status property to defaults
=head2 del
my $status = $storage->del("foo-2019-06-25.tar.gz");
Performs the "del" method in all storage subclasses
Returns summary status. See L</summary>
=head2 error
print $storage->error("Foo"); # Foo
print $storage->error("Bar"); # Foo\nBar
print $storage->error; # Foo\nBar
print $storage->error(""); # <"">
Sets and gets the error pool
=head2 fixup
Callback the "fixup" method. This method called automatically
when the put method performs
=head2 get
$st = $storage->get(
name => "foo-2019-06-25.tar.gz",
file => "/full/path/to/foo-2019-06-25.tar.gz",
);
Fetching backup file to specified file path from each storage until first successful result
Returns summary status. See L</summary>
=head2 init
Performs the "init" method in all storage subclasses and returns self object instance
For internal use only
=head2 list
my @filelist = $storage->list;
Returns summary list of backup files from all available storages
=head2 put
$st = $storage->put(
name => "foo-2019-06-25.tar.gz",
file => "/full/path/to/foo-2019-06-25.tar.gz",
size => 123456,
);
Sending backup file to each available storage
Returns summary status. See L</summary>
=head2 status
my $new_status = $storage->status(0);
Sets new status value and returns it
my $status = $storage->status;
Returns status value. 0 - Error; 1 - Ok
=head2 storage_status
$storage->storage_status(HTTP => 0);
my $storage_status = $storage->storage_status("HTTP");
Sets/gets storage status. For internal use only
=head2 summary
my $status = $storage->summary;
Returns summary status.
=over 4
=item B<1> PASS status. Process successful
=item B<0> FAIL status. Process failed
=item B<-1> SKIP status. Process was skipped
=back
=head2 test
my $test = $storage->test or die $storage->error;
Performs testing each storage and returns summary status. See L</summary>
=head2 test_report
foreach my $tr ($storage->test_report) {
my ($st, $vl, $er) = @$tr;
print STDOUT $vl, "\n";
print STDOUT $st ? $st < 0 ? 'SKIP' : 'PASS' : 'FAIL', "\n";
print STDERR $er, "\n";
);
}
Returns list of test result for each storage as:
[
[STATUS, NAME, ERROR],
# ...
]
=head2 validate
( run in 0.793 second using v1.01-cache-2.11-cpan-39bf76dae61 )