diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-03-08 09:50:36 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-03-08 11:50:33 +0200 |
commit | a8494c5196f7b0135a50577c8d90584a3c9d62f6 (patch) | |
tree | bb27fa9925798db485fe87e6bd09c504a5548c7c | |
parent | 11f3b2bd7064cb5f1f5bb902a9b9cf57cd75abf7 (diff) | |
download | glacier-a8494c5196f7b0135a50577c8d90584a3c9d62f6.tar.gz glacier-a8494c5196f7b0135a50577c8d90584a3c9d62f6.tar.bz2 |
Version 2.00
* Changes: Version 2.00
* lib/App/Glacier.pm (new): Fix option parsing.
* lib/App/Glacier/Core.pm (clone): New method.
* lib/App/Glacier/Command.pm (clone): New method.
* lib/App/Glacier/Command/ListVault.pm: Clone the Sync method
from $self, instead of initializing it from scratch.
-rw-r--r-- | Changes | 4 | ||||
-rw-r--r-- | lib/App/Glacier.pm | 13 | ||||
-rw-r--r-- | lib/App/Glacier/Command.pm | 13 | ||||
-rw-r--r-- | lib/App/Glacier/Command/ListVault.pm | 6 | ||||
-rw-r--r-- | lib/App/Glacier/Core.pm | 11 |
5 files changed, 37 insertions, 10 deletions
@@ -1,3 +1,7 @@ +2.00 2018-03-08 + +* Redo the class system. + 1.00 2018-02-24 * Initial release. diff --git a/lib/App/Glacier.pm b/lib/App/Glacier.pm index 47ed91c..8d62f56 100644 --- a/lib/App/Glacier.pm +++ b/lib/App/Glacier.pm @@ -8,7 +8,7 @@ use App::Glacier::Command; use File::Basename; use Carp; -our $VERSION = '1.00'; +our $VERSION = '2.00'; my %comtab = ( @@ -70,21 +70,22 @@ sub getcom { sub new { my ($class, $argref) = shift; - my %args; + my $self = $class->SUPER::new( $argref, optmap => { - 'config-file|f=s' => sub { $args{config} = $_[1] }, - 'account=s' => sub { $args{account} = $_[1] }, - 'region=s' => sub { $args{region} = $_[1] } + 'config-file|f=s' => 'config', + 'account=s' => 'account', + 'region=s' => 'region' }); + my $com = shift @{$self->argv} or $self->usage_error("no command name"); &{$self->getcom($com)}($self->argv, debug => $self->{_debug}, dry_run => $self->dry_run, progname => $self->progname, - %args); + %{$self->{_options} // {}}); } __END__ diff --git a/lib/App/Glacier/Command.pm b/lib/App/Glacier/Command.pm index 3267c01..a641f34 100644 --- a/lib/App/Glacier/Command.pm +++ b/lib/App/Glacier/Command.pm @@ -108,7 +108,7 @@ sub new { my $dry_run = delete $_{dry_run}; my $progname = delete $_{progname}; - my $self = bless $class->SUPER::new($argref, %_), $class; + my $self = $class->SUPER::new($argref, %_); $self->{_debug} = $debug if $debug; $self->{_dry_run} = $dry_run if $dry_run; @@ -153,6 +153,17 @@ sub new { return $self; } +# Produce a semi-flat clone of $orig, blessing it into $class. +# The clone is semi-flat, because it shares the parsed configuration and +# the glacier object with the $orig. +sub clone { + my ($class, $orig) = @_; + my $self = $class->SUPER::clone($orig); + $self->{_config} = $orig->config; + $self->{_glacier} = $orig->{_glacier}; + $self +} + sub touchdir { my ($self, $dir) = @_; unless (-d $dir) { diff --git a/lib/App/Glacier/Command/ListVault.pm b/lib/App/Glacier/Command/ListVault.pm index c19e7e7..47b56c9 100644 --- a/lib/App/Glacier/Command/ListVault.pm +++ b/lib/App/Glacier/Command/ListVault.pm @@ -305,11 +305,11 @@ sub get_vault_inventory { unless defined $dir; unless ($self->{_options}{cached}) { - if ($dir->status == DIR_PENDING) { + if ($dir->status == DIR_PENDING) { require App::Glacier::Command::Sync; - my $sync = new App::Glacier::Command::Sync; + my $sync = clone App::Glacier::Command::Sync($self); $sync->sync($vault_name) or exit(EX_TEMPFAIL); - } + } } my @glob; diff --git a/lib/App/Glacier/Core.pm b/lib/App/Glacier/Core.pm index 9ac2494..0d0f072 100644 --- a/lib/App/Glacier/Core.pm +++ b/lib/App/Glacier/Core.pm @@ -6,6 +6,7 @@ use Pod::Man; use Pod::Usage; use Pod::Find qw(pod_where); use File::Basename; +use Storable; use Carp; require Exporter; @@ -100,6 +101,16 @@ sub new { return $self; } +sub clone { + my ($class, $orig) = @_; + bless { + _debug => $orig->{_debug}, + _dry_run => $orig->{_dry_run}, + _progname => $orig->{_progname}, + _argref => [ Storable::dclone($orig->{_argref}) ] + }, $class +} + sub dry_run { shift->{_dry_run} } sub argv { shift->{_argref} } sub command_line { @{shift->{_argref}} } |