line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::GitHooks::Plugin::PerlCompile; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
2617354
|
use strict; |
|
17
|
|
|
|
|
28
|
|
|
17
|
|
|
|
|
401
|
|
4
|
17
|
|
|
17
|
|
53
|
use warnings; |
|
17
|
|
|
|
|
21
|
|
|
17
|
|
|
|
|
342
|
|
5
|
|
|
|
|
|
|
|
6
|
17
|
|
|
17
|
|
50
|
use base 'App::GitHooks::Plugin'; |
|
17
|
|
|
|
|
21
|
|
|
17
|
|
|
|
|
2565
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# External dependencies. |
9
|
17
|
|
|
17
|
|
1030
|
use File::Spec qw(); |
|
17
|
|
|
|
|
22
|
|
|
17
|
|
|
|
|
296
|
|
10
|
17
|
|
|
17
|
|
1774
|
use System::Command; |
|
17
|
|
|
|
|
57675
|
|
|
17
|
|
|
|
|
93
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Internal dependencies. |
13
|
17
|
|
|
17
|
|
1861
|
use App::GitHooks::Constants qw( :PLUGIN_RETURN_CODES ); |
|
17
|
|
|
|
|
10789
|
|
|
17
|
|
|
|
|
6649
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
App::GitHooks::Plugin::PerlCompile - Verify that Perl files compile without errors. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This plugin verifies that staged Perl files compile without errors before |
24
|
|
|
|
|
|
|
allowing the commit to be completed. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 VERSION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Version 1.1.1 |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our $VERSION = '1.1.1'; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 CONFIGURATION OPTIONS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
This plugin supports the following options in the C<[PerlCompile]> section of |
39
|
|
|
|
|
|
|
your C<.githooksrc> file. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
[PerlCompile] |
42
|
|
|
|
|
|
|
lib_paths = ./lib, ./t/lib |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 lib_paths |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
This option gives an opportunity to include other paths to Perl libraries, and |
48
|
|
|
|
|
|
|
in particular paths that are local to the current repository. It allows testing |
49
|
|
|
|
|
|
|
that the Perl files compile without having to amend PERL5LIB to include the |
50
|
|
|
|
|
|
|
repository-specific libraries. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
lib_paths = ./lib, ./t/lib |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 METHODS |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 get_file_pattern() |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Return a pattern to filter the files this plugin should analyze. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $file_pattern = App::GitHooks::Plugin::PerlCompile->get_file_pattern( |
62
|
|
|
|
|
|
|
app => $app, |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub get_file_pattern |
68
|
|
|
|
|
|
|
{ |
69
|
15
|
|
|
15
|
1
|
576292
|
return qr/\.(?:pl|pm|t|cgi)$/x; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 get_file_check_description() |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Return a description of the check performed on files by the plugin and that |
76
|
|
|
|
|
|
|
will be displayed to the user, if applicable, along with an indication of the |
77
|
|
|
|
|
|
|
success or failure of the plugin. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $description = App::GitHooks::Plugin::PerlCompile->get_file_check_description(); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub get_file_check_description |
84
|
|
|
|
|
|
|
{ |
85
|
13
|
|
|
13
|
1
|
8148
|
return 'The file passes perl -c'; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 run_pre_commit_file() |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Code to execute for each file as part of the pre-commit hook. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $success = App::GitHooks::Plugin::PerlCompile->run_pre_commit_file(); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub run_pre_commit_file |
98
|
|
|
|
|
|
|
{ |
99
|
6
|
|
|
6
|
1
|
5307
|
my ( $class, %args ) = @_; |
100
|
6
|
|
|
|
|
69
|
my $file = delete( $args{'file'} ); |
101
|
6
|
|
|
|
|
44
|
my $git_action = delete( $args{'git_action'} ); |
102
|
6
|
|
|
|
|
34
|
my $app = delete( $args{'app'} ); |
103
|
6
|
|
|
|
|
166
|
my $repository = $app->get_repository(); |
104
|
6
|
|
|
|
|
469
|
my $config = $app->get_config(); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Ignore deleted files. |
107
|
6
|
50
|
|
|
|
110
|
return $PLUGIN_RETURN_SKIPPED |
108
|
|
|
|
|
|
|
if $git_action eq 'D'; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Prepare extra libs specified in .githooksrc. |
111
|
6
|
|
|
|
|
148
|
my $lib_paths = $config->get( 'PerlCompile', 'lib_paths' ); |
112
|
6
|
|
50
|
|
|
286
|
my @lib = map { ( '-I', $_ ) } split( /\s*,\s*/, $lib_paths // '' ); |
|
0
|
|
|
|
|
0
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Execute perl -cw. |
115
|
6
|
|
|
|
|
125
|
my $path = File::Spec->catfile( $repository->work_tree(), $file ); |
116
|
6
|
|
|
|
|
420
|
my ( $pid, $stdin, $stdout, $stderr ) = System::Command->spawn( $^X, '-cw', @lib, $path ); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Retrieve the output. |
119
|
6
|
|
|
|
|
26846
|
my $output; |
120
|
|
|
|
|
|
|
{ |
121
|
6
|
|
|
|
|
13
|
local $/ = undef; |
|
6
|
|
|
|
|
24
|
|
122
|
6
|
|
|
|
|
12245
|
$output = <$stderr>; |
123
|
6
|
|
|
|
|
49
|
chomp( $output ); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# Raise an exception if we didn't get "syntax OK". |
127
|
6
|
100
|
|
|
|
538
|
die "$output\n" |
128
|
|
|
|
|
|
|
if $output !~ /\Q$file syntax OK\E$/x; |
129
|
|
|
|
|
|
|
|
130
|
1
|
|
|
|
|
33
|
return $PLUGIN_RETURN_PASSED; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 BUGS |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Please report any bugs or feature requests through the web interface at |
137
|
|
|
|
|
|
|
L. |
138
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
139
|
|
|
|
|
|
|
your bug as I make changes. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 SUPPORT |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
perldoc App::GitHooks::Plugin::PerlCompile |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
You can also look for information at: |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=over |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item * GitHub's request tracker |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
L |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
L |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item * CPAN Ratings |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
L |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item * MetaCPAN |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=back |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 AUTHOR |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L, |
175
|
|
|
|
|
|
|
C<< >>. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Copyright 2013-2016 Guillaume Aubert. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
This code is free software; you can redistribute it and/or modify it under the |
183
|
|
|
|
|
|
|
same terms as Perl 5 itself. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY |
186
|
|
|
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
187
|
|
|
|
|
|
|
PARTICULAR PURPOSE. See the LICENSE file for more details. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=cut |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; |