What do you think this module/function should be called? Right now, I'm using chump but I'm also considering champ, chimp and chmop...

=head1 NAME chump - like "chomp" but also checks your spelling =head1 SYNOPSIS use 5.010; use chump lang => 'en'; while (<>) { chump; say $_; last unless $_; }
=head1 DESCRIPTION The chump package exports a function C<chump> which acts just like the Perl built-in C<chomp> (i.e. removes a trailing new line character) bu +t also corrects any spelling mistakes in the string. =head2 Functions =over =item * C<< chump($string) >> Modifies C<$string> in-place, removing a trailing new line character i +f there is one, and correcting any spelling mistakes. =back =head2 Import Options Any options passed on the "use" line are passed on to Text::Aspell. Options are lexically scoped, and scopes are not cumulative. { use chump lang => 'fr', mode => 'email'; my $line = <>; chump $line; # check spelling in French. { use chump lang => 'en'; my $line2 = <>; chump $line2; # check spelling in English # but not in email mode. } my $line3 = <>; chump $line3; # in French and email mode again. } =head2 Unimport Do not unimport the module. =cut package chump; use JSON qw//; use Text::Aspell; use strict 'subs', 'vars'; sub import { my $class = shift; my $caller = caller; *{"$caller\::chump"} = \&chump; if (@_) { $^H{+__PACKAGE__} = _serialize_options(@_); } } sub unimport { warn "You think you no chump?\n"; } sub _serialize_options { JSON::to_json({ @_ }); } sub _deserialize_options { return unless $_[0]; my $r = JSON::from_json($_[0]); %{ $r || {} }; } sub chump (_) { my $spell = Text::Aspell->new; my @caller = caller(0); my %opts = _deserialize_options($caller[10]{+__PACKAGE__}); foreach my $key (keys %opts) { $spell->set_option($key, $opts{$key}); } my @parts = split /([[:alpha:]]+)/, $_[0]; my $count; for my $i (0 .. $#parts) { if ($parts[$i] =~ /^[[:alpha:]]+$/) { next if $spell->check($parts[$i]); my ($guess) = $spell->suggest($parts[$i]); $guess = '?' x (length $parts[$i]) unless defined $guess; $parts[$i] = $guess; $count++; } } $_[0] = join q{}, @parts; return $count + chomp $_[0]; } __PACKAGE__

In reply to RFC: Best name for this module? by tobyink

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.