File Coverage

blib/lib/App/GitHooks/Plugin/Test/PrintSTDERR.pm
Criterion Covered Total %
statement 27 27 100.0
branch 1 2 50.0
condition 1 2 50.0
subroutine 9 9 100.0
pod 2 2 100.0
total 40 42 95.2


line stmt bran cond sub pod time code
1             package App::GitHooks::Plugin::Test::PrintSTDERR;
2              
3 23     23   69085 use strict;
  23         36  
  23         520  
4 23     23   69 use warnings;
  23         25  
  23         453  
5              
6 23     23   65 use base 'App::GitHooks::Plugin';
  23         21  
  23         2185  
7              
8             # External dependencies.
9 23     23   80 use Carp;
  23         21  
  23         1063  
10              
11             # Internal dependencies.
12 23     23   1282 use App::GitHooks::Constants qw( :PLUGIN_RETURN_CODES );
  23         23  
  23         3856  
13              
14              
15             =head1 NAME
16              
17             App::GitHooks::Plugin::Test::PrintSTDERR - A test plugin that allows printing a specific string to STDERR.
18              
19              
20             =head1 DESCRIPTION
21              
22              
23             =head1 SYNOPSIS
24              
25             use App::GitHooks::Plugin::Test::PrintSTDERR;
26              
27             # In .githooksrc.
28             # [Test::PrintSTDERR]
29             # pre-commit = Triggered a pre-commit plugin!
30             # prepare-commit-msg = Triggered a prepare-commit-msg plugin!
31              
32             # Run hooks calling the plugin.
33              
34              
35             =head1 VERSION
36              
37             Version 1.8.0
38              
39             =cut
40              
41             our $VERSION = '1.8.0';
42              
43             our $HOOK_REPLIES;
44              
45              
46             =head1 METHODS
47              
48             =head2 get_file_pattern()
49              
50             Return a pattern to filter the files this plugin should analyze.
51              
52             my $file_pattern = App::GitHooks::Plugin::Test::PrintSTDERR->get_file_pattern(
53             app => $app,
54             );
55              
56             =cut
57              
58             sub get_file_pattern
59             {
60 1     1 1 4150 return qr//x;
61             }
62              
63              
64             =head2 get_file_check_description()
65              
66             Return a description of the check performed on files by the plugin and that
67             will be displayed to the user, if applicable, along with an indication of the
68             success or failure of the plugin.
69              
70             my $description = App::GitHooks::Plugin::Test::PrintSTDERR->get_file_check_description();
71              
72             =cut
73              
74             sub get_file_check_description
75             {
76 1     1 1 2992 return 'Test plugin - print on STDERR.';
77             }
78              
79              
80             =head1 SUPPORTED HOOKS
81              
82             This plugin supports all the hooks defined in C,
83             including file-level checks for the appropriate hooks.
84              
85             =over 4
86              
87             =item run_applypatch_msg
88              
89             =item run_commit_msg
90              
91             =item run_post_applypatch
92              
93             =item run_post_checkout
94              
95             =item run_post_commit
96              
97             =item run_post_merge
98              
99             =item run_post_receive
100              
101             =item run_post_rewrite
102              
103             =item run_post_update
104              
105             =item run_pre_applypatch
106              
107             =item run_pre_auto_gc
108              
109             =item run_pre_commit
110              
111             =item run_pre_commit_file
112              
113             =item run_pre_push
114              
115             =item run_pre_rebase
116              
117             =item run_pre_receive
118              
119             =item run_prepare_commit_msg
120              
121             =item run_update
122              
123             =back
124              
125             =cut
126              
127             foreach my $hook ( @$App::GitHooks::Plugin::SUPPORTED_SUBS )
128             {
129 23     23   90 no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNoStrict)
  23         22  
  23         3109  
130             my $sub = 'run_' . $hook;
131             *$sub = sub
132             {
133 2     2   5 my ( $class, %args ) = @_;
134 2         4 my $app = delete( $args{'app'} );
135 2         4 my $config = $app->get_config();
136              
137 2   50     5 my $return = $config->get( 'Test::PrintSTDERR', $hook ) // '';
138 2 50       8 croak "No test to print on STDERR specified for >$hook<."
139             if $return !~ /\w/;
140 2         23 print STDERR "$return\n";
141              
142 2         6 return $PLUGIN_RETURN_PASSED;
143             };
144             }
145              
146              
147             =head1 BUGS
148              
149             Please report any bugs or feature requests through the web interface at
150             L.
151             I will be notified, and then you'll automatically be notified of progress on
152             your bug as I make changes.
153              
154              
155             =head1 SUPPORT
156              
157             You can find documentation for this module with the perldoc command.
158              
159             perldoc App::GitHooks::Plugin::Test::PrintSTDERR
160              
161              
162             You can also look for information at:
163              
164             =over
165              
166             =item * GitHub's request tracker
167              
168             L
169              
170             =item * AnnoCPAN: Annotated CPAN documentation
171              
172             L
173              
174             =item * CPAN Ratings
175              
176             L
177              
178             =item * MetaCPAN
179              
180             L
181              
182             =back
183              
184              
185             =head1 AUTHOR
186              
187             L,
188             C<< >>.
189              
190              
191             =head1 COPYRIGHT & LICENSE
192              
193             Copyright 2013-2016 Guillaume Aubert.
194              
195             This code is free software; you can redistribute it and/or modify it under the
196             same terms as Perl 5 itself.
197              
198             This program is distributed in the hope that it will be useful, but WITHOUT ANY
199             WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
200             PARTICULAR PURPOSE. See the LICENSE file for more details.
201              
202             =cut
203              
204             1;