Skip to content

Commit 573e185

Browse files
authored
Merge pull request #5 from nunorc/pr/verbose
Pr/verbose
2 parents db10307 + 95d28ff commit 573e185

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

bin/p5stack

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,14 @@ use App::p5stack;
1010
my $app = App::p5stack->new(@ARGV);
1111
$app->run();
1212

13+
=head1 Options
14+
15+
=over 4
16+
17+
=item C<-D>
18+
19+
Activates debug mode. Dump configuration varibles, and some other useful debug information.
20+
21+
=back
22+
23+
=cut

lib/App/p5stack.pm

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,55 @@ sub new {
1818
my ($class, @argv) = @_;
1919
my $self = bless {}, $class;
2020

21-
$self->{orig_argv} = [@argv];
21+
$self->{orig_argv} = [ @argv ];
22+
23+
## treat flags only if before the "command"
24+
while (@argv && $argv[0] =~ /^-/) {
25+
$self->_activate_flag(shift @argv)
26+
}
27+
2228
$self->{command} = @argv ? lc shift @argv : '';
23-
$self->{argv} = [@argv];
2429

30+
$self->{argv} = [ @argv ];
31+
2532
# handle config
2633
$self->_do_config;
27-
34+
$self->_dump_config if $self->{debug};
35+
2836
return $self;
2937
}
3038

39+
sub _activate_flag {
40+
my ($self, $flag) = @_;
41+
if ($flag eq "-D") { $self->{debug} = 1; }
42+
# FIXME: complin on unknown flags?
43+
}
44+
3145
sub run {
3246
my ($self) = @_;
3347

34-
if ($self->{command} eq 'setup') { $self->_do_setup; }
35-
elsif ($self->{command} eq 'perl') { $self->_do_perl; }
48+
if ($self->{command} eq 'setup') { $self->_do_setup; }
49+
elsif ($self->{command} eq 'perl') { $self->_do_perl; }
3650
elsif ($self->{command} eq 'cpanm') { $self->_do_cpanm; }
37-
elsif ($self->{command} eq 'bin') { $self->_do_bin; }
38-
elsif ($self->{command} eq 'run') { $self->_do_run; }
51+
elsif ($self->{command} eq 'bin') { $self->_do_bin; }
52+
elsif ($self->{command} eq 'run') { $self->_do_run; }
3953
else { $self->_do_help; }
4054
}
4155

56+
sub _dump_config {
57+
my ($self) = @_;
58+
print STDERR Dumper($self);
59+
}
60+
4261
sub _do_config {
4362
my ($self) = @_;
4463

4564
# set some defaults
4665
$self->{perl} = 'system';
4766
$self->{deps} = 'dzil';
4867
$self->{skip_install} = 1;
49-
$self->{p5stack_root} = catfile($ENV{HOME},'.p5stack');
50-
$self->{perls_root} = catfile($ENV{HOME},'.p5stack','perls');
68+
$self->{p5stack_root} = catfile($ENV{HOME}, '.p5stack');
69+
$self->{perls_root} = catfile($ENV{HOME}, '.p5stack', 'perls');
5170
$self->{perl_version} = '5.20.3';
5271

5372
# guess stuff from context
@@ -196,9 +215,10 @@ sub _do_install_perl_release {
196215
sub _do_perl {
197216
my ($self) = @_;
198217

199-
my $run = join(' ',$self->{perl}, "-I $self->{Ilib}",
200-
"-Mlocal::lib", @{$self->{argv}});
218+
my $run = join(' ',$self->{perl}, "-I$self->{Ilib}",
219+
"-Mlocal::lib=$self->{local_lib}", @{$self->{argv}});
201220

221+
print STDERR "Running: $run\n" if $self->{debug};
202222
system $run;
203223
}
204224

0 commit comments

Comments
 (0)