]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/piglatin.pl
* Accidentally left in a debug output
[infobot.git] / src / Modules / piglatin.pl
1 # turns english text into piglatin
2 # Copyright (c) 2005 Tim Riker <Tim@Rikers.org>
3
4 use strict;
5 use warnings;
6
7 package piglatin;
8
9 sub piglatin {
10     my ($text) = @_;
11     my $piglatin;
12     my $suffix = 'ay';
13
14     # FIXME: does not handle:
15     #  non-trailing punctuation and hyphens
16     #  y as vowel 'style' -> 'ylestay'
17     #  contractions
18     for my $word ( split /\s+/, $text ) {
19         my ( $pigword, $postfix );
20
21         #($word,$postfix) = $word =~ s/^([a-z]*)([,.!\?;:'"])?$//i;
22         if ( $word =~ s/([,.!\?;:'"])$//i ) {
23             $postfix = $1;
24         }
25         if ( $word =~ /^(qu)(.*)/ ) {
26             $pigword = "$2$1$suffix";
27         }
28         elsif ( $word =~ /^(Qu)(.)(.*)/ ) {
29             $pigword = uc($2) . $3 . lc($1) . $suffix;
30         }
31         elsif ( $word =~ /^([bcdfghjklmnpqrstvwxyz]+)(.*)/ ) {
32             $pigword = "$2$1$suffix";
33         }
34         elsif ( $word =~
35             /^([BCDFGHJKLMNPQRSTVWXYZ])([bcdfghjklmnpqrstvwxyz]*)([aeiouy])(.*)/
36           )
37         {
38             $pigword = uc($3) . $4 . lc($1) . $2 . $suffix;
39         }
40         else {
41             $pigword = $word . 'w' . $suffix;
42         }
43         $piglatin .= ' ' if $piglatin;
44         $piglatin .= $pigword . $postfix;
45     }
46     &::performStrictReply( $piglatin || 'failed' );
47 }
48
49 1;
50
51 # vim:ts=4:sw=4:expandtab:tw=80