From: Moritz Bunkus Date: Fri, 29 Mar 2019 14:22:00 +0000 (+0100) Subject: Module: Devel::REPL::Plugin::* aus modules/override verschoben X-Git-Tag: release-3.5.4~75^2~19 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=f93b80e46fe43b677abf8bfa71cca68b9ec0c805;p=kivitendo-erp.git Module: Devel::REPL::Plugin::* aus modules/override verschoben Es handelt sich um explizit für kivitendo geschriebene Module, daher sind sie im override falsch. --- diff --git a/Devel/REPL/Plugin/AutoloadModules.pm b/Devel/REPL/Plugin/AutoloadModules.pm new file mode 100644 index 000000000..e36ee9654 --- /dev/null +++ b/Devel/REPL/Plugin/AutoloadModules.pm @@ -0,0 +1,29 @@ +package Devel::REPL::Plugin::AutoloadModules; + +use Moose::Role; +use namespace::clean -except => [ 'meta' ]; +use Data::Dumper; + +has 'autoloaded' => ( is => 'rw', isa => 'HashRef', default => sub { {} } ); + +my $re = qr/Runtime error: Can.t locate object method "\w+" via package "\w+" \(perhaps you forgot to load "(\w+)"\?\)/; +around 'execute' => sub { + my $orig = shift; + my $self = shift; + + my @re = $self->$orig(@_); # original call + + return @re unless defined $re[0] && $re[0] =~ /$re/; # if there is no "perhaps you forgot" error, just return + my $module = $1; # save the missing package name + + return @re if $self->autoloaded->{$module}; # if we tried to load it before, give up and return the error + + $self->autoloaded->{$module} = 1; # make sure we don't try this again + $self->eval("use SL::$module"); # try to load the missing module + + @re = $self->$orig(@_); # try again + + return @re; +}; + +1; diff --git a/Devel/REPL/Plugin/PermanentHistory.pm b/Devel/REPL/Plugin/PermanentHistory.pm new file mode 100644 index 000000000..3a46b56cf --- /dev/null +++ b/Devel/REPL/Plugin/PermanentHistory.pm @@ -0,0 +1,39 @@ +package Devel::REPL::Plugin::PermanentHistory; + +use Moose::Role; +use namespace::clean -except => [ 'meta' ]; +use File::Slurp; +use Data::Dumper; + +has 'history_file' => ( is => 'rw' ); + +sub load_history { + my $self = shift; + my $file = shift; + + $self->history_file( $file ); + + return unless $self->history_file && -f $self->history_file; + + my @history = + map { chomp; $_ } + read_file($self->history_file); +# print Dumper(\@history); + $self->history( \@history ); + $self->term->addhistory($_) for @history; +} + +before 'DESTROY' => sub { + my $self = shift; + + return unless $self->history_file; + + write_file $self->history_file, + map { $_, $/ } + grep $_, + grep { !/^quit\b/ } + @{ $self->history }; +}; + +1; + diff --git a/modules/override/Devel/REPL/Plugin/AutoloadModules.pm b/modules/override/Devel/REPL/Plugin/AutoloadModules.pm deleted file mode 100644 index e36ee9654..000000000 --- a/modules/override/Devel/REPL/Plugin/AutoloadModules.pm +++ /dev/null @@ -1,29 +0,0 @@ -package Devel::REPL::Plugin::AutoloadModules; - -use Moose::Role; -use namespace::clean -except => [ 'meta' ]; -use Data::Dumper; - -has 'autoloaded' => ( is => 'rw', isa => 'HashRef', default => sub { {} } ); - -my $re = qr/Runtime error: Can.t locate object method "\w+" via package "\w+" \(perhaps you forgot to load "(\w+)"\?\)/; -around 'execute' => sub { - my $orig = shift; - my $self = shift; - - my @re = $self->$orig(@_); # original call - - return @re unless defined $re[0] && $re[0] =~ /$re/; # if there is no "perhaps you forgot" error, just return - my $module = $1; # save the missing package name - - return @re if $self->autoloaded->{$module}; # if we tried to load it before, give up and return the error - - $self->autoloaded->{$module} = 1; # make sure we don't try this again - $self->eval("use SL::$module"); # try to load the missing module - - @re = $self->$orig(@_); # try again - - return @re; -}; - -1; diff --git a/modules/override/Devel/REPL/Plugin/PermanentHistory.pm b/modules/override/Devel/REPL/Plugin/PermanentHistory.pm deleted file mode 100644 index 3a46b56cf..000000000 --- a/modules/override/Devel/REPL/Plugin/PermanentHistory.pm +++ /dev/null @@ -1,39 +0,0 @@ -package Devel::REPL::Plugin::PermanentHistory; - -use Moose::Role; -use namespace::clean -except => [ 'meta' ]; -use File::Slurp; -use Data::Dumper; - -has 'history_file' => ( is => 'rw' ); - -sub load_history { - my $self = shift; - my $file = shift; - - $self->history_file( $file ); - - return unless $self->history_file && -f $self->history_file; - - my @history = - map { chomp; $_ } - read_file($self->history_file); -# print Dumper(\@history); - $self->history( \@history ); - $self->term->addhistory($_) for @history; -} - -before 'DESTROY' => sub { - my $self = shift; - - return unless $self->history_file; - - write_file $self->history_file, - map { $_, $/ } - grep $_, - grep { !/^quit\b/ } - @{ $self->history }; -}; - -1; -