NAME
HTML::Calendar::Simple - A simple html calendar
SYNOPSIS
use HTML::Calendar::Simple;
my $cal = HTML::Calendar::Simple->new; # This month, this year
$cal = HTML::Calendar::Simple->new({ 'month' => $month }); # This year
$cal = HTML::Calendar::Simple->new({ 'month' => $month,
'year' => $year});
my $month = $cal->month;
my $year = $cal->year;
$cal->pin_up(a_picture_location);
$cal->daily_info({ 'day' => $day,
'day_link' => $location,
$type1 => $info1,
$type2 => $info2,
'link' => [$link, $tag],
});
print $cal;
print $cal->calendar_month;
or
print $cal->calendar_month({border => 0}); #this allows you to change the border of the table ( default is set to 1 )
which shows the border with padding.
my $html = HTML::Calendar::Simple->calendar_year;
$html = HTML::Calendar::Simple->calendar_year({ 'year' => $year });
$html = HTML::Calendar::Simple->calendar_year(
{ 'pin_up' => $where_to_find_the_picture,
'year' => $year,
$month => { $day1 => $link1,
$day2 => $link2, }
});
DESCRIPTION
This is a simple module which will make an HTML representation of a given month. You can add links to individual days, or in fact, any sort of information you want.
Yes, the inspiration for this came out of me looking at HTML::CalendarMonthSimple, and thinking 'Hmmm. A bit too complicated for what I want. I know, I will write a simplified version.' So I did.
new
my $cal = HTML::Calendar::Simple->new;
my $cal = HTML::Calendar::Simple->new({ 'month' => $month });
my $cal = HTML::Calendar::Simple->new({ 'month' => $month,
'year' => $year });
This will make a new HTML::Calendar::Simple object.
month
my $month = $cal->month;
This will return the numerical value of the month.
year
my $year = $cal->year;
This will return the four-digit year of the calendar
daily_info
$cal->daily_info({ 'day' => $day,
'day_link' => $location, # puts an href on the day
$type1 => $info1,
$type2 => $info2,
'link' => [$link, $tag],
});
This will record that fact that $info of $type happen(s|ed) on $day.
Now, if there is no method defined to cope with $type, then the information pased as $info will just be text printed in the cell of $day. So, if you want something special to happen to (say) a type of 'meeting', you would have to define a method called _meeting.
For example:
$cal->daily_info({ 'day' => 12,
'meeting' => 'Meet swm' });
and somewhere else in this module...
sub _meeting {
my $self = shift;
return $self->_cgi->h1( shift );
}
So any day that had a meeting key in its hash would be displayed as an <h1>$info</h1>
Note: If you call daily_info again with the same day with the same type BUT with different info, then the old info will get clobbered.
There is already one method in here, and that is _link. So, you can do:
$cal->daily_info({ 'day' => $day,
'link' => [$link, $tag],
});
Note that the key 'link' takes an array ref.
Also, if you don't pass valid uris as values of the keys 'link' and 'day_link', well, that is your out if they don't work!
More Examples:
you can use a loop to span over days to add info to rather then manualy making one for each event.
my $cal = HTML::Calendar::Simple->new();
for my $day (0..$end_day_of_month){
$cal->daily_info({ 'day' => $day,
'day_link' => $location, # puts an href on the day
$type1 => $info1,
$type2 => $info2,
'link' => [$link, $tag],
});
}
print $cal->calendar_month();
pin_up
$cal->pin_up(a_picture_with_location);
This will add a picture above the calendar month, just like the calendar I have hanging up in my kitchen, (It is a cat calendar, if you are interested, as my second son loves cats. As do I!)
This could be used to have a mechanic's garage Pirelli-style pr0n calendar, but that would be your call. Mine would be something including a Triumph Daytona 955i. Mmmm, nice.
calendar_month
my $html = $cal->calendar_month;
This will return an html string of the calendar month in question.
html
my $html = $cal->html;
This will return an html string of the calendar month in question.
THIS CALL HAS BEEN DEPRECATED.
calendar_year
my $html = HTML::Calendar::Simple->calendar_year;
$html = HTML::Calendar::Simple->calendar_year({ 'year' => $year });
$html = HTML::Calendar::Simple->calendar_year(
{ 'pin_up' => $where_to_find_the_picture,
'year' => $year,
$month => { $day1 => $link1,
$day2 => $link2, }
});
This will return the an html string for every month in the year passed, or the current year if nothing passed in.
This key of the hashref month is *another* hashref, where the key here is the day in that month, and the value a link.
This is icky, I know, and now puts me in mind of making HTML::Calendar::Day, HTML::Calendar::Month and HTML::Calendar::Year, and having an overarching HTML::Calendar.
BUGS
None known
TODO
Oh....lots of things.
o Rip out the CGI stuff and put all the HTML in a template, so the user
can decide on the format of the calendar themselves.
o Allow for the setting of borders etc like HTML::CalendarMonthSimple.
o Format the output better if there is info in a daily cell.
o Perhaps overload '.' so you could add two calendars. Not sure.
o Check the links passed in are of format http://www.stray-toaster.co.uk
or something.
o Get rid of the days and months hashes and replace with something better.
o And if all that happens, it may as well be HTML::CalendarMonthSimple!!
o Make HTML::Calendar::Day, HTML::Calendar::Month and HTML::Calendar::Year
SHOWING YOUR APPRECIATION
There was a thread on london.pm mailing list about working in a vacumn - that it was a bit depressing to keep writing modules but never get any feedback. So, if you use and like this module then please send me an email and make my day.
All it takes is a few little bytes.
(Leon wrote that, not me!)
AUTHOR
Stray Toaster <coder@stray-toaster.co.uk>
With Thanks
o To swm E<lt>F<swm@swmcc.com>E<gt> for some roadtesting!
o To <lt>F<Simon Young><gt> for the pin-up idea
o To <lt>F<Aaron Yorkovitch><gt> patch for being able to change the table border
COPYRIGHT
Copyright (C) 2012, mwk
This module is free software; you can redistribute it or modify it under the same terms as Perl itself.