line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
13570
|
use 5.006; |
|
2
|
|
|
|
|
6
|
|
2
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
35
|
|
3
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
117
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Dist::Zilla::Util::CurrentCmd; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.002003'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Attempt to determine the current command Dist::Zilla is running under. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
965
|
use Moose; |
|
2
|
|
|
|
|
588203
|
|
|
2
|
|
|
|
|
11
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
9399
|
use Sub::Exporter '-setup' => { exports => [qw( current_cmd is_build is_install as_cmd )], }; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
19
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our $_FORCE_CMD; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub current_cmd { |
33
|
10
|
|
|
10
|
1
|
1214
|
my $i = 0; |
34
|
10
|
100
|
|
|
|
19
|
if ($_FORCE_CMD) { |
35
|
5
|
|
|
|
|
15
|
return $_FORCE_CMD; |
36
|
|
|
|
|
|
|
} |
37
|
5
|
|
|
|
|
40
|
while ( my @frame = caller $i ) { |
38
|
32
|
|
|
|
|
21
|
$i++; |
39
|
32
|
50
|
|
|
|
146
|
next unless ( my ( $command, ) = $frame[3] =~ /\ADist::Zilla::App::Command::(.*)::([^:\s]+)\z/msx ); |
40
|
0
|
|
|
|
|
0
|
return $command; |
41
|
|
|
|
|
|
|
} |
42
|
5
|
|
|
|
|
13
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub is_build { |
52
|
2
|
|
|
2
|
1
|
5
|
my $cmd = current_cmd(); |
53
|
2
|
|
66
|
|
|
15
|
return ( defined $cmd and 'build' eq $cmd ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub is_install { |
63
|
2
|
|
|
2
|
1
|
5
|
my $cmd = current_cmd(); |
64
|
2
|
|
66
|
|
|
15
|
return ( defined $cmd and 'install' eq $cmd ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub as_cmd { |
80
|
3
|
|
|
3
|
1
|
1506
|
my ( $cmd, $callback ) = @_; |
81
|
|
|
|
|
|
|
## no critic ( Variables::ProhibitLocalVars ) |
82
|
3
|
|
|
|
|
7
|
local $_FORCE_CMD = $cmd; |
83
|
3
|
|
|
|
|
5
|
return $callback->(); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
87
|
2
|
|
|
2
|
|
953
|
no Moose; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=pod |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=encoding UTF-8 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 NAME |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Dist::Zilla::Util::CurrentCmd - Attempt to determine the current command Dist::Zilla is running under. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 VERSION |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
version 0.002003 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 SYNOPSIS |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
use Dist::Zilla::Util::CurrentCmd qw(current_cmd); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
... |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
if ( is_install() ) { |
112
|
|
|
|
|
|
|
die "This plugin hates installing things for some reason!" |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
if ( is_build() ) { |
115
|
|
|
|
|
|
|
print "I Love you man\n"; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
if ( current_cmd() eq 'run' ) { |
118
|
|
|
|
|
|
|
die "RUN THE OTHER WAY" |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 DESCRIPTION |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This module exists in case you are absolutely certain you want to have different behaviors for either a plugin, or a bundle, to |
124
|
|
|
|
|
|
|
trigger on ( or off ) a specific phase. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Usually, this is a bad idea, and the need to do this suggests a poor choice of work-flow to begin with. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
That said, this utility is I<probably> more useful in a bundle than in a plugin, in that it will be slightly more optimal than |
129
|
|
|
|
|
|
|
say, having an C<ENV> flag to control this difference. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 FUNCTIONS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 C<current_cmd> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Returns the name of the of the B<first> C<command> entry in the C<caller> stack that matches |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
/\ADist::Zilla::App::Command::(.*)::([^:\s]+)\z/msx |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
For instance: |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Dist::Zilla::App::Command::build::execute -> |
142
|
|
|
|
|
|
|
build |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 C<is_build> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Convenience shorthand for C<current_cmd() eq 'build'> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 C<is_install> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Convenience shorthand for C<current_cmd() eq 'install'> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 C<as_cmd> |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Internals wrapper to lie to code operating in the callback that the C<current_cmd> is. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
as_cmd('install' => sub { |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
is_install(); # true |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
}); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 CAVEATS |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
User beware, this code is both hackish and new, and relies on using C<caller> to determine which |
165
|
|
|
|
|
|
|
C<Dist::Zilla::App::Command::> we are running under. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
There may be conditions that there are no C<Command>s in the C<caller> stack which meet this definition, or the I<first> such |
168
|
|
|
|
|
|
|
thing may be a misleading representation of what is actually running. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
And there's a degree of uncertainty of reliability, because I haven't yet devised reliable ways of testing it that don't |
171
|
|
|
|
|
|
|
involve invoking C<dzil> ( which is problematic on testers where C<Dist::Zilla> is in C<@INC> but C<dzil> is not in |
172
|
|
|
|
|
|
|
C<ENV{PATH}> ) |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
To that extent, I don't even know for sure if this module works yet, or if it works in a bundle, or if it works in all |
175
|
|
|
|
|
|
|
commands, or if it works under C<Dist::Zilla::App::Tester> as expected. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 AUTHOR |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Kent Fredric <kentnl@cpan.org> |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
186
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |