Koha-QA
view release on metacpan or search on metacpan
lib/Koha/QA/Spelling.pm view on Meta::CPAN
package Koha::QA::Spelling;
use Modern::Perl;
use base 'Koha::QA::Base';
=head1 NAME
Koha::QA::Spelling - Centralized spell checking using codespell
=head1 SYNOPSIS
use Koha::QA::Spelling;
# With a file
my $checker = Koha::QA::Spelling->new({file => $file_path, ignore_file => $ignore_file});
# Or with content directly
my $checker = Koha::QA::Spelling->new({content => $file_content, ignore_file => $ignore_file});
my $is_valid = $checker->check;
my @errors = $checker->errors;
=head1 DESCRIPTION
This module provides centralized spell checking using codespell.
=head1 METHODS
=head2 new
my $checker = Koha::QA::Spelling->new({file => $file_path, ignore_file => $ignore_file});
Creates a new Spelling checker instance.
Accepts either a 'file' parameter (path to a file) or a 'content' parameter (string content).
=head2 check
my $is_valid = $checker->check;
Checks a file for spelling errors using codespell.
=head2 errors
my @errors = $checker->errors;
Returns array of error hashrefs, each with:
- file: The file path
- message: The spelling error message
=cut
use IPC::Run3;
sub check {
my ($self) = @_;
my $file = $self->file;
my $ignore_file = $self->{ignore_file};
# Check if codespell is available
unless ( $self->_has_codespell() ) {
$self->{_errors} = [ { file => $file, message => 'codespell is not available' } ];
return 0;
}
( run in 0.449 second using v1.01-cache-2.11-cpan-eb134014566 )