| 1 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | # ABSTRACT: An interactive shell to run Dist::Zilla commands | ||
| 4 | package Dist::Zilla::App::Command::shell; | ||
| 5 | { | ||
| 6 | $Dist::Zilla::App::Command::shell::VERSION = '0.005'; | ||
| 7 | } | ||
| 8 | |||
| 9 | 0 | ▶ | use Dist::Zilla::App -command; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | |||
| 11 | sub abstract { "open an interactive shell to run other DZ commands" } | ||
| 12 | |||
| 13 | sub execute | ||
| 14 | { | ||
| 15 | my $self = shift; | ||
| 16 | |||
| 17 | # Get the list of commands | ||
| 18 | my %builtins = map { ($_ => 1) } $self->app->command_names; | ||
| 19 | my $app_class = ref($self->app); | ||
| 20 | |||
| 21 | require Term::ReadLine; | ||
| 22 | require Text::ParseWords; | ||
| 23 | |||
| 24 | my $term = Term::ReadLine->new('Dist::Zilla shell'); | ||
| 25 | my $prompt = 'DZ> '; | ||
| 26 | |||
| 27 | while (1) { | ||
| 28 | my $line = $term->readline($prompt); | ||
| 29 | |||
| 30 | local @ARGV = Text::ParseWords::shellwords($line); | ||
| 31 | next unless @ARGV; | ||
| 32 | last if $ARGV[0] =~ /\A(?:exit|x|quit|q)\z/; | ||
| 33 | |||
| 34 | if (exists $builtins{$ARGV[0]}) { | ||
| 35 | local $@; | ||
| 36 | eval { $app_class->run(@ARGV) }; | ||
| 37 | print STDERR $@ if $@; | ||
| 38 | } else { | ||
| 39 | # Pass the line as-is to the shell | ||
| 40 | system $line; | ||
| 41 | } | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | 1; | ||
| 46 | __END__ | ||