The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

HTML::CalendarMonth - Perl extension for generating and manipulating HTML calendar months

SYNOPSIS

 use HTML::CalendarMonth;
 use HTML::AsSubs;

 # Using HTML::AsSubs
 $c = HTML::CalendarMonth->new( month => 3, year => 69 );
 $c->item($c->year, $c->month)->attr(bgcolor => 'wheat');
 $c->item($c->year, $c->month)->wrap_content(font({size => '+2'}));
 $c->item(12, 16, 28)->wrap_content(strong());
 print $c->as_HTML;

 # Using regular HTML::Element creation
 $c2 = HTML::CalendarMonth->new( month => 8, year => 79 );
 $c2->item($c2->year, $c2->month)->attr(bgcolor => 'wheat');
 $f = HTML::Element->new('font', size => '+2');
 $c2->item($c2->year, $c2->month)->wrap_content($f);
 $c2->item_daycol('Su', 'Sa')->attr(bgcolor => 'cyan');
 print $c2->as_HTML;

 # Full locale support via DateTime::Locale
 $c3 HTML::CalendarMonth->new( month => 8, year => 79, locale => 'fr' );
 print $c3->as_HTML

DESCRIPTION

HTML::CalendarMonth is a subclass of HTML::ElementTable. See HTML::ElementTable(3) for how that class works, for it affects this module on many levels. Like HTML::ElementTable, HTML::CalendarMonth behaves as if it were an HTML::ElementSuper, which is a regular HTML::Element with methods added to easily manipulate the appearance of the HTML table containing the calendar.

The primary interaction with HTML::CalendarMonth is through items. An item is merely a symbol that represents the content of the cell of interest within the calendar. For instance, the element representing the 14th day of the month would be returned by $c->item(14). Similarly, the element representing the header for Monday would be returned by $c->item('Mo'). If the year happened to by 1984, then $c->item(1984) would return the cell representing the year. Since years and particular months change frequently, it is probably more useful to take advantage of the month() and year() methods, which return the respective item symbol for the current calendar. In the prior example, using 1984, the following is equivalent: $c->item($c- >year()).

Multiple cells of the calendar can be manipulated as if they were a single element. For instance, $c->item(15)->attr(bgcolor => 'cyan') would alter the background color of the cell representing the 15th. By the same token, $c->item(15, 16, 17, 23)->attr(bgcolor => 'cyan') would do the same thing for all cells containing the item symbols passed to the item() method.

The calendar structure is still nothing more than a table structure; the same table structure provided by the HTML::ElementTable class. In addition to the item based access methods above, calendar cells can still be accessed using row and column grid coordinates using the cell() method provided by the table class. All coordinate-based methods in the table class are accessible to the calendar class.

The module includes support for week-of-the-year numbering, arbitrary 1st day of the week definitions, and aliasing so that you can express any element in any language HTML can handle.

Dates that are beyond the range of the built-in time functions of perl are handled either by the ncal/cal command, Date::Calc, or Date::Manip. The presence of any one of these utilities and modules will suffice for these far flung date calculations. If you want to use week-of-year numbering, then ncal or either one of the date modules is required.

Full locale support is offered via DateTime::Locale. For a full list of supported locale id's, look at HTML::CalendarMonth::Locale->locales() or DateTime::Locale->ids().

METHODS

All arguments appearing in [brackets] are optional, and do not represent anonymous array references.

    Constructor

    new()

    With no arguments, the constructor will return a calendar object representing the current month with a default appearance. The initial configuration of the calendar is controlled by special attributes. Non- calendar related attributes are passed along to HTML::ElementTable. Any non-table related attributes left after that are passed to HTML::Element while constructing the <table> tag. See HTML::ElementTable if you are interested in attributes that can be passed along to that class.

    Special Attributes for HTML::CalendarMonth:

    month

    1-12, or Jan-Dec. Defaults to current month.

    year

    Four digit representation. Defaults to current year.

    head_m

    Specifies whether to display the month header. Default 1.

    head_y

    Specifies whether to display the year header. Default 1.

    head_dow

    Specifies whether to display days of the week header. Default 1.

    locale

    Specifies a locale in which to render the calendar. Default is 'en_US'. See HTML::CalendarMonth::Locale for more information. If for some reason you prefer to use different labels than those provided by locale, see the alias attribute below.

    full_days

    Specifies whether or not to use full day names or their abbreviated names. Default is 0, use abbreviated names. Use -1 for 'narrow' mode, the shortest (not guaranteed to be unique) abbreviations.

    full_months

    Specifies whether or not to use full month names or their abbriviated names. Default is 1, use full names. Use -1 for 'narrow' mode, the shortest (not guaranteed to be unique) abbreviations.

    alias

    Takes a hash reference mapping labels provided by locale to any custom label you prefer. Lookups, such as day('Sun'), will still use the locale string, but when the calendar is rendered the aliased value will appear.

    head_week

    Specifies whether to display the week-of-year numbering. Default 0.

    week_begin

    Specify first day of the week, which can be 1..7, starting with Sunday. Defaults to 1, or Sunday. In order to specify Monday, set this to 2, and so on. By default, this is determined based on the locale.

    enable_css

    Set some handy CSS class attributes on elements, enabled by default. Currently the classes are:

      hcm-table       Set on the <lt>table<gt> tag of the calendar
      hcm-day-head    Set on the day-of-week <lt>tr<gt> or <lt>td<gt> tags
      hcm-year-head   Set on the <lt>td<gt> tag for the year
      hcm-month-head  Set on the <lt>td<gt> tag for the month
      hcm-week-head   Set on the <lt>td<gt> tags for the week-of-year
    semantic_css

    Sets some additional CSS class attributes on elements, disabled by default. The notion of 'today' is taken either from the system clock (default) or from the 'today' parameter as provided to new(). Currently these classes are:

      hcm-today    Set on the <lt>td<gt> tag for today, if present
      hcm-past     Set on the <lt>td<gt> tags for prior days, if present
      hcm-future   Set on the <lt>td<gt> tags for subsequent days, if present
    historic

    This option is ignored for dates that do not exceed the range of the built- in perl time functions. For dates that do exceed these ranges, this option specifies the default calculation method. When set, if the 'ncal' or 'cal' command is available on your system, that will be used rather than the Date::Calc or Date::Manip modules. This can be an issue since the date modules blindly extrapolate the Gregorian calendar, whereas ncal/cal will revert to the Julian calendar during September 1752. If either ncal or cal are not available on your system, this attribute is meaningless. Defaults to 1.

Item Query Methods

The following methods return lists of item *symbols* (28, 29, 'Thu', ...) that are related in some way to the provided list of items. The returned symbols may then be used as arguments to the glob methods detailed further below.

row_items(item1, [item2, ...])

Returns all item symbols in rows shared by the provided item symbols.

col_items(item1, [item2, ...])

Returns all item symbols in columns shared by the provided item symbols.

daycol_items(col_item1, [col_item2, ...])

Same as col_items(), but the returned item symbols are limited to those that are not header items (month, year, day-of-week).

row_of(item1, [item2, ...])

Returns the row indices of rows containing the provided item symbols.

col_of(item1, [item2, ...])

Returns the column indices of columns containing the provided item symbols.

lastday()

Returns the day number (symbol) of the last day of the month.

dow1st()

Returns the column index for the first day of the month.

days()

Returns a list of all days of the month as numbers.

dayheaders()

Returns a list of all day headers (Su..Sa)

headers()

Returns a list of all headers (month, year, dayheaders)

items()

Returns a list of all item symbols (day number, header values) in the calendar.

first_col()

Returns the index of the first column of the calendar. This is always 0.

last_col()

Returns the index of the last column of the calendar (note that this could be the week-of-year column if head_week is enabled).

first_row()

Returns the index of the first row of the calendar. This is always 0.

first_week_row()

Returns the index of the first row of the calendar containing day items (ie, the first week). This could vary depending on header modes.

last_row()

Returns the index of the last row of the calendar.

Glob Methods

Glob methods return references that are functionally equivalent to an individual calendar cell. Mostly, they provide item based analogues to the glob methods provided in HTML::ElementTable. In methods dealing with rows, columns, and boxes, the globs include empty calendar cells (which would otherwise need to be accessed through native HTML::ElementTable methods). The row and column numbers returned by the item methods above are compatible with the grid based methods in HTML::ElementTable.

For details on how these globs work, check out HTML::ElementTable and HTML::ElementGlob.

item(item1, [item2, ...])

Returns all cells containing the provided item symbols.

item_row(item1, [item2, ...])

Returns all cells in all rows occupied by the provided item symbols.

item_col(item1, [item2, ...])

Returns all cells in all columns occupied by the provided item symbols.

item_daycol(item1, [item2, ...])

Same as item_col(), except limits the cells to non header cells.

item_box(item1a, item1b, [item2a, item2b, ...])

Returns all cells in the boxes defined by the item pairs provided.

allheaders()

Returns all header cells.

alldays()

Returns all non header cells, including empty cells.

all()

Returns all cells in the calendar, including empty cells.

Transformation Methods

The following methods provide ways of translating between various item symbols, coordinates, and other representations.

coords_of(item)

Returns the row and column coordinates of the provided item symbol, for use with the grid based methods in HTML::ElementTable.

item_at(row,column)

Returns the item symbol of the item at the provided coordinates, for use with the item based methods of HTML::CalendarMonth.

monthname(monthnum)

Returns the name (item symbol) of the month number provided, where monthnum can be 1..12.

monthnum(monthname)

Returns the number (1..12) of the month name provided. Only a minimal case-insensitive match on the month name is necessary; the proper item symbol for the month will be determined from this match.

dayname(daynum)

Returns the name (item symbol) of the day of week header for a number of a day of the week, where daynum is 1..7.

daynum(dayname)

Returns the number of the day of the week given the symbolic name for that day (Su..Sa).

daytime(day)

Returns the number in seconds since the epoch for a given day. The day must be present in the current calendar.

Transformation Methods

default_css()

Returns a simple style sheet as a string that can be used in an HTML document in conjunction with the classes assigned to elements when css is enabled.

REQUIRES

HTML::ElementTable

OPTIONAL

Date::Calc, DateTime, or Date::Manip (only if you want week-of- year numbering or non-contemporary dates on a system without the cal command)

AUTHOR

Matthew P. Sisk, <sisk@mojotoad.com>

COPYRIGHT

Copyright (c) 1998-2010 Matthew P. Sisk. All rights reserved. All wrongs revenged. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

A useful page of examples can be found at http://www.mojotoad.com/sisk/projects/HTML-CalendarMonth.

For information on iso639 standards for abbreviations for language names, see http://www.loc.gov/standards/iso639-2/englangn.html

HTML::ElementTable(3), HTML::Element(3), perl(1)

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 1068:

You can't have =items (as at line 1072) unless the first thing after the =over is an =item

Around line 1364:

You forgot a '=back' before '=head1'