HTML::Pen::Iterator - Creating a calendar using a Pen Iterator
<: &do( 'festival.pl' )> <: &iterator( *events, $festival )> <: &iterator( *active, $$festival[1] )> <: &block( *HEADER, 'endblock' )> <td class="calendarHeader"> <: &iteratorValue( *active, 'weekday' )> </td> endblock <: &block( *WEEK, 'endblock' )> <tr> <: &undef( $#$events = 6 )> <: &iterate( *events, @DAY )> </tr> endblock <: &block( *DAY, 'endblock' )> <td class="calendar"> <div class="calendar"> <div class="calendarDate"> <: &iteratorValue( *events, 'monthday' )> </div> <: &iterate( *events, @HOUR )> </div> </td> endblock <: &block( *HOUR, 'endblock' )> <div class="calendarHour"><: &iteratorValue( *events, 'timedisplay' )></div> <: &iterate( *events, @EVENT )> endblock <: &block( *EVENT, 'endblock' )> <div class="calendarEvent"><: &iteratorValue( *events,'event' )></div> endblock <!--: &comment() content starts here --> <table class="calendar" cellspacing="0"> <tr> <td colspan="7" class="monthName"> <: &iteratorValue( *active, 'monthname' )> <: &iteratorValue( *active, 'year' )> </td> </tr> <tr> <: &iterate( *active, @HEADER )> </tr> <: &iterate( *events, @WEEK )> </table>
This code generates an HTML table representing an event calendar.
Here's a quick walkthrough of the Pen code:
$festival, defined in festival.pl, (see HTML::Pen::Iterator::Example) is a reference to a four dimensional array. It's structure is defined as:
$festival
festival.pl
\@weeks -> \@days -> \@times -> \@events -> \%eventobjects
$festival data is represented by the iterator *events, which contains five weeks. The first complete week, $festival->[1], is represented by seven days in the *active iterator. This iterator is used to look up the monthname and weekday name properties.
*events
$festival->[1]
*active
The @HEADER block, which display the weekday nmes in the second row, is not recursive. The @WEEK block, which displays the remaining five rows, is recursive to four blocks deep.
@WEEK -> @DAY -> @HOUR -> @EVENT
http://www.tqis.com/pen/misc/iterator.htm
Jim Schueler, <jim@tqis.com>
Copyright (C) 2011 by Jim Schueler
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.9 or, at your option, any later version of Perl 5 you may have available.
To install HTML::Pen, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::Pen
CPAN shell
perl -MCPAN -e shell install HTML::Pen
For more information on module installation, please visit the detailed CPAN module installation guide.