# HTML::CalendarMonthSimple.pm # Generate HTML calendars. An alternative to HTML::CalendarMonth # Herein, the symbol $self is used to refer to the object that's being passed around. package HTML::CalendarMonthSimple; my $VERSION = "1.02"; use strict; use Date::Calc; # Within the constructor is the only place where values are access directly. # Methods are provided for accessing/changing values, and those methods # are used even internally. # Most of the constructor is assigning default values. sub new { my $class = shift; $class = ref($class) || $class; my $self = {}; %$self = @_; # Load ourselves up from the args # Set the month and year to either args or today ($self->{'month'}) || ($self->{'month'} = (Date::Calc::Today)[1]); ($self->{'year'}) || ($self->{'year'} = (Date::Calc::Today)[0]); # Some defaults $self->{'border'} = 5; $self->{'width'} = '100%'; $self->{'showdatenumbers'} = 1; $self->{'showweekdayheaders'} = 1; $self->{'cellalignment'} = 'left'; # Set the default calendar header $self->{'header'} = sprintf("
$header | ||||||
Sunday | \nMonday | \nTuesday | \nWednesday | \nThursday | \nFriday | \nSaturday | \n
---|---|---|---|---|---|---|
Sunday | \nMonday | \nTuesday | \nWednesday | \nThursday | \nFriday | \nSaturday | \n
$thiscontent | \n"; } $html .= "
Don't forget to buy flowers."); $cal->addcontent(13,"Thirteenth day of the month"); $cal->bgcolor('pink'); print $cal->as_HTML; =head1 DESCRIPTION HTML::CalendarMonthSimple is a Perl module for generating, manipulating, and printing a HTML calendar grid for a specified month. It is intended as a faster and easier-to-use alternative to HTML::CalendarMonth. This module requires the Date::Calc module, which is available from CPAN if you don't already have it. =head1 INTERFACE METHODS =head1 new(ARGUMENTS) Naturally, new() returns a newly constructed calendar object. Recognized arguments are 'year' and 'month', to specify which month's calendar will be used. If either is omitted, the current value is used. An important note is that the month and the year are NOT the standard C or Perl -- use a month in the range 1-12 and a real year, e.g. 2001. # Examples: # Create a calendar for this month. $cal = new HTML::CalendarMonthSimple(); # One for a specific month/year $cal = new HTML::CalendarMonthSimple('month'=>2,'year=>2000); # One for "the current date" in 1997 $cal = new HTML::CalendarMonthSimple('year'=>1997); =head1 setcontent(DATE,STRING) =head1 addcontent(DATE,STRING) =head1 getcontent(DATE) These methods are used to control the content of date cells within the calendar grid. # Examples: # The cell for the 15th of the month will now say something. $cal->setcontent(15,"An Important Event!"); # Later down the program, we want the content to be boldfaced. $foo = "" . $cal->getcontent(15) . ""; $cal->setcontent(15,$foo); # Or we could get extra spiffy: $cal->setcontent(15,"" . $cal->getcontent(15) . ""); # Example: # addcontent() does not clober existing content. # Also, if you setcontent() to '', you've deleted the content. $cal->setcontent(16,''); $cal->addcontent(16,"
Hello World
"); $cal->addcontent(16,"Hello Again
"); print $cal->getcontent(16); # Prints 2 sentences =head1 setdatehref(DATE,URL_STRING) =head1 getdatehref(DATE) These methods are used to control the content of date cells within the calendar grid. # Example: # The date number in the cell for the 15th of the month will # be a link to the sourceforge website $cal->setdatehref(15,"http://sourceforge.net/"); # Example: # You want to add to an URL $cal->setdatehref(15, $getdatehref(15)."projects/perl/"); =head1 as_HTML() This method returns a string containing the HTML table for the month. # Example: print $cal->as_HTML(); It's okay to continue modifying the calendar after calling as_HTML(). My guess is that you'd want to call as_HTML() again to print the further-modified calendar, but that's your business... =head1 year() =head1 month() =head1 monthname() These methods simply return the year/month of the calendar. monthname() returns the text name of the month, e.g. "December". =head1 border([INTEGER]) This specifies the value of the border attribute to the tag for each day's cell. This controls how text will be centered/aligned within the cells.
Any value can be used, if you think the web browser will find it interesting. Some useful alignments are: left, right, center, top, and bottom,
By default, cells are aligned to the left.
=head1 header([STRING])
By default, the current month and year are displayed at the top of the calendar grid. This is called the "header".
The header() method allows you to set the header to whatever you like. If no new header is specified, the current header is returned.
If the header is set to an empty string, then no header will be printed at all. (No, you won't be stuck with a big empty cell!)
# Example:
# Set the month/year header to something snazzy.
my($y,$m) = ( $cal->year() , $cal->monthname() );
$cal->header(" |