| 1 | # | ||||||||||
| 2 | # This file is part of Test-Pod-Spelling-CommonMistakes | ||||||||||
| 3 | # | ||||||||||
| 4 | # This software is copyright (c) 2014 by Apocalypse. | ||||||||||
| 5 | # | ||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||
| 8 | # | ||||||||||
| 9 | 1 | ▶ | use strict; use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | package Test::Pod::Spelling::CommonMistakes; | ||||||||||
| 11 | # git description: release-1.000-2-gb6f88eb | ||||||||||
| 12 | 1 | $Test::Pod::Spelling::CommonMistakes::VERSION = '1.001'; | |||||||||
| 13 | 1 | our $AUTHORITY = 'cpan:APOCAL'; | |||||||||
| 14 | |||||||||||
| 15 | # ABSTRACT: Checks POD for common spelling mistakes | ||||||||||
| 16 | |||||||||||
| 17 | # Import the modules we need | ||||||||||
| 18 | 1 | ▶ | use Pod::Spell::CommonMistakes 0.01 qw( check_pod_all ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | ▶ | use Test::Pod 1.40 (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | # setup our tests and etc | ||||||||||
| 22 | 1 | ▶ | use Test::Builder 0.94; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 1 | my $Test = Test::Builder->new; | |||||||||
| 24 | |||||||||||
| 25 | # auto-export our 2 subs | ||||||||||
| 26 | 1 | ▶ | use parent qw( Exporter ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 1 | our @EXPORT = qw( pod_file_ok all_pod_files_ok ); ## no critic ( ProhibitAutomaticExportation ) | |||||||||
| 28 | |||||||||||
| 29 | #pod =method all_pod_files_ok( [ @files ] ) | ||||||||||
| 30 | #pod | ||||||||||
| 31 | #pod This function is what you will usually run. It automatically finds any POD in your distribution and runs checks on them. | ||||||||||
| 32 | #pod | ||||||||||
| 33 | #pod Accepts an optional argument: an array of files to check. By default it checks all POD files it can find in the distribution. Every file it finds | ||||||||||
| 34 | #pod is passed to the C<pod_file_ok()> function. | ||||||||||
| 35 | #pod | ||||||||||
| 36 | #pod =cut | ||||||||||
| 37 | |||||||||||
| 38 | 0 | ▶ | sub all_pod_files_ok { | ||||||||
|
Subroutine
all_pod_files_ok: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 39 | 0 | ▶ | my @files = @_ ? @_ : Test::Pod::all_pod_files(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | |||||||||||
| 41 | 0 | $Test->plan( tests => scalar @files ); | |||||||||
| 42 | |||||||||||
| 43 | 0 | my $ok = 1; | |||||||||
| 44 | 0 | foreach my $file ( @files ) { | |||||||||
| 45 | 0 | ▶ | pod_file_ok( $file ) or undef $ok; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 0 | return $ok; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | #pod =method pod_file_ok( $file, [ $name ] ) | ||||||||||
| 52 | #pod | ||||||||||
| 53 | #pod C<pod_file_ok()> will okay the test if there is spelling errors present in the POD. Furthermore, if the POD was | ||||||||||
| 54 | #pod malformed as reported by L<Pod::Simple>, the test will fail and not attempt to check spelling. | ||||||||||
| 55 | #pod | ||||||||||
| 56 | #pod When it fails, C<pod_file_ok()> will show any misspelled words and their suggested spelling as diagnostics. | ||||||||||
| 57 | #pod | ||||||||||
| 58 | #pod The optional second argument $name is the name of the test. If it is omitted, C<pod_file_ok()> chooses a default | ||||||||||
| 59 | #pod test name "Spelling test for $file". | ||||||||||
| 60 | #pod | ||||||||||
| 61 | #pod =cut | ||||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | sub pod_file_ok { | ||||||||
|
Subroutine
pod_file_ok: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 64 | 0 | my $file = shift; | |||||||||
| 65 | 0 | ▶ | my $name = @_ ? shift : "Spelling test for $file"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | |||||||||||
| 67 | 0 | ▶ | if ( ! -f $file ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | $Test->ok( 0, $name ); | |||||||||
| 69 | 0 | $Test->diag( "Error: '$file' does not exist" ); | |||||||||
| 70 | 0 | return; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | # Parse the POD! | ||||||||||
| 74 | 0 | my $res; | |||||||||
| 75 | 0 | eval { | |||||||||
| 76 | 0 | $res = check_pod_all( $file ); | |||||||||
| 77 | }; | ||||||||||
| 78 | 0 | ▶ | if ( $@ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | $Test->ok( 0, $name ); | |||||||||
| 80 | 0 | $Test->diag( "Error: Unable to parse '$file' - $@" ); | |||||||||
| 81 | 0 | return; | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | # Did we get any errors? | ||||||||||
| 85 | 0 | ▶ | if ( keys %$res == 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | $Test->ok( 1, $name ); | |||||||||
| 87 | 0 | return 1; | |||||||||
| 88 | } else { | ||||||||||
| 89 | 0 | $Test->ok( 0, $name ); | |||||||||
| 90 | 0 | foreach my $e ( keys %$res ) { | |||||||||
| 91 | ## no critic ( ProhibitAccessOfPrivateData ) | ||||||||||
| 92 | 0 | $Test->diag( "'$e' should be spelled " . $res->{ $e } ); | |||||||||
| 93 | } | ||||||||||
| 94 | 0 | return; | |||||||||
| 95 | } | ||||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | 1 | 1; | |||||||||
| 99 | |||||||||||
| 100 | __END__ | ||||||||||