Acme-Opish

 view release on metacpan or  search on metacpan

lib/Acme/Opish.pm  view on Meta::CPAN

use base qw(Exporter);
use vars qw(@EXPORT @EXPORT_OK);
@EXPORT = @EXPORT_OK = qw(
    enop
    has_silent_e
    no_silent_e
);
use File::Basename;

# no_silent_e list {{{
my %OK; @OK{qw(
    adobe
    acme
    acne
    anime
    antistrophe
    apostrophe
    be
    breve
    Brule
    cabriole
    cache
    Calliope
    capote
    Catananche
    catastrophe
    clave
    cliche
    consomme
    coyote
    diastrophe
    epanastrophe
    epitome
    forte
    Giuseppe
    kamikaze
    karate
    me
    misogyne
    Pele
    phlebotome
    progne
    Psyche
    psyche
    Quixote
    recipie
    Sade
    Salome
    saute
    stanze
    supercatastrophe
    Tempe
    tousche
    tsetse
    tonsillectome
    tonsillotome
    tracheotome
    ukulele
    we
    zimbabwe
)} = undef;
# }}}

# Add 'no_silent_e' entries if present and then return the list.
sub no_silent_e {
    $OK{$_} = undef for @_;
    return keys %OK;
}

# Remove'no_silent_e' entries if present and then return the list.
sub has_silent_e {
    delete $OK{$_} for @_;
    return keys %OK;
}

# Prefix vowels not declared in the 'no_silent_e' list.
sub enop {
    my $prefix = 'op';
    # If present, the prefix is given as a named parameter.
    if ($_[0] eq '-opish_prefix') {
        shift;
        $prefix = shift;
    }

    # Process the given text stream.
    my @strings = @_;
        # Given as a known system filename.
    for (@strings) {  # {{{
        if (-f) {
            # Open the file for reading.
            open IN, $_ or carp "Can't read $_: $!\n";

            # Construct a new filename.
            my ($name, $path) = fileparse($_, '');
            $_ = $path . 'opish-' . $name;

            # Open the new file for writing.
            open OUT, ">$_" or carp "Can't write $_: $!\n";

            # Write opish to the file.
            while (my $line = <IN>) {
                print OUT _to_opish($prefix, $line), "\n";
            }

            # Close the files.
            close IN;
            close OUT;
        }  # }}}
        # ..or given as strings on the commandline.
        else {
            $_ = _to_opish($prefix, $_);
        }
    }

    return @strings;
}

# DrMath++ && DrForr++ && Yay!
sub _to_opish {
    my ($prefix, $string) = @_;

    # XXX Oof.  We don't preserve whitespace.  : \
    my @words = split /\s+/, $string;

    # Process each word as a unit.
    for (@words) {



( run in 3.615 seconds using v1.01-cache-2.11-cpan-d80b1682f3f )