Acme-Opish
view release on metacpan or search on metacpan
lib/Acme/Opish.pm view on Meta::CPAN
# Is this word capitalized?
my $is_capped = /^[A-Z]/ ? 1 : 0;
# Lowercase the first letter in case we have to prefix it.
$_ = lcfirst;
# Okay. Prefix the sucka.
# XXX Ack. How can I simplify this ugliness?
if (exists $OK{ lc $_ }) { # {{{
s/
( # Capture...
[aeiouy]+ # consecutive vowels
\B # that do not terminate at a word boundry
(?![aeiouy]) # that are not followed by another vowel
| # or
[aeiouy]* # any consecutive vowels
[aeiouy] # with any vowel following
\b # that terminates at a word boundry.
) # ...end capture.
/$prefix$1/gisx; # Add 'op' to what we captured.
} # }}}
# Special case 'ye'.
elsif (lc ($_) eq 'ye') {
$_ = 'y' . $prefix . substr ($_, -1);
}
# We don't want to prefix a non-vowel y.
elsif (/^y[aeiouy]/i) { # {{{
s/
(?:^y)? # Our string starts with y, but we don't
# want to consider it for every match.
( # Capture...
[aeiouy]+ # consecutive vowels
\B # that do not terminate at a word boundry
(?![aeiouy]) # that are not followed by another vowel
| # or
[aeiouy]* # any consecutive vowels
[aiouy] # with any non-e vowel following
\b # that terminates at a word boundry.
| # or
[aeiouy]+ # consecutive vowels
[aeiouy] # with any vowel following
\b # that terminates at a word boundry.
) # ...end capture.
/$prefix$1/gisx; # Add 'op' to what we captured.
$_ = 'y' . $_;
} # }}}
# This regexp captures the "non-solitary, trailing e" vowels.
else { # {{{
s/
( # Capture...
[aeiouy]+ # consecutive vowels
\B # that do not terminate at a word boundry
(?![aeiouy]) # that are not followed by another vowel
| # or
[aeiouy]* # any consecutive vowels
[aiouy] # with any non-e vowel following
\b # that terminates at a word boundry.
| # or
[aeiouy]+ # consecutive vowels
[aeiouy] # with any vowel following
\b # that terminates at a word boundry.
) # ...end capture.
/$prefix$1/gisx; # Add 'op' to what we captured.
} # }}}
# The original word was capitalized.
$_ = ucfirst if $is_capped;
}
lib/Acme/Opish.pm view on Meta::CPAN
More accurately, this means, add an arbitrary prefix to the vowel
groups of words, except for the "silent e" and "starting, non-vowel
y's".
Note: This module capitalizes words like you would expect. Maybe a
couple examples will elucidate this point:
enop('Abc') produces 'Opabc'
enop('abC') produces 'opabC'
Unfortunately, this function, currently converts consecutive spaces
and newlines into single spaces and newlines. Yes, this is not a
feature, but a bug.
* See the eg/ directory for examples.
=head1 EXPORT
=head2 enop [-opish_prefix => STRING,] ARRAY
Convert strings or entire text files to opish.
( run in 1.271 second using v1.01-cache-2.11-cpan-39bf76dae61 )