
package comics;

require Exporter;
use warnings;

@ISA         = qw(Exporter);
@EXPORT      = qw(list);
@EXPORT_OK   = qw(list);
%EXPORT_TAGS = ( all => \@EXPORT_OK );
$VERSION     = v0.0.6;
$prefix      = '/u/e/n/englet/public/html/comics/';

sub new 
{
	my ($invocant) = shift;
	my ($class   ) = ref($invocant) || $invocant;
	$time = shift;

	my ($self) = {
	  version => $VERSION,
	  list    => create_list(@$time),
	  time    => $time,
	  prefix  => $prefix,
	  @_
	};
	bless  ($self,$class);
	return ($self);
}

sub version()   
{ return ($VERSION);   }

sub list() 
{
	my ($self)  = shift;
	return (%{$self->{list}});
}

sub create_list() 
{
	my %list = ();
	my $folder;
	my(@time) = @_;

	# Comics.com Comics (which require searching for the image name)
	$list{'9 Chickweed Lane'}    = {search => qr@.*<IMG SRC=\"(.+?)\" ALT=\"Today's Comic\" BORDER=\"0\">@, fill => 'chickweed'};
	$list{'B.C.'}                = {search => qr@.*<IMG SRC=\"(.+?)\" ALT=\"Today's Comic\" BORDER="0">@, fill => 'bc', creators => 1};
	$list{'Dilbert'}             = {search => qr@.*<IMG SRC=\"(.+?)\" BORDER=0 ALT=\"Today's Dilbert Comic\">@, fill => 'dilbert', sundayjpg => 1};
	$list{'Get Fuzzy'}           = {search => qr@.*<img src=\"(.+?)\" border=\"0\" onload=\"STR.AttachZoomHover@, fill => 'get_fuzzy', sundayjpg => 1};
	$list{'Frazz'}               = {search => qr@.*<IMG SRC=\"(.+?)\" ALT=\"Today's Comic\" BORDER=\"0\">@, fill => 'frazz'};
	$list{'Over the Hedge'}      = {search => qr@.*<IMG SRC=\"(.+?)\" ALT=\"Today's Comic\" BORDER="0">@, fill => 'hedge', sundayjpg => 1};
	$list{'Peanuts'}             = {search => qr@.*<IMG SRC=\"(.+?)\" ALT=\"Today's Strip\" BORDER="0">@, fill => 'peanuts'};
	$list{'Pearls Before Swine'} = {search => qr@.*<IMG SRC=\"(.+?)\" ALT=\"Today's Comic\" BORDER="0">@, fill => 'pearls', sundayjpg => 1};
	$list{'Rose is Rose'}        = {search => qr@.*<IMG SRC=\"(.+?)\" ALT=\"Today's Comic\" BORDER="0">@, fill => 'roseisrose'};
	$list{'Speedbump'}           = {search => qr@.*<IMG SRC=\"(.+?)\" ALT=\"Today's Comic\" BORDER="0">@, fill => 'speedbump', creators => 1};
	$list{'Strange Brew'}        = {search => qr@.*<IMG SRC=\"(.+?)\" ALT=\"Today's Comic\" BORDER="0">@, fill => 'strangebrew', creators => 1};
	$list{'The Other Coast'}     = {search => qr@.*<IMG SRC=\"(.+?)\" ALT=\"Today's Comic\" BORDER="0">@, fill => 'othercoast', creators => 1};
	$list{'Wizard of Id'}        = {search => qr@.*<IMG SRC=\"(.+?)\" ALT=\"Today's Comic\" BORDER="0">@, fill => 'wizardofid', creators => 1};

	# King Features comics (which require the 'referer')
	$list{'Baby Blues'}             = {url => sprintf('http://est.rbma.com/content/Baby_Blues?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };
	$list{'Bizarro'}                = {url => sprintf('http://est.rbma.com/content/Bizarro?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };
	$list{'Buckles'}                = {url => sprintf('http://est.rbma.com/content/Buckles?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };
	$list{'Curtis'}                 = {url => sprintf('http://est.rbma.com/content/Curtis?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };
	$list{'Dennis the Menace'}      = {url => sprintf('http://est.rbma.com/content/Dennis_The_Menace?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };
	$list{'Funky Winkerbean'}       = {url => sprintf('http://est.rbma.com/content/Funky_Winkerbean?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };
	$list{'Grin and Bear It'}       = {url => sprintf('http://est.rbma.com/content/Grin_and_Bear_It?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };
	$list{'Hagar the Horrible'}     = {url => sprintf('http://est.rbma.com/content/Hagar_The_Horrible?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };
	$list{'Mallard Fillmore'}       = {url => sprintf('http://est.rbma.com/content/Mallard_Fillmore?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };
	$list{'Mother Goose and Grimm'} = {url => sprintf('http://est.rbma.com/content/Mgoose?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };
	$list{'Mutts'}                  = {url => sprintf('http://est.rbma.com/content/Mutts?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };
	$list{'Rhymes with Orange'}     = {url => sprintf('http://est.rbma.com/content/Rhymes_with_Orange?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };
	$list{'Sally Forth'}            = {url => sprintf('http://est.rbma.com/content/Sally_Forth?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };
	$list{'Shermans Lagoon'}        = {url => sprintf('http://est.rbma.com/content/Shermans_Lagoon?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };
	$list{'Tiger'}                  = {url => sprintf('http://est.rbma.com/content/Tiger?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };
	$list{'Zits'}                   = {url => sprintf('http://est.rbma.com/content/Zits?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };

	# Calvin and Hobbes are repeated from a few years ago
	$list{'Calvin and Hobbes'} = {url => sprintf('http://images.ucomics.com/comics/ch/%04d/ch%02d%02d%02d.gif',$time[5]+1900,$time[5]%100,$time[4]+1,$time[3]),
				      file => 'calvinandhobbes'.sprintf('-%04d%02d%02d.gif', $time[5]+1900,$time[4]+1,$time[3]) };

	# ucomics.com comics are easy, because the file names can be determined from the date.
	$list{'Doonesbury'}          = {url => sprintf('http://images.ucomics.com/comics/db/%04d/db%02d%02d%02d.gif',$time[5]+1900,$time[5]%100,$time[4]+1,$time[3]) };
	$list{'The Duplex'}          = {url => sprintf('http://images.ucomics.com/comics/dp/%04d/dp%02d%02d%02d.gif',$time[5]+1900,$time[5]%100,$time[4]+1,$time[3]) };
	$list{'For Better or Worse'} = {url => sprintf('http://images.ucomics.com/comics/fb/%04d/fb%02d%02d%02d.gif',$time[5]+1900,$time[5]%100,$time[4]+1,$time[3]) };
	$list{'FoxTrot'}             = {url => sprintf('http://images.ucomics.com/comics/ft/%04d/ft%02d%02d%02d.gif',$time[5]+1900,$time[5]%100,$time[4]+1,$time[3]) };
	$list{'Garfield'}            = {url => sprintf('http://images.ucomics.com/comics/ga/%04d/ga%02d%02d%02d.gif',$time[5]+1900,$time[5]%100,$time[4]+1,$time[3]) };
	$list{'Non Sequitur'}        = {url => sprintf('http://images.ucomics.com/comics/nq/%04d/nq%02d%02d%02d.gif',$time[5]+1900,$time[5]%100,$time[4]+1,$time[3]) };
	$list{'Shoe'}                = {url => sprintf('http://images.ucomics.com/comics/tmsho/%04d/tmsho%02d%02d%02d.gif',$time[5]+1900,$time[5]%100,$time[4]+1,$time[3]) };
	$list{'Ziggy'}               = {url => sprintf('http://images.ucomics.com/comics/zi/%04d/zi%02d%02d%02d.gif',$time[5]+1900,$time[5]%100,$time[4]+1,$time[3]) };

	# Comics I don't collect anymore.
	#$list{'The Boondocks'}      = {url => sprintf('http://images.ucomics.com/comics/bo/%04d/bo%02d%02d%02d.gif',$time[5]+1900,$time[5]%100,$time[4]+1,$time[3]) };
	#$list{'Bound and Gagged'}   = {url => sprintf('http://images.ucomics.com/comics/tmbou/%04d/tmbou%02d%02d%02d.gif',$time[5]+1900,$time[5]%100,$time[4]+1,$time[3]) };
	#$list{'Close to Home'}      = {url => sprintf('http://images.ucomics.com/comics/cl/%04d/cl%02d%02d%02d.gif',$time[5]+1900,$time[5]%100,$time[4]+1,$time[3]) };
	#$list{'The Norm'}           = {url => sprintf('http://est.rbma.com/content/Norm?date=%04d%02d%02d',$time[5]+1900,$time[4]+1,$time[3]), referer => 'http://www.kingfeatures.com/' };

	foreach $item (keys %list) {
	  $folder = $item;
	  $folder =~ s/(.)/\l$1/g;
	  $folder =~ s/ //g;
	  $folder =~ s/\.//g;
	  $list{$item}{name}   = $item;
	  $list{$item}{folder} = $folder;
	  $list{$item}{file}   = $folder.sprintf('-%04d%02d%02d.gif', $time[5]+1900,$time[4]+1,$time[3]) unless defined ($list{$item}{file});
	  $list{$item}{all}    = $prefix.$list{$item}{folder}.'/'.$list{$item}{file};
	  $list{$item}{img}    = 'comics/'.$list{$item}{folder}.'/'.$list{$item}{file};
	}

	return \%list;
}
