File Coverage

blib/lib/App/GitHooks/Plugin/ValidatePODFormat.pm
Criterion Covered Total %
statement 38 39 97.4
branch 5 8 62.5
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 54 58 93.1


line stmt bran cond sub pod time code
1             package App::GitHooks::Plugin::ValidatePODFormat;
2              
3 9     9   1360443 use strict;
  9         16  
  9         253  
4 9     9   34 use warnings;
  9         14  
  9         251  
5              
6 9     9   35 use base 'App::GitHooks::Plugin';
  9         16  
  9         2089  
7              
8             # External dependencies.
9 9     9   5929 use Pod::Simple;
  9         220977  
  9         342  
10              
11             # Internal dependencies.
12 9     9   1841 use App::GitHooks::Constants qw( :PLUGIN_RETURN_CODES );
  9         13151  
  9         4521  
13              
14              
15             =head1 NAME
16              
17             App::GitHooks::Plugin::ValidatePODFormat - Validate POD format in Perl and POD files.
18              
19              
20             =head1 DESCRIPTION
21              
22              
23             =head1 VERSION
24              
25             Version 1.1.0
26              
27             =cut
28              
29             our $VERSION = '1.1.0';
30              
31              
32             =head1 METHODS
33              
34             =head2 get_file_pattern()
35              
36             Return a pattern to filter the files this plugin should analyze.
37              
38             my $file_pattern = App::GitHooks::Plugin::ValidatePODFormat->get_file_pattern(
39             app => $app,
40             );
41              
42             =cut
43              
44             sub get_file_pattern
45             {
46 7     7 1 383848 return qr/\.(?:pl|pm|t|cgi|pod)$/x;
47             }
48              
49              
50             =head2 get_file_check_description()
51              
52             Return a description of the check performed on files by the plugin and that
53             will be displayed to the user, if applicable, along with an indication of the
54             success or failure of the plugin.
55              
56             my $description = App::GitHooks::Plugin::ValidatePODFormat->get_file_check_description();
57              
58             =cut
59              
60             sub get_file_check_description
61             {
62 7     7 1 5323 return 'POD format is valid.';
63             }
64              
65              
66             =head2 run_pre_commit_file()
67              
68             Code to execute for each file as part of the pre-commit hook.
69              
70             my $success = App::GitHooks::Plugin::ValidatePODFormat->run_pre_commit_file();
71              
72             =cut
73              
74             sub run_pre_commit_file
75             {
76 3     3 1 4463 my ( $class, %args ) = @_;
77 3         48 my $file = delete( $args{'file'} );
78 3         30 my $git_action = delete( $args{'git_action'} );
79 3         27 my $app = delete( $args{'app'} );
80 3         129 my $staged_changes = $app->get_staged_changes();
81 3         169 my $repository = $app->get_repository();
82              
83             # Ignore deleted files.
84 3 50       79 return $PLUGIN_RETURN_SKIPPED
85             if $git_action eq 'D';
86              
87             # Ignore revert commits.
88 3 50       101 return $PLUGIN_RETURN_SKIPPED
89             if $staged_changes->is_revert();
90              
91             # Run the POD checker.
92 3         262 my $checker = Pod::Simple->new();
93 3         520 $checker->output_string( \my $trash ); # Ignore any output
94 3         7506 $checker->parse_file( $file );
95              
96             # If the POD checker reports an error, investigate.
97 3 100       3239 if ( $checker->any_errata_seen() ) {
98             # Parse the errors.
99 1         11 my @formatted_errors = ();
100 1         5 my $lines = $checker->{errata};
101 1         11 foreach my $line ( sort { $a <=> $b } keys %$lines ) {
  0         0  
102 1         9 my $errors = $lines->{$line};
103 1         3 push( @formatted_errors, map { "Line $line: $_" } @$errors );
  1         8  
104             }
105              
106             # An error was reported but no specific error was found. This shouldn't
107             # happen.
108 1 50       5 die "POD parsing failed, but no specific error could be reported.\n"
109             if scalar( @formatted_errors ) == 0;
110              
111 1         52 die join( "\n", @formatted_errors ), "\n";
112             }
113              
114 2         97 return $PLUGIN_RETURN_PASSED;
115             }
116              
117              
118             =head1 BUGS
119              
120             Please report any bugs or feature requests through the web interface at
121             L.
122             I will be notified, and then you'll automatically be notified of progress on
123             your bug as I make changes.
124              
125              
126             =head1 SUPPORT
127              
128             You can find documentation for this module with the perldoc command.
129              
130             perldoc App::GitHooks::ValidatePODFormat
131              
132              
133             You can also look for information at:
134              
135             =over
136              
137             =item * GitHub's request tracker
138              
139             L
140              
141             =item * AnnoCPAN: Annotated CPAN documentation
142              
143             L
144              
145             =item * CPAN Ratings
146              
147             L
148              
149             =item * MetaCPAN
150              
151             L
152              
153             =back
154              
155              
156             =head1 AUTHOR
157              
158             L,
159             C<< >>.
160              
161              
162             =head1 COPYRIGHT & LICENSE
163              
164             Copyright 2013-2017 Guillaume Aubert.
165              
166             This code is free software; you can redistribute it and/or modify it under the
167             same terms as Perl 5 itself.
168              
169             This program is distributed in the hope that it will be useful, but WITHOUT ANY
170             WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
171             PARTICULAR PURPOSE. See the LICENSE file for more details.
172              
173             =cut
174              
175             1;