Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f93b80e4

Von Moritz Bunkus vor etwa 5 Jahren hinzugefügt

  • ID f93b80e46fe43b677abf8bfa71cca68b9ec0c805
  • Vorgänger 65b2387a
  • Nachfolger 1d540b8d

Module: Devel::REPL::Plugin::* aus modules/override verschoben

Es handelt sich um explizit für kivitendo geschriebene Module, daher
sind sie im override falsch.

Unterschiede anzeigen:

Devel/REPL/Plugin/AutoloadModules.pm
1
package Devel::REPL::Plugin::AutoloadModules;
2

  
3
use Moose::Role;
4
use namespace::clean -except => [ 'meta' ];
5
use Data::Dumper;
6

  
7
has 'autoloaded' => ( is => 'rw', isa => 'HashRef', default => sub { {} } );
8

  
9
my $re = qr/Runtime error: Can.t locate object method "\w+" via package "\w+" \(perhaps you forgot to load "(\w+)"\?\)/;
10
around 'execute' => sub {
11
  my $orig = shift;
12
  my $self = shift;
13

  
14
  my @re = $self->$orig(@_);                           # original call
15

  
16
  return @re unless defined $re[0] && $re[0] =~ /$re/; # if there is no "perhaps you forgot" error, just return
17
  my $module = $1;                                     # save the missing package name
18

  
19
  return @re if $self->autoloaded->{$module};          # if we tried to load it before, give up and return the error
20

  
21
  $self->autoloaded->{$module} = 1;                    # make sure we don't try this again
22
  $self->eval("use SL::$module");                      # try to load the missing module
23

  
24
  @re = $self->$orig(@_);                              # try again
25

  
26
  return @re;
27
};
28

  
29
1;
Devel/REPL/Plugin/PermanentHistory.pm
1
package Devel::REPL::Plugin::PermanentHistory;
2

  
3
use Moose::Role;
4
use namespace::clean -except => [ 'meta' ];
5
use File::Slurp;
6
use Data::Dumper;
7

  
8
has 'history_file' => ( is => 'rw' );
9

  
10
sub load_history {
11
  my $self = shift;
12
  my $file = shift;
13

  
14
  $self->history_file( $file );
15

  
16
  return unless $self->history_file && -f $self->history_file;
17

  
18
  my @history =
19
    map { chomp; $_ }
20
    read_file($self->history_file);
21
#  print  Dumper(\@history);
22
  $self->history( \@history );
23
  $self->term->addhistory($_) for @history;
24
}
25

  
26
before 'DESTROY' => sub {
27
  my $self = shift;
28

  
29
  return unless $self->history_file;
30

  
31
  write_file $self->history_file,
32
    map { $_, $/ }
33
    grep $_,
34
    grep { !/^quit\b/ }
35
    @{ $self->history };
36
};
37

  
38
1;
39

  
modules/override/Devel/REPL/Plugin/AutoloadModules.pm
1
package Devel::REPL::Plugin::AutoloadModules;
2

  
3
use Moose::Role;
4
use namespace::clean -except => [ 'meta' ];
5
use Data::Dumper;
6

  
7
has 'autoloaded' => ( is => 'rw', isa => 'HashRef', default => sub { {} } );
8

  
9
my $re = qr/Runtime error: Can.t locate object method "\w+" via package "\w+" \(perhaps you forgot to load "(\w+)"\?\)/;
10
around 'execute' => sub {
11
  my $orig = shift;
12
  my $self = shift;
13

  
14
  my @re = $self->$orig(@_);                           # original call
15

  
16
  return @re unless defined $re[0] && $re[0] =~ /$re/; # if there is no "perhaps you forgot" error, just return
17
  my $module = $1;                                     # save the missing package name
18

  
19
  return @re if $self->autoloaded->{$module};          # if we tried to load it before, give up and return the error
20

  
21
  $self->autoloaded->{$module} = 1;                    # make sure we don't try this again
22
  $self->eval("use SL::$module");                      # try to load the missing module
23

  
24
  @re = $self->$orig(@_);                              # try again
25

  
26
  return @re;
27
};
28

  
29
1;
modules/override/Devel/REPL/Plugin/PermanentHistory.pm
1
package Devel::REPL::Plugin::PermanentHistory;
2

  
3
use Moose::Role;
4
use namespace::clean -except => [ 'meta' ];
5
use File::Slurp;
6
use Data::Dumper;
7

  
8
has 'history_file' => ( is => 'rw' );
9

  
10
sub load_history {
11
  my $self = shift;
12
  my $file = shift;
13

  
14
  $self->history_file( $file );
15

  
16
  return unless $self->history_file && -f $self->history_file;
17

  
18
  my @history =
19
    map { chomp; $_ }
20
    read_file($self->history_file);
21
#  print  Dumper(\@history);
22
  $self->history( \@history );
23
  $self->term->addhistory($_) for @history;
24
}
25

  
26
before 'DESTROY' => sub {
27
  my $self = shift;
28

  
29
  return unless $self->history_file;
30

  
31
  write_file $self->history_file,
32
    map { $_, $/ }
33
    grep $_,
34
    grep { !/^quit\b/ }
35
    @{ $self->history };
36
};
37

  
38
1;
39

  

Auch abrufbar als: Unified diff