Skip to content

Commit

Permalink
@inc is now forwarded too
Browse files Browse the repository at this point in the history
  • Loading branch information
sirtoobii committed Feb 16, 2022
1 parent 1d2938d commit 7fcad83
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.0.3 2022-02-16 15:08:23 +0100 Tobias Bossert <tobib at cpan.org>
- Also forward includes to target mojo command

0.0.2 2022-02-11 12:52:26 +0100 Tobias Bossert <tobib at cpan.org>
- Repo updates
- Constrained dependency versions
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

![https://metacpan.org/pod/Mojolicious::Command::coverage](https://img.shields.io/cpan/v/Mojolicious-Command-coverage)

Start you Mojo app in coverage mode
Start you Mojo app in coverage mode. In short this command does the following:

```text
./myapp.pl coverage [application arguments]
# Is translated to
perl -I $INC[0] ... - I $INC[N] -MDevel::Cover=$coverageConfig -MDevel::Deanonymize=$deanonConfig myapp.pl [application arguments]
```

# SYNOPSIS

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.2
0.0.3
16 changes: 13 additions & 3 deletions lib/Mojolicious/Command/coverage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use warnings FATAL => 'all';
use Mojo::Base 'Mojolicious::Command', -signatures;
use Mojo::Util qw(getopt);

use Data::Dumper;

our $VERSION = "0.0.2"; # Do not update manually

# Short description
Expand Down Expand Up @@ -39,17 +41,20 @@ sub run($self, @args) {
$coverageConfig = $self->app->coverageConfig;
print "Command::coverage: Taking config from `$appName->coverageConfig` for Devel::Cover \n";
}
# We also have to forward @INC which may have been set-up with Findbin
my @Is = ('-I') x scalar @INC;
my @includes = map {($Is[$_], $INC[$_])} (0 .. $#INC); # this is basically zip(arr1,arr2) in other languages

# if there is no custom config, we fallback to default
$deanonConfig = $appName if $deanonConfig eq "";
$coverageConfig = "-ignore,t/,-coverage,statement,branch,condition,path,subroutine" if $coverageConfig eq "";

my @commandline_inject = ();
if ($deanonConfig ne "0") {
@commandline_inject = ('perl', "-MDevel::Cover=$coverageConfig", "-MDevel::Deanonymize=$deanonConfig", $0);
@commandline_inject = ('perl', @includes, "-MDevel::Cover=$coverageConfig", "-MDevel::Deanonymize=$deanonConfig", $0);
}
else {
@commandline_inject = ('perl', "-MDevel::Cover=$coverageConfig", $0);
@commandline_inject = ('perl', @includes, "-MDevel::Cover=$coverageConfig", $0);
}
# Merge with application arguments
my @full_commandline = (@commandline_inject, @orig_args[$n_args .. $#orig_args]);
Expand Down Expand Up @@ -84,7 +89,12 @@ Mojolicious::Command::coverage - Run your application with coverage statistics

=head1 DESCRIPTION
Starts your mojo application with L<Devel::Cover> and optionally L<Devel::Deanonymize>.
Starts your mojo application with L<Devel::Cover> and optionally L<Devel::Deanonymize>. In short this command does the following:
./myapp.pl coverage [application arguments]
# Is translated to
perl -I $INC[0] ... - I $INC[N] -MDevel::Cover=$coverageConfig -MDevel::Deanonymize=$deanonConfig myapp.pl [application arguments]
=cut

Expand Down

0 comments on commit 7fcad83

Please sign in to comment.