=for advent_year 2007 =for advent_day 17 =for advent_title Subclassing all the way! =for advent_author David Westbrook These Perl Advent Calendar submissions have specific formatting guidelines,N<1> which need to be adhered to by the authors, or done by the editors in time-comsuming second passes. Using MN<2> and following the guidelines in the M documentation, a simple text format in A can be defined for authors.N<3> The first items we want to address and make easy are the use of F<<tt>> for file, module, and program names, the use of F for code samples, and the whole header section, including title, author, and css.N<4> The easiest is the POD F tag, where we use the C<_handle_element_start()> and C<_handle_element_end()> methods to simply insert F<<tt>> and F<</tt>> tags, respectively, for the C<$element_name eq 'F'> case (lines 43-44, 88-89). Implementing the F and F codes follows the exact same model (lines 45-46, 90-91). Now, module names are a step more, because we want them to be hyperlinked to thier CPAN search results. For this, we define our code custom POD code of F with the C method (line 21). We have this behave the same as F, with the addition of a case in the C<_handle_text()> method that changes the string from just the text to a HTML hyperlink (lines 125-126). Any I (indented) text in POD we want to treat as code, and have automatically follow the F guideline. For this, we have a case in the C<_handle_text()> method for C<$element_name eq 'Verbatim'> that passes the text through MF<::perltidy> with the C<-html -pre> options (lines 99-107). The tricky ones are setting the title and author fields. This is because they can't simply be written out in the order they are found in the POD source; e.g. the title appears twice -- once in the F<<title>> tag and once in a F<<h1>> tag, and both of those, and the author name, comprise the whole HTML header (lines 65-76) along with some static markup such as the F<<html>>, F<<head>>, F<<body>>, and F<<style>> tags. So the approach is to use the C method (line 22) to declare several C<=for advent_KEY VALUE> tags to use for setting the various pieces of information. We note via a C<$section> package variable whenever we come upon one of these in the C<_handle_element_start()> method (lines 47-48). Then the next C<_handle_text()> run for C<$element_name eq 'Para'> will use the text to set C<$data{$section}> instead of appending it to the output (lines 118-120). So this will populate a data hash as the source is processed. What then ties everything together and does the actual output is the C<$element_name eq 'Document'> case in the C<_handle_element_end()> method (lines 58-78). use mod17a; my $advent = mod17a->new; $advent->parse_file( \*STDIN ); =sourcedcode mod17a.pm 1. See the A 2. "Normally we'd say something on Phalanx 100 (or core) was too well known; but a self-referential piece on a non obvious usage is within house style twice." -Bill 3. Full examples can be seen for days A<../1|1>/A<../mod1.pod|.pod>, A<../8|8>/A<../mod8.pod|.pod>, A<../16|16>/A<../mod16.pod|.pod>, and this (17) entry's A. 4. Watch for M to be released on CPAN with a fuller feature set, documentation, and a F script.