]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/piglatin.pl
* Add vim formatting comments ( # vim:ts=4:sw=4:expandtab:tw=80 )
[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 {
11   my ($text) = @_;
12   my $piglatin;
13   my $suffix = 'ay';
14
15   # FIXME: does not handle:
16   #  non-trailing punctuation and hyphens
17   #  y as vowel 'style' -> 'ylestay'
18   #  contractions
19   for my $word (split /\s+/, $text) {
20     my ($pigword, $postfix);
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     } elsif ($word =~ /^(Qu)(.)(.*)/ ) {
28       $pigword = uc($2) . $3 . lc($1) . $suffix;
29     } elsif ($word =~ /^([bcdfghjklmnpqrstvwxyz]+)(.*)/ ) {
30       $pigword = "$2$1$suffix";
31     } elsif ($word =~ /^([BCDFGHJKLMNPQRSTVWXYZ])([bcdfghjklmnpqrstvwxyz]*)([aeiouy])(.*)/ ) {
32       $pigword = uc($3) . $4 . lc($1) . $2 . $suffix;
33     } else {
34       $pigword = $word . 'w' . $suffix;
35     }
36     $piglatin .= ' ' if $piglatin;
37     $piglatin .= $pigword . $postfix;
38   }
39   &::performStrictReply($piglatin||'failed');
40 }
41
42 1;
43
44 # vim:ts=4:sw=4:expandtab:tw=80