| 1 | package App::GitHooks::Plugin::ValidatePODFormat; | ||||||||||
| 2 | |||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 9 | ▶ | use base 'App::GitHooks::Plugin'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | # External dependencies. | ||||||||||
| 9 | 9 | ▶ | use Pod::Simple; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | # Internal dependencies. | ||||||||||
| 12 | 9 | ▶ | use App::GitHooks::Constants qw( :PLUGIN_RETURN_CODES ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 9 | 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 | 7 | ▶ | { | ||||||||
|
Subroutine
get_file_pattern: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 46 | 7 | 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 | 7 | ▶ | { | ||||||||
|
Subroutine
get_file_check_description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 62 | 7 | 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 | 3 | ▶ | { | ||||||||
|
Subroutine
run_pre_commit_file: called CC=6 SCAR=22.7
Pod
documented
| |||||||||||
| 76 | 3 | my ( $class, %args ) = @_; | |||||||||
| 77 | 3 | my $file = delete( $args{'file'} ); | |||||||||
| 78 | 3 | my $git_action = delete( $args{'git_action'} ); | |||||||||
| 79 | 3 | my $app = delete( $args{'app'} ); | |||||||||
| 80 | 3 | my $staged_changes = $app->get_staged_changes(); | |||||||||
| 81 | 3 | my $repository = $app->get_repository(); | |||||||||
| 82 | |||||||||||
| 83 | # Ignore deleted files. | ||||||||||
| 84 | 3 | ▶ | return $PLUGIN_RETURN_SKIPPED | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | if $git_action eq 'D'; | ||||||||||
| 86 | |||||||||||
| 87 | # Ignore revert commits. | ||||||||||
| 88 | 3 | ▶ | return $PLUGIN_RETURN_SKIPPED | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | if $staged_changes->is_revert(); | ||||||||||
| 90 | |||||||||||
| 91 | # Run the POD checker. | ||||||||||
| 92 | 3 | my $checker = Pod::Simple->new(); | |||||||||
| 93 | 3 | $checker->output_string( \my $trash ); # Ignore any output | |||||||||
| 94 | 3 | $checker->parse_file( $file ); | |||||||||
| 95 | |||||||||||
| 96 | # If the POD checker reports an error, investigate. | ||||||||||
| 97 | 3 | ▶ | if ( $checker->any_errata_seen() ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | # Parse the errors. | ||||||||||
| 99 | 0 | my @formatted_errors = (); | |||||||||
| 100 | 0 | my $lines = $checker->{errata}; | |||||||||
| 101 | 0 | foreach my $line ( sort { $a <=> $b } keys %$lines ) { | |||||||||
| 102 | 0 | my $errors = $lines->{$line}; | |||||||||
| 103 | 0 | push( @formatted_errors, map { "Line $line: $_" } @$errors ); | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | # An error was reported but no specific error was found. This shouldn't | ||||||||||
| 107 | # happen. | ||||||||||
| 108 | 0 | ▶ | die "POD parsing failed, but no specific error could be reported.\n" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | if scalar( @formatted_errors ) == 0; | ||||||||||
| 110 | |||||||||||
| 111 | 0 | die join( "\n", @formatted_errors ), "\n"; | |||||||||
| 112 | } | ||||||||||
| 113 | |||||||||||
| 114 | 3 | 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<https://github.com/guillaumeaubert/App-GitHooks-Plugin-ValidatePODFormat/issues/new>. | ||||||||||
| 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<https://github.com/guillaumeaubert/App-GitHooks-Plugin-ValidatePODFormat/issues> | ||||||||||
| 140 | |||||||||||
| 141 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 142 | |||||||||||
| 143 | L<http://annocpan.org/dist/app-githooks-plugin-validatepodformat> | ||||||||||
| 144 | |||||||||||
| 145 | =item * CPAN Ratings | ||||||||||
| 146 | |||||||||||
| 147 | L<http://cpanratings.perl.org/d/app-githooks-plugin-validatepodformat> | ||||||||||
| 148 | |||||||||||
| 149 | =item * MetaCPAN | ||||||||||
| 150 | |||||||||||
| 151 | L<https://metacpan.org/release/App-GitHooks-Plugin-ValidatePODFormat> | ||||||||||
| 152 | |||||||||||
| 153 | =back | ||||||||||
| 154 | |||||||||||
| 155 | |||||||||||
| 156 | =head1 AUTHOR | ||||||||||
| 157 | |||||||||||
| 158 | L<Guillaume Aubert|https://metacpan.org/author/AUBERTG>, | ||||||||||
| 159 | C<< <aubertg at cpan.org> >>. | ||||||||||
| 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 | 9 | 1; | |||||||||