blib/lib/App/GitHooks/Hook.pm

filter: Statementstmt 100% 33 / 33 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 100% 46 / 46 CC 4 SCAR 7.4
CC
4
Cov
100%
run
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.1
« blib/lib/App/GitHooks/Plugin.pm ↑ Summary blib/lib/App/GitHooks/Plugin/Test/CustomReply.pm »
1 package App::GitHooks::Hook;
2  
3 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 23 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # External dependencies.
7 23 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 23 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Internal dependencies.
11 23 ▶use App::GitHooks::Constants qw( :HOOK_EXIT_CODES :PLUGIN_RETURN_CODES );
Subroutine BEGIN: called CC=1 SCAR=0.0
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.7.3
22  
23 =cut
24  
25 23 our $VERSION = '1.7.3';
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<App::GitHooks> object.
45  
46 =item * stdin I<(optional)>
47  
48 An arrayref of lines retrieved from SDTIN.
49  
50 See for example the C<pre-push> hook for uses of this argument.
51  
52 =back
53  
54 =cut
55  
56 sub run
57 {
58 3 ▶ my ( $class, %args ) = @_;
Subroutine run: called CC=4 SCAR=13.9
Pod documented
59 3 my $app = $args{'app'};
60 3 my $stdin = $args{'stdin'};
61  
62 # Find all the plugins that are applicable for this hook.
63 3 my $plugins = $app->get_hook_plugins( $app->get_hook_name() );
64  
65 # Run all the plugins.
66 3 my $has_errors = 0;
67 3 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 my $method = 'run_' . $app->get_hook_name();
73 2 $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 ▶ return $plugin->$method(
Subroutine __ANON__: called CC=1 SCAR=0.0
81 app => $app,
82 stdin => $stdin,
83 );
84 }
85 catch
86 {
87 1 ▶ chomp( $_ );
Subroutine __ANON__: called CC=1 SCAR=0.0
88 1 my $failure_character = $app->get_failure_character();
89 1 print $app->color( 'red', "$failure_character $_\n" );
90 1 return $PLUGIN_RETURN_FAILED;
91 2 };
92  
93 2 ▶ $has_errors = 1
Branch: 1 branch
BranchTrueFalseTotal
if $return_code == $App::GitHooks::Hook::PLUGIN_RETURN_FAILED 1 1 2
94 if $return_code == $PLUGIN_RETURN_FAILED;
95 }
96  
97 # Return an exit code for Git.
98 3 ▶ return $has_errors
Branch: 1 branch
BranchTrueFalseTotal
$has_errors ? : 1 2 3
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<https://github.com/guillaumeaubert/App-GitHooks/issues/new>.
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<https://github.com/guillaumeaubert/App-GitHooks/issues>
126  
127 =item * AnnoCPAN: Annotated CPAN documentation
128  
129 L<http://annocpan.org/dist/app-githooks>
130  
131 =item * CPAN Ratings
132  
133 L<http://cpanratings.perl.org/d/app-githooks>
134  
135 =item * MetaCPAN
136  
137 L<https://metacpan.org/release/App-GitHooks>
138  
139 =back
140  
141  
142 =head1 AUTHOR
143  
144 L<Guillaume Aubert|https://metacpan.org/author/AUBERTG>,
145 C<< <aubertg at cpan.org> >>.
146  
147  
148 =head1 COPYRIGHT & LICENSE
149  
150 Copyright 2013-2015 Guillaume Aubert.
151  
152 This program is free software: you can redistribute it and/or modify it under
153 the terms of the GNU General Public License version 3 as published by the Free
154 Software Foundation.
155  
156 This program is distributed in the hope that it will be useful, but WITHOUT ANY
157 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
158 PARTICULAR PURPOSE. See the GNU General Public License for more details.
159  
160 You should have received a copy of the GNU General Public License along with
161 this program. If not, see http://www.gnu.org/licenses/
162  
163 =cut
164  
165 23 1;
« blib/lib/App/GitHooks/Plugin.pm ↑ Summary blib/lib/App/GitHooks/Plugin/Test/CustomReply.pm »