HTML-Spelling-Site
view release on metacpan or search on metacpan
lib/HTML/Spelling/Site/Checker.pm view on Meta::CPAN
}
}
$write_cache->( $timestamp_cache, $digest_cache );
return { misspellings => \@ret, };
}
sub _format_error
{
my ( $self, $error ) = @_;
return sprintf( "%s:%d:%s",
$error->{filename}, $error->{line_num}, $error->{line_with_context},
);
}
sub spell_check
{
my ( $self, $args ) = @_;
my $misspellings = $self->_calc_mispellings($args);
foreach my $error ( @{ $misspellings->{misspellings} } )
{
printf {*STDOUT} "%s\n", $self->_format_error($error);
}
print "\n";
}
sub test_spelling
{
my ( $self, $args ) = @_;
my $MAXLEN = ( $args->{'MAXLEN'} || 1000 );
my $MAXSIZE = ( $args->{'MAXSIZE'} || 20 );
my $misspellings = $self->_calc_mispellings($args);
if ( $args->{light} )
{
require Test::More;
my $ret = Test::More::is( scalar( @{ $misspellings->{misspellings} } ),
0, $args->{blurb} );
my $output_text = '';
DIAGLOOP:
foreach my $error ( @{ $misspellings->{misspellings} } )
{
$output_text .= $self->_format_error($error) . "\n";
if ( length($output_text) >= $MAXLEN )
{
$output_text = substr( $output_text, 0, $MAXLEN );
last DIAGLOOP;
}
}
Test::More::diag($output_text);
return $ret;
}
require Test::Differences;
my @arr = @{ $misspellings->{misspellings} };
if ( @arr > $MAXSIZE )
{
$#arr = $MAXSIZE - 1;
}
return Test::Differences::eq_or_diff( ( \@arr ), [], $args->{blurb}, );
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
HTML::Spelling::Site::Checker - does the actual checking.
=head1 VERSION
version 0.10.3
=head1 SYNOPSIS
In lib/Shlomif/Spelling/FindFiles.pm :
package Shlomif::Spelling::FindFiles;
use strict;
use warnings;
use MooX qw/late/;
use List::MoreUtils qw/any/;
use HTML::Spelling::Site::Finder;
my @prunes =
(
qr#^\Qdest/t2/humour/by-others/how-to-make-square-corners-with-CSS/#,
);
sub list_htmls
{
my ($self) = @_;
return HTML::Spelling::Site::Finder->new(
{
root_dir => 'dest/t2',
prune_cb => sub {
my ($path) = @_;
return any { $path =~ $_ } @prunes;
},
}
)->list_all_htmls;
}
1;
In lib/Shlomif/Spelling/Whitelist.pm :
package Shlomif::Spelling::Whitelist;
use strict;
use warnings;
lib/HTML/Spelling/Site/Checker.pm view on Meta::CPAN
1;
In bin/spell-checker-iface :
#!/usr/bin/env perl
use strict;
use warnings;
use lib './lib';
use Shlomif::Spelling::Iface;
Shlomif::Spelling::Iface->new->run;
In t/html-spell-check.t :
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 1;
{
my $output = `./bin/spell-checker-iface 2>&1`;
chomp($output);
# TEST
is ($output, '', "No spelling errors.");
}
=head1 DESCRIPTION
The instances of this class can be used to do the actual scanning of
local HTML files.
=head1 METHODS
=head2 my $obj = HTML::Spelling::Site::Checker->new({ whitelist_parser => $parser_obj, check_word_cb => sub { ... }, timestamp_cache_fn => '/path/to/timestamp-cache.json' })
Initialises a new object. C<whitelist_parser> is normally an instance of
L<HTML::Spelling::Site::Whitelist>. C<check_word_cb> is a subroutine to check
a word for correctness. C<timestamp_cache_fn> points to the path where the
cache of the last-checked timestamps of the files is stored in JSON format.
=head2 $finder->spell_check();
Performs the spell check and prints the erroneous words to stdout.
=head2 $bool = $finder->should_check({word=>$word_string})
Whether the word should be checked for being misspelled or not. Can be
overridden in subclasses. (Was added in version 0.4.0).
=head2 $finder->test_spelling({ files => [@files], blurb => $blurb, });
A spell check function compatible with L<Test::More> . Emits one assertion.
Since version 0.2.0, if a C<<< light => 1 >>> key is specified and is true, it
will not use L<Test::Differences>, which tends to consume a lot of RAM when
there are many messages.
Since version 0.10.0, C<'MAXLEN'> argument was added.
Since version 0.10.0, C<'MAXSIZE'> argument was added.
=head2 $finder->whitelist_parser()
For internal use.
=head2 $finder->check_word_cb()
For internal use.
=head2 $finder->timestamp_cache_fn()
For internal use.
=for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
=head1 SUPPORT
=head2 Websites
The following websites have more information about this module, and may be of help to you. As always,
in addition to those websites please use your favorite search engine to discover more resources.
=over 4
=item *
MetaCPAN
A modern, open-source CPAN search engine, useful to view POD in HTML format.
L<https://metacpan.org/release/HTML-Spelling-Site>
=item *
RT: CPAN's Bug Tracker
The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
L<https://rt.cpan.org/Public/Dist/Display.html?Name=HTML-Spelling-Site>
=item *
CPANTS
The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
L<http://cpants.cpanauthors.org/dist/HTML-Spelling-Site>
=item *
CPAN Testers
The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
L<http://www.cpantesters.org/distro/H/HTML-Spelling-Site>
( run in 1.652 second using v1.01-cache-2.11-cpan-140bd7fdf52 )