#!/usr/bin/perl
#
# coffeetalk
#
# A simple program to randomly generate coffee bar drinks for those who
# want to hit a Starbucks over lunch but don't know what to buy. 
# Keeps it simple but follows the standard call syntax. As written, it'll
# generate decaf and iced drinks at random; as my Perl capabilities 
# develop, you'll be able to hack it around a bit.
#
# Read around the source a bit and you should be able to learn something
# about being a barista as well. I'd like to think it's almost as
# interesting as hacking Perl.
#
# coffeetalk is (c)1998 Brian Connors and is freely distributable under
# the terms of the GNU Public License. If you need a copy of the GPL,
# go to http://www.gnu.org or grep your distribution disks (you are using
# Linux, right? :-) ) for a file called COPYING.

# There's always a stupid user. 

$usage = "usage: coffeetalk -dDiImM2bFu. RTFMP.";

# initialize random something generator

srand;

# The different drink components, arranged neatly in arrays. Yes, it's 
# a bit ugly, but it's Perl. You will see that on some categories, options
# are repeated more than once. This is to cause a statistical slant in 
# favor of those items. Like I said, ugly.

@iced = qw(hot hot hot hot iced);
@caff = qw(regular regular regular decaf halfcaf);
@shots = qw(single double triple quad);

# trivia: venti is Italian for twenty, and it's a twenty-ounce cup. 

@size = qw(short tall grande venti);
@milk = qw(whole whole whole whole breve 2% nonfat nonfat);

# This reflects the Starbucks flavor selection. It's rather more limited
# than most coffee places I've seen; if you have your own additions, feel
# free to add them. 

@flavor = qw(plain plain plain plain plain vanilla hazelnut almond
irishcreme raspberry mint valencia);
@drink = qw(espresso americano latte cappucino mocha);

# And now generate the drink...
# This part prints nothing. It simply generates a series of words from
# the above arrays, creating the raw drink name. Of course, a venti skim
# americano is nonsensical and a valencia espresso is disgusting, but 
# we'll deal with that later. Ah, the glories of ad hoc programming...

$miced = $iced[rand(@iced)];
$mcaff = $caff[rand(@caff)];
$mshots = $shots[rand(@shots)];
$msize = $size[rand(@size)];
$mmilk = $milk[rand(@milk)];
$mflavor = $flavor[rand(@milk)];
$mdrink = $drink[rand(@drink)];

# There are a few command line args you might want to know about. Like 
# everything about this beast, it's an ad hoc mess. But like I said, 
# it's Perl.

# -i and -I control iced drinks.
# -d, -h, and -D control caffeination. 
# -s is meaningless at this point, but I may use it to control 
#    Starbucks-specific features.
# -m will force whole milk; -M will force skim; -2 will force 2%.
# -F will force non-flavored drinks. Due to the structure of the flavor
#    generator, -f is currently not worth the trouble.

# The interface is fairly primitive; I don't know much Perl yet, so 
# there's no way I'm screwing with getopt or getopt_long. 
# 
# Of course, this is still pretty screwy.

do {
	if ($ARGV[0] eq "-i") {
		$miced = "iced";
	} elsif ($ARGV[0] eq "-I") {
		$miced = "hot";
	} elsif ($ARGV[0] eq "-d") {
		$mcaff = "decaf";
	} elsif ($ARGV[0] eq "-D") {
		$mcaff = "regular";
	} elsif ($ARGV[0] eq "-h") {
		$mcaff = "halfcaf";
	} elsif ($ARGV[0] eq "-b") {
		$mmilk = "breve";
	} elsif ($ARGV[0] eq "-m") {
		$mmilk = "whole";
	} elsif ($ARGV[0] eq "-M") {
		$mmilk = "nonfat";
	} elsif ($ARGV[0] eq "-2") {
		$mmilk = "2%";
	} elsif ($ARGV[0] eq "-F") {
		$mflavor = "plain";
	} elsif ($ARGV[0] eq "-u") {
		print ("$usage\n");
		exit; 
	}
# Debug code
#	print($ARGV[0]);
} while ($ARGV = shift);

# And now we untangle the mess and print it out.

# We'll see this again...

if ($miced ne "hot") {
	print ("$miced ");
}

if ($mcaff ne "regular") {
	print ("$mcaff ");
}

# The size logic is a mess because espresso uses different terminology.

if ($mdrink eq "espresso") {
	if ($msize eq "short" || $msize eq "tall") {
		print ("solo ");
	} else {
		print ("doppio ");
	}
} else {
	print ("$msize ");
}

# Interestingly, I once came up with a computer language idea that had
# an unless clause in it (http://www.cs.bc.edu/~connorbd/magenta.html).
# Never thought it would be the easiest way to do anything.

unless ($mdrink eq "americano" || $mdrink eq "espresso") {

	if ($mmilk ne "whole") {
		print ("$mmilk ");
	}
}

if ($mflavor ne "plain") {
	print ("$mflavor ");
}

# Sometimes it's easy, though...

print ("$mdrink \n");


# As stated in the docs, this stuff is GPL, but if there are any 
# attempts to expand this for a special purpose, I'd appreciate
# knowing about them so I can distribute everything about them.
# Some possible enhancements: 
#	-Additions of Seattlish stuff like Italian sodas
#	-More Starbucks stuff
#	-Versions specific to other coffee shops (I may release a 
#	 Coffee Connection version for nostalgic Bostonians if 
#	 there's any demand at all).
# Let me know, and if you do hack it send me a copy so I can include
# it in the distribution.
