File Coverage

blib/lib/Dist/Zilla/App/Command/run.pm
Criterion Covered Total %
statement 6 18 33.3
branch 0 6 0.0
condition n/a
subroutine 2 7 28.5
pod 5 5 100.0
total 13 36 36.1


line stmt bran cond sub pod time code
1             package Dist::Zilla::App::Command::run 6.030;
2             # ABSTRACT: run stuff in a dir where your dist is built
3              
4 4     4   2598 use Dist::Zilla::Pragmas;
  4         11  
  4         25  
5              
6 4     4   32 use Dist::Zilla::App -command;
  4         8  
  4         71  
7              
8             #pod =head1 SYNOPSIS
9             #pod
10             #pod $ dzil run ./bin/myscript
11             #pod $ dzil run prove -bv t/mytest.t
12             #pod $ dzil run bash
13             #pod
14             #pod =head1 DESCRIPTION
15             #pod
16             #pod This command will build your dist with Dist::Zilla, then build the
17             #pod distribution and then run a command in the build directory. It's something
18             #pod like doing this:
19             #pod
20             #pod dzil build
21             #pod rsync -avp My-Project-version/ .build/
22             #pod cd .build
23             #pod perl Makefile.PL # or perl Build.PL
24             #pod make # or ./Build
25             #pod export PERL5LIB=$PWD/blib/lib:$PWD/blib/arch
26             #pod <your command as defined by rest of params>
27             #pod
28             #pod Except for the fact it's built directly in a subdir of .build (like
29             #pod F<.build/69105y2>).
30             #pod
31             #pod A command returning with an non-zero error code will left the build directory
32             #pod behind for analysis, and C<dzil> will exit with a non-zero status. Otherwise,
33             #pod the build directory will be removed and dzil will exit with status zero.
34             #pod
35             #pod If no run command is provided, a new default shell is invoked. This can be
36             #pod useful for testing your distribution as if it were installed.
37             #pod
38             #pod =cut
39              
40 0     0 1   sub abstract { 'run stuff in a dir where your dist is built' }
41              
42             sub opt_spec {
43 0     0 1   [ 'build!' => 'do the Build actions before running the command; done by default',
44             { default => 1 } ],
45             [ 'trial' => 'build a trial release that PAUSE will not index' ],
46             }
47              
48             sub description {
49 0     0 1   "This will build your dist and run the given 'command' in the build dir.\n" .
50             "If no command was specified, your shell will be run there instead."
51             }
52              
53             sub usage_desc {
54 0     0 1   return '%c run %o [ command [ arg1 arg2 ... ] ]';
55             }
56              
57             sub execute {
58 0     0 1   my ($self, $opt, $args) = @_;
59              
60 0 0         unless (@$args) {
61 0 0         my $envname = $^O eq 'MSWin32' ? 'COMSPEC' : 'SHELL';
62 0 0         unless ($ENV{$envname}) {
63 0           $self->usage_error("no command supplied to run and no \$$envname set");
64             }
65 0           $args = [ $ENV{$envname} ];
66 0           $self->log("no command supplied to run so using \$$envname: $args->[0]");
67             }
68              
69 0           $self->zilla->run_in_build($args, { build => $opt->build, trial => $opt->trial });
70             }
71              
72             1;
73              
74             __END__
75              
76             =pod
77              
78             =encoding UTF-8
79              
80             =head1 NAME
81              
82             Dist::Zilla::App::Command::run - run stuff in a dir where your dist is built
83              
84             =head1 VERSION
85              
86             version 6.030
87              
88             =head1 SYNOPSIS
89              
90             $ dzil run ./bin/myscript
91             $ dzil run prove -bv t/mytest.t
92             $ dzil run bash
93              
94             =head1 DESCRIPTION
95              
96             This command will build your dist with Dist::Zilla, then build the
97             distribution and then run a command in the build directory. It's something
98             like doing this:
99              
100             dzil build
101             rsync -avp My-Project-version/ .build/
102             cd .build
103             perl Makefile.PL # or perl Build.PL
104             make # or ./Build
105             export PERL5LIB=$PWD/blib/lib:$PWD/blib/arch
106             <your command as defined by rest of params>
107              
108             Except for the fact it's built directly in a subdir of .build (like
109             F<.build/69105y2>).
110              
111             A command returning with an non-zero error code will left the build directory
112             behind for analysis, and C<dzil> will exit with a non-zero status. Otherwise,
113             the build directory will be removed and dzil will exit with status zero.
114              
115             If no run command is provided, a new default shell is invoked. This can be
116             useful for testing your distribution as if it were installed.
117              
118             =head1 PERL VERSION
119              
120             This module should work on any version of perl still receiving updates from
121             the Perl 5 Porters. This means it should work on any version of perl released
122             in the last two to three years. (That is, if the most recently released
123             version is v5.40, then this module should work on both v5.40 and v5.38.)
124              
125             Although it may work on older versions of perl, no guarantee is made that the
126             minimum required version will not be increased. The version may be increased
127             for any reason, and there is no promise that patches will be accepted to lower
128             the minimum required perl.
129              
130             =head1 AUTHOR
131              
132             Ricardo SIGNES 😏 <cpan@semiotic.systems>
133              
134             =head1 COPYRIGHT AND LICENSE
135              
136             This software is copyright (c) 2023 by Ricardo SIGNES.
137              
138             This is free software; you can redistribute it and/or modify it under
139             the same terms as the Perl 5 programming language system itself.
140              
141             =cut