| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::GitHooks::Hook; |
|
2
|
|
|
|
|
|
|
|
|
3
|
23
|
|
|
23
|
|
14860
|
use strict; |
|
|
23
|
|
|
|
|
25
|
|
|
|
23
|
|
|
|
|
513
|
|
|
4
|
23
|
|
|
23
|
|
64
|
use warnings; |
|
|
23
|
|
|
|
|
23
|
|
|
|
23
|
|
|
|
|
417
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# External dependencies. |
|
7
|
23
|
|
|
23
|
|
64
|
use Carp; |
|
|
23
|
|
|
|
|
25
|
|
|
|
23
|
|
|
|
|
1224
|
|
|
8
|
23
|
|
|
23
|
|
2200
|
use Try::Tiny; |
|
|
23
|
|
|
|
|
4794
|
|
|
|
23
|
|
|
|
|
999
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Internal dependencies. |
|
11
|
23
|
|
|
23
|
|
1341
|
use App::GitHooks::Constants qw( :HOOK_EXIT_CODES :PLUGIN_RETURN_CODES ); |
|
|
23
|
|
|
|
|
26
|
|
|
|
23
|
|
|
|
|
8427
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
App::GitHooks::Hook - Base class for all git hook handlers. |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 VERSION |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Version 1.8.0 |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = '1.8.0'; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 METHODS |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 run() |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Run the hook handler and return an exit status to pass to git. |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $exit_status = App::GitHooks::Hook->run( |
|
35
|
|
|
|
|
|
|
app => $app, |
|
36
|
|
|
|
|
|
|
); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Arguments: |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=over 4 |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item * app I<(mandatory)> |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
An L object. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item * stdin I<(optional)> |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
An arrayref of lines retrieved from SDTIN. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
See for example the C hook for uses of this argument. |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=back |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub run |
|
57
|
|
|
|
|
|
|
{ |
|
58
|
3
|
|
|
3
|
1
|
39
|
my ( $class, %args ) = @_; |
|
59
|
3
|
|
|
|
|
5
|
my $app = $args{'app'}; |
|
60
|
3
|
|
|
|
|
4
|
my $stdin = $args{'stdin'}; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Find all the plugins that are applicable for this hook. |
|
63
|
3
|
|
|
|
|
11
|
my $plugins = $app->get_hook_plugins( $app->get_hook_name() ); |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Run all the plugins. |
|
66
|
3
|
|
|
|
|
4
|
my $has_errors = 0; |
|
67
|
3
|
|
|
|
|
6
|
foreach my $plugin ( @$plugins ) |
|
68
|
|
|
|
|
|
|
{ |
|
69
|
|
|
|
|
|
|
# Since Perl doesn't allow dashes in method names but git hook names have |
|
70
|
|
|
|
|
|
|
# dashes, we need to make sure we convert dashes to underscores when |
|
71
|
|
|
|
|
|
|
# generating the method name to run. |
|
72
|
2
|
|
|
|
|
6
|
my $method = 'run_' . $app->get_hook_name(); |
|
73
|
2
|
|
|
|
|
6
|
$method =~ s/-/_/g; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Run the plugin method corresponding to this hook. |
|
76
|
|
|
|
|
|
|
# If the plugin throws an exception, print the error message and consider |
|
77
|
|
|
|
|
|
|
# the return code to be a failure. |
|
78
|
|
|
|
|
|
|
my $return_code = try |
|
79
|
|
|
|
|
|
|
{ |
|
80
|
2
|
|
|
2
|
|
53
|
return $plugin->$method( |
|
81
|
|
|
|
|
|
|
app => $app, |
|
82
|
|
|
|
|
|
|
stdin => $stdin, |
|
83
|
|
|
|
|
|
|
); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
catch |
|
86
|
|
|
|
|
|
|
{ |
|
87
|
1
|
|
|
1
|
|
14
|
chomp( $_ ); |
|
88
|
1
|
|
|
|
|
4
|
my $failure_character = $app->get_failure_character(); |
|
89
|
1
|
|
|
|
|
6
|
print $app->color( 'red', "$failure_character $_\n" ); |
|
90
|
1
|
|
|
|
|
4
|
return $PLUGIN_RETURN_FAILED; |
|
91
|
2
|
|
|
|
|
14
|
}; |
|
92
|
|
|
|
|
|
|
|
|
93
|
2
|
100
|
|
|
|
21
|
$has_errors = 1 |
|
94
|
|
|
|
|
|
|
if $return_code == $PLUGIN_RETURN_FAILED; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Return an exit code for Git. |
|
98
|
3
|
100
|
|
|
|
18
|
return $has_errors |
|
99
|
|
|
|
|
|
|
? $HOOK_EXIT_FAILURE |
|
100
|
|
|
|
|
|
|
: $HOOK_EXIT_SUCCESS; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 BUGS |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Please report any bugs or feature requests through the web interface at |
|
107
|
|
|
|
|
|
|
L. |
|
108
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
|
109
|
|
|
|
|
|
|
your bug as I make changes. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 SUPPORT |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
perldoc App::GitHooks::Hook |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
You can also look for information at: |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=over |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item * GitHub's request tracker |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
L |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item * MetaCPAN |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=back |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 AUTHOR |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
L, |
|
145
|
|
|
|
|
|
|
C<< >>. |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Copyright 2013-2016 Guillaume Aubert. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This code is free software; you can redistribute it and/or modify it under the |
|
153
|
|
|
|
|
|
|
same terms as Perl 5 itself. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY |
|
156
|
|
|
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
|
157
|
|
|
|
|
|
|
PARTICULAR PURPOSE. See the LICENSE file for more details. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |