Subject: | Enhancement: Support -I flag |
I often miss the "-I" command line parameter in re.pl to add directories to @INC (so that it behaves similar to perl).
The attached patch adds a "incdir" attribute to Devel::REPL::Script which adds the "-I" functionality.
I didn't add anything to the documentation as it's pretty self-explaining IMHO.
Please review!
Subject: | add_inc.patch |
628d0340062fb6fc29134be114390bbdd50ef903
diff --git a/lib/Devel/REPL/Script.pm b/lib/Devel/REPL/Script.pm
index fb1e953..d3e6bf7 100644
--- a/lib/Devel/REPL/Script.pm
+++ b/lib/Devel/REPL/Script.pm
@@ -22,6 +22,14 @@ has 'profile' => (
default => sub { $ENV{DEVEL_REPL_PROFILE} || 'Minimal' },
);
+has 'incdir' => (
+ is => 'ro',
+ isa => 'ArrayRef[Str]',
+ traits => ['MooseX::Getopt::Meta::Attribute::Trait'],
+ default => sub { [] },
+ cmd_flag => 'I'
+);
+
has '_repl' => (
is => 'ro', isa => 'Devel::REPL',
default => sub { Devel::REPL->new() }
@@ -31,6 +39,7 @@ sub BUILD {
my ($self) = @_;
$self->load_profile($self->profile);
$self->load_rcfile($self->rcfile);
+ $self->add_inc();
}
sub load_profile {
@@ -53,6 +62,12 @@ sub load_rcfile {
$self->apply_script($rc_file);
}
+sub add_inc {
+ my $self = shift;
+ unshift @INC, @{$self->incdir};
+ return;
+}
+
sub apply_script {
my ($self, $script, $warn_on_unreadable) = @_;