PerlAlien / App-af

Command line tool for alienfile
2 stars 0 forks source link

Add debug hooks for the install subcommand #1

Closed plicease closed 7 years ago

plicease commented 7 years ago

You should be able to call an arbitrary command before or after a hook using the install subcommand for testing. This way you can check the state right before or right after any of the hooks, in the correct directory for that stage.

Invocation should look something like this:

% af install --before build bash --after download 'ls -l'

This will run ls -l right after the download, and bash right before the build begins.

The methods $build->meta->after_hook and $build->meta->before_hook are undocumented as of this writing, but I intend on making them documented, supported methods in the near future. This could also be implemented using $build->meta->around_hook but my preference is to use after/before_hook.

On second thought this should be implemented with $build->meta->around_hook because we will need to be able to catch and rethrow exceptions that happen in the enclosing hook. Something like:

$meta->around_hook(
  $hook_name => sub {
    my($orig, @args) = @_;
    my $ret = eval { $orig->(@args) };
    my $error = $@;
    # execute command here
    die $error if $error;
    $ret;
  }
);

Actually I think for the before we can do the $build->meta->before_hook for simplicity.

plicease commented 7 years ago

https://metacpan.org/pod/Getopt::Long#Options-with-multiple-values