1=head1 NAME 2 3Pod::Simple::Subclassing -- write a formatter as a Pod::Simple subclass 4 5=head1 SYNOPSIS 6 7 package Pod::SomeFormatter; 8 use Pod::Simple; 9 @ISA = qw(Pod::Simple); 10 $VERSION = '1.01'; 11 use strict; 12 13 sub _handle_element_start { 14 my($parser, $element_name, $attr_hash_r) = @_; 15 ... 16 } 17 18 sub _handle_element_end { 19 my($parser, $element_name, $attr_hash_r) = @_; 20 # NOTE: $attr_hash_r is only present when $element_name is "over" or "begin" 21 # The remaining code excerpts will mostly ignore this $attr_hash_r, as it is 22 # mostly useless. It is documented where "over-*" and "begin" events are 23 # documented. 24 ... 25 } 26 27 sub _handle_text { 28 my($parser, $text) = @_; 29 ... 30 } 31 1; 32 33=head1 DESCRIPTION 34 35This document is about using Pod::Simple to write a Pod processor, 36generally a Pod formatter. If you just want to know about using an 37existing Pod formatter, instead see its documentation and see also the 38docs in L<Pod::Simple>. 39 40B<The zeroeth step> in writing a Pod formatter is to make sure that there 41isn't already a decent one in CPAN. See L<http://search.cpan.org/>, and 42run a search on the name of the format you want to render to. Also 43consider joining the Pod People list 44L<http://lists.perl.org/showlist.cgi?name=pod-people> and asking whether 45anyone has a formatter for that format -- maybe someone cobbled one 46together but just hasn't released it. 47 48B<The first step> in writing a Pod processor is to read L<perlpodspec>, 49which contains information on writing a Pod parser (which has been 50largely taken care of by Pod::Simple), but also a lot of requirements 51and recommendations for writing a formatter. 52 53B<The second step> is to actually learn the format you're planning to 54format to -- or at least as much as you need to know to represent Pod, 55which probably isn't much. 56 57B<The third step> is to pick which of Pod::Simple's interfaces you want to 58use: 59 60=over 61 62=item Pod::Simple 63 64The basic L<Pod::Simple> interface that uses C<_handle_element_start()>, 65C<_handle_element_end()> and C<_handle_text()>. 66 67=item Pod::Simple::Methody 68 69The L<Pod::Simple::Methody> interface is event-based, similar to that of 70L<HTML::Parser> or L<XML::Parser>'s "Handlers". 71 72=item Pod::Simple::PullParser 73 74L<Pod::Simple::PullParser> provides a token-stream interface, sort of 75like L<HTML::TokeParser>'s interface. 76 77=item Pod::Simple::SimpleTree 78 79L<Pod::Simple::SimpleTree> provides a simple tree interface, rather like 80L<XML::Parser>'s "Tree" interface. Users familiar with XML handling will 81be comfortable with this interface. Users interested in outputting XML, 82should look into the modules that produce an XML representation of the 83Pod stream, notably L<Pod::Simple::XMLOutStream>; you can feed the output 84of such a class to whatever XML parsing system you are most at home with. 85 86=back 87 88B<The last step> is to write your code based on how the events (or tokens, 89or tree-nodes, or the XML, or however you're parsing) will map to 90constructs in the output format. Also be sure to consider how to escape 91text nodes containing arbitrary text, and what to do with text 92nodes that represent preformatted text (from verbatim sections). 93 94 95 96=head1 Events 97 98TODO intro... mention that events are supplied for implicits, like for 99missing >'s 100 101In the following section, we use XML to represent the event structure 102associated with a particular construct. That is, an opening tag 103represents the element start, the attributes of that opening tag are 104the attributes given to the callback, and the closing tag represents 105the end element. 106 107Three callback methods must be supplied by a class extending 108L<Pod::Simple> to receive the corresponding event: 109 110=over 111 112=item C<< $parser->_handle_element_start( I<element_name>, I<attr_hashref> ) >> 113 114=item C<< $parser->_handle_element_end( I<element_name> ) >> 115 116=item C<< $parser->_handle_text( I<text_string> ) >> 117 118=back 119 120Here's the comprehensive list of values you can expect as 121I<element_name> in your implementation of C<_handle_element_start> 122and C<_handle_element_end>:: 123 124=over 125 126=item events with an element_name of Document 127 128Parsing a document produces this event structure: 129 130 <Document start_line="543"> 131 ...all events... 132 </Document> 133 134The value of the I<start_line> attribute will be the line number of the first 135Pod directive in the document. 136 137If there is no Pod in the given document, then the 138event structure will be this: 139 140 <Document contentless="1" start_line="543"> 141 </Document> 142 143In that case, the value of the I<start_line> attribute will not be meaningful; 144under current implementations, it will probably be the line number of the 145last line in the file. 146 147=item events with an element_name of Para 148 149Parsing a plain (non-verbatim, non-directive, non-data) paragraph in 150a Pod document produces this event structure: 151 152 <Para start_line="543"> 153 ...all events in this paragraph... 154 </Para> 155 156The value of the I<start_line> attribute will be the line number of the start 157of the paragraph. 158 159For example, parsing this paragraph of Pod: 160 161 The value of the I<start_line> attribute will be the 162 line number of the start of the paragraph. 163 164produces this event structure: 165 166 <Para start_line="129"> 167 The value of the 168 <I> 169 start_line 170 </I> 171 attribute will be the line number of the first Pod directive 172 in the document. 173 </Para> 174 175=item events with an element_name of B, C, F, or I. 176 177Parsing a BE<lt>...E<gt> formatting code (or of course any of its 178semantically identical syntactic variants 179S<BE<lt>E<lt> ... E<gt>E<gt>>, 180or S<BE<lt>E<lt>E<lt>E<lt> ... E<gt>E<gt>E<gt>E<gt>>, etc.) 181produces this event structure: 182 183 <B> 184 ...stuff... 185 </B> 186 187Currently, there are no attributes conveyed. 188 189Parsing C, F, or I codes produce the same structure, with only a 190different element name. 191 192If your parser object has been set to accept other formatting codes, 193then they will be presented like these B/C/F/I codes -- i.e., without 194any attributes. 195 196=item events with an element_name of S 197 198Normally, parsing an SE<lt>...E<gt> sequence produces this event 199structure, just as if it were a B/C/F/I code: 200 201 <S> 202 ...stuff... 203 </S> 204 205However, Pod::Simple (and presumably all derived parsers) offers the 206C<nbsp_for_S> option which, if enabled, will suppress all S events, and 207instead change all spaces in the content to non-breaking spaces. This is 208intended for formatters that output to a format that has no code that 209means the same as SE<lt>...E<gt>, but which has a code/character that 210means non-breaking space. 211 212=item events with an element_name of X 213 214Normally, parsing an XE<lt>...E<gt> sequence produces this event 215structure, just as if it were a B/C/F/I code: 216 217 <X> 218 ...stuff... 219 </X> 220 221However, Pod::Simple (and presumably all derived parsers) offers the 222C<nix_X_codes> option which, if enabled, will suppress all X events 223and ignore their content. For formatters/processors that don't use 224X events, this is presumably quite useful. 225 226 227=item events with an element_name of L 228 229Because the LE<lt>...E<gt> is the most complex construct in the 230language, it should not surprise you that the events it generates are 231the most complex in the language. Most of complexity is hidden away in 232the attribute values, so for those of you writing a Pod formatter that 233produces a non-hypertextual format, you can just ignore the attributes 234and treat an L event structure like a formatting element that 235(presumably) doesn't actually produce a change in formatting. That is, 236the content of the L event structure (as opposed to its 237attributes) is always what text should be displayed. 238 239There are, at first glance, three kinds of L links: URL, man, and pod. 240 241When a LE<lt>I<some_url>E<gt> code is parsed, it produces this event 242structure: 243 244 <L content-implicit="yes" raw="that_url" to="that_url" type="url"> 245 that_url 246 </L> 247 248The C<type="url"> attribute is always specified for this type of 249L code. 250 251For example, this Pod source: 252 253 L<http://www.perl.com/CPAN/authors/> 254 255produces this event structure: 256 257 <L content-implicit="yes" raw="http://www.perl.com/CPAN/authors/" to="http://www.perl.com/CPAN/authors/" type="url"> 258 http://www.perl.com/CPAN/authors/ 259 </L> 260 261When a LE<lt>I<manpage(section)>E<gt> code is parsed (and these are 262fairly rare and not terribly useful), it produces this event structure: 263 264 <L content-implicit="yes" raw="manpage(section)" to="manpage(section)" type="man"> 265 manpage(section) 266 </L> 267 268The C<type="man"> attribute is always specified for this type of 269L code. 270 271For example, this Pod source: 272 273 L<crontab(5)> 274 275produces this event structure: 276 277 <L content-implicit="yes" raw="crontab(5)" to="crontab(5)" type="man"> 278 crontab(5) 279 </L> 280 281In the rare cases where a man page link has a section specified, that text appears 282in a I<section> attribute. For example, this Pod source: 283 284 L<crontab(5)/"ENVIRONMENT"> 285 286will produce this event structure: 287 288 <L content-implicit="yes" raw="crontab(5)/"ENVIRONMENT"" section="ENVIRONMENT" to="crontab(5)" type="man"> 289 "ENVIRONMENT" in crontab(5) 290 </L> 291 292In the rare case where the Pod document has code like 293LE<lt>I<sometext>|I<manpage(section)>E<gt>, then the I<sometext> will appear 294as the content of the element, the I<manpage(section)> text will appear 295only as the value of the I<to> attribute, and there will be no 296C<content-implicit="yes"> attribute (whose presence means that the Pod parser 297had to infer what text should appear as the link text -- as opposed to 298cases where that attribute is absent, which means that the Pod parser did 299I<not> have to infer the link text, because that L code explicitly specified 300some link text.) 301 302For example, this Pod source: 303 304 L<hell itself!|crontab(5)> 305 306will produce this event structure: 307 308 <L raw="hell itself!|crontab(5)" to="crontab(5)" type="man"> 309 hell itself! 310 </L> 311 312The last type of L structure is for links to/within Pod documents. It is 313the most complex because it can have a I<to> attribute, I<or> a 314I<section> attribute, or both. The C<type="pod"> attribute is always 315specified for this type of L code. 316 317In the most common case, the simple case of a LE<lt>podpageE<gt> code 318produces this event structure: 319 320 <L content-implicit="yes" raw="podpage" to="podpage" type="pod"> 321 podpage 322 </L> 323 324For example, this Pod source: 325 326 L<Net::Ping> 327 328produces this event structure: 329 330 <L content-implicit="yes" raw="Net::Ping" to="Net::Ping" type="pod"> 331 Net::Ping 332 </L> 333 334In cases where there is link-text explicitly specified, it 335is to be found in the content of the element (and not the 336attributes), just as with the LE<lt>I<sometext>|I<manpage(section)>E<gt> 337case discussed above. For example, this Pod source: 338 339 L<Perl Error Messages|perldiag> 340 341produces this event structure: 342 343 <L raw="Perl Error Messages|perldiag" to="perldiag" type="pod"> 344 Perl Error Messages 345 </L> 346 347In cases of links to a section in the current Pod document, 348there is a I<section> attribute instead of a I<to> attribute. 349For example, this Pod source: 350 351 L</"Member Data"> 352 353produces this event structure: 354 355 <L content-implicit="yes" raw="/"Member Data"" section="Member Data" type="pod"> 356 "Member Data" 357 </L> 358 359As another example, this Pod source: 360 361 L<the various attributes|/"Member Data"> 362 363produces this event structure: 364 365 <L raw="the various attributes|/"Member Data"" section="Member Data" type="pod"> 366 the various attributes 367 </L> 368 369In cases of links to a section in a different Pod document, 370there are both a I<section> attribute and a L<to> attribute. 371For example, this Pod source: 372 373 L<perlsyn/"Basic BLOCKs and Switch Statements"> 374 375produces this event structure: 376 377 <L content-implicit="yes" raw="perlsyn/"Basic BLOCKs and Switch Statements"" section="Basic BLOCKs and Switch Statements" to="perlsyn" type="pod"> 378 "Basic BLOCKs and Switch Statements" in perlsyn 379 </L> 380 381As another example, this Pod source: 382 383 L<SWITCH statements|perlsyn/"Basic BLOCKs and Switch Statements"> 384 385produces this event structure: 386 387 <L raw="SWITCH statements|perlsyn/"Basic BLOCKs and Switch Statements"" section="Basic BLOCKs and Switch Statements" to="perlsyn" type="pod"> 388 SWITCH statements 389 </L> 390 391Incidentally, note that we do not distinguish between these syntaxes: 392 393 L</"Member Data"> 394 L<"Member Data"> 395 L</Member Data> 396 L<Member Data> [deprecated syntax] 397 398That is, they all produce the same event structure (for the most part), namely: 399 400 <L content-implicit="yes" raw="$depends_on_syntax" section="Member Data" type="pod"> 401 "Member Data" 402 </L> 403 404The I<raw> attribute depends on what the raw content of the C<LE<lt>E<gt>> is, 405so that is why the event structure is the same "for the most part". 406 407If you have not guessed it yet, the I<raw> attribute contains the raw, 408original, unescaped content of the C<LE<lt>E<gt>> formatting code. In addition 409to the examples above, take notice of the following event structure produced 410by the following C<LE<lt>E<gt>> formatting code. 411 412 L<click B<here>|page/About the C<-M> switch> 413 414 <L raw="click B<here>|page/About the C<-M> switch" section="About the -M switch" to="page" type="pod"> 415 click B<here> 416 </L> 417 418Specifically, notice that the formatting codes are present and unescaped 419in I<raw>. 420 421There is a known bug in the I<raw> attribute where any surrounding whitespace 422is condensed into a single ' '. For example, given LE<60> linkE<62>, I<raw> 423will be " link". 424 425=item events with an element_name of E or Z 426 427While there are Pod codes EE<lt>...E<gt> and ZE<lt>E<gt>, these 428I<do not> produce any E or Z events -- that is, there are no such 429events as E or Z. 430 431=item events with an element_name of Verbatim 432 433When a Pod verbatim paragraph (AKA "codeblock") is parsed, it 434produces this event structure: 435 436 <Verbatim start_line="543" xml:space="preserve"> 437 ...text... 438 </Verbatim> 439 440The value of the I<start_line> attribute will be the line number of the 441first line of this verbatim block. The I<xml:space> attribute is always 442present, and always has the value "preserve". 443 444The text content will have tabs already expanded. 445 446 447=item events with an element_name of head1 .. head4 448 449When a "=head1 ..." directive is parsed, it produces this event 450structure: 451 452 <head1> 453 ...stuff... 454 </head1> 455 456For example, a directive consisting of this: 457 458 =head1 Options to C<new> et al. 459 460will produce this event structure: 461 462 <head1 start_line="543"> 463 Options to 464 <C> 465 new 466 </C> 467 et al. 468 </head1> 469 470"=head2" through "=head4" directives are the same, except for the element 471names in the event structure. 472 473=item events with an element_name of encoding 474 475In the default case, the events corresponding to C<=encoding> directives 476are not emitted. They are emitted if C<keep_encoding_directive> is true. 477In that case they produce event structures like 478L</"events with an element_name of head1 .. head4"> above. 479 480=item events with an element_name of over-bullet 481 482When an "=over ... Z<>=back" block is parsed where the items are 483a bulleted list, it will produce this event structure: 484 485 <over-bullet indent="4" start_line="543"> 486 <item-bullet start_line="545"> 487 ...Stuff... 488 </item-bullet> 489 ...more item-bullets... 490 </over-bullet fake-closer="1"> 491 492The attribute I<fake-closer> is only present if it is a true value; it is not 493present if it is a false value. It is shown in the above example to illustrate 494where the attribute is (in the B<closing> tag). It signifies that the C<=over> 495did not have a matching C<=back>, and thus Pod::Simple had to create a fake 496closer. 497 498For example, this Pod source: 499 500 =over 501 502 =item * 503 504 Something 505 506 =back 507 508Would produce an event structure that does B<not> have the I<fake-closer> 509attribute, whereas this Pod source: 510 511 =over 512 513 =item * 514 515 Gasp! An unclosed =over block! 516 517would. The rest of the over-* examples will not demonstrate this attribute, 518but they all can have it. See L<Pod::Checker>'s source for an example of this 519attribute being used. 520 521The value of the I<indent> attribute is whatever value is after the 522"=over" directive, as in "=over 8". If no such value is specified 523in the directive, then the I<indent> attribute has the value "4". 524 525For example, this Pod source: 526 527 =over 528 529 =item * 530 531 Stuff 532 533 =item * 534 535 Bar I<baz>! 536 537 =back 538 539produces this event structure: 540 541 <over-bullet indent="4" start_line="10"> 542 <item-bullet start_line="12"> 543 Stuff 544 </item-bullet> 545 <item-bullet start_line="14"> 546 Bar <I>baz</I>! 547 </item-bullet> 548 </over-bullet> 549 550=item events with an element_name of over-number 551 552When an "=over ... Z<>=back" block is parsed where the items are 553a numbered list, it will produce this event structure: 554 555 <over-number indent="4" start_line="543"> 556 <item-number number="1" start_line="545"> 557 ...Stuff... 558 </item-number> 559 ...more item-number... 560 </over-bullet> 561 562This is like the "over-bullet" event structure; but note that the contents 563are "item-number" instead of "item-bullet", and note that they will have 564a "number" attribute, which some formatters/processors may ignore 565(since, for example, there's no need for it in HTML when producing 566an "<UL><LI>...</LI>...</UL>" structure), but which any processor may use. 567 568Note that the values for the I<number> attributes of "item-number" 569elements in a given "over-number" area I<will> start at 1 and go up by 570one each time. If the Pod source doesn't follow that order (even though 571it really should!), whatever numbers it has will be ignored (with 572the correct values being put in the I<number> attributes), and an error 573message might be issued to the user. 574 575=item events with an element_name of over-text 576 577These events are somewhat unlike the other over-* 578structures, as far as what their contents are. When 579an "=over ... Z<>=back" block is parsed where the items are 580a list of text "subheadings", it will produce this event structure: 581 582 <over-text indent="4" start_line="543"> 583 <item-text> 584 ...stuff... 585 </item-text> 586 ...stuff (generally Para or Verbatim elements)... 587 <item-text> 588 ...more item-text and/or stuff... 589 </over-text> 590 591The I<indent> and I<fake-closer> attributes are as with the other over-* events. 592 593For example, this Pod source: 594 595 =over 596 597 =item Foo 598 599 Stuff 600 601 =item Bar I<baz>! 602 603 Quux 604 605 =back 606 607produces this event structure: 608 609 <over-text indent="4" start_line="20"> 610 <item-text start_line="22"> 611 Foo 612 </item-text> 613 <Para start_line="24"> 614 Stuff 615 </Para> 616 <item-text start_line="26"> 617 Bar 618 <I> 619 baz 620 </I> 621 ! 622 </item-text> 623 <Para start_line="28"> 624 Quux 625 </Para> 626 </over-text> 627 628 629 630=item events with an element_name of over-block 631 632These events are somewhat unlike the other over-* 633structures, as far as what their contents are. When 634an "=over ... Z<>=back" block is parsed where there are no items, 635it will produce this event structure: 636 637 <over-block indent="4" start_line="543"> 638 ...stuff (generally Para or Verbatim elements)... 639 </over-block> 640 641The I<indent> and I<fake-closer> attributes are as with the other over-* events. 642 643For example, this Pod source: 644 645 =over 646 647 For cutting off our trade with all parts of the world 648 649 For transporting us beyond seas to be tried for pretended offenses 650 651 He is at this time transporting large armies of foreign mercenaries to 652 complete the works of death, desolation and tyranny, already begun with 653 circumstances of cruelty and perfidy scarcely paralleled in the most 654 barbarous ages, and totally unworthy the head of a civilized nation. 655 656 =back 657 658will produce this event structure: 659 660 <over-block indent="4" start_line="2"> 661 <Para start_line="4"> 662 For cutting off our trade with all parts of the world 663 </Para> 664 <Para start_line="6"> 665 For transporting us beyond seas to be tried for pretended offenses 666 </Para> 667 <Para start_line="8"> 668 He is at this time transporting large armies of [...more text...] 669 </Para> 670 </over-block> 671 672=item events with an element_name of over-empty 673 674B<Note: These events are only triggered if C<parse_empty_lists()> is set to a 675true value.> 676 677These events are somewhat unlike the other over-* structures, as far as what 678their contents are. When an "=over ... Z<>=back" block is parsed where there 679is no content, it will produce this event structure: 680 681 <over-empty indent="4" start_line="543"> 682 </over-empty> 683 684The I<indent> and I<fake-closer> attributes are as with the other over-* events. 685 686For example, this Pod source: 687 688 =over 689 690 =over 691 692 =back 693 694 =back 695 696will produce this event structure: 697 698 <over-block indent="4" start_line="1"> 699 <over-empty indent="4" start_line="3"> 700 </over-empty> 701 </over-block> 702 703Note that the outer C<=over> is a block because it has no C<=item>s but still 704has content: the inner C<=over>. The inner C<=over>, in turn, is completely 705empty, and is treated as such. 706 707=item events with an element_name of item-bullet 708 709See L</"events with an element_name of over-bullet">, above. 710 711=item events with an element_name of item-number 712 713See L</"events with an element_name of over-number">, above. 714 715=item events with an element_name of item-text 716 717See L</"events with an element_name of over-text">, above. 718 719=item events with an element_name of for 720 721TODO... 722 723=item events with an element_name of Data 724 725TODO... 726 727=back 728 729 730 731=head1 More Pod::Simple Methods 732 733Pod::Simple provides a lot of methods that aren't generally interesting 734to the end user of an existing Pod formatter, but some of which you 735might find useful in writing a Pod formatter. They are listed below. The 736first several methods (the accept_* methods) are for declaring the 737capabilities of your parser, notably what C<=for I<targetname>> sections 738it's interested in, what extra NE<lt>...E<gt> codes it accepts beyond 739the ones described in the I<perlpod>. 740 741=over 742 743=item C<< $parser->accept_targets( I<SOMEVALUE> ) >> 744 745As the parser sees sections like: 746 747 =for html <img src="fig1.jpg"> 748 749or 750 751 =begin html 752 753 <img src="fig1.jpg"> 754 755 =end html 756 757...the parser will ignore these sections unless your subclass has 758specified that it wants to see sections targeted to "html" (or whatever 759the formatter name is). 760 761If you want to process all sections, even if they're not targeted for you, 762call this before you start parsing: 763 764 $parser->accept_targets('*'); 765 766=item C<< $parser->accept_targets_as_text( I<SOMEVALUE> ) >> 767 768This is like accept_targets, except that it specifies also that the 769content of sections for this target should be treated as Pod text even 770if the target name in "=for I<targetname>" doesn't start with a ":". 771 772At time of writing, I don't think you'll need to use this. 773 774 775=item C<< $parser->accept_codes( I<Codename>, I<Codename>... ) >> 776 777This tells the parser that you accept additional formatting codes, 778beyond just the standard ones (I B C L F S X, plus the two weird ones 779you don't actually see in the parse tree, Z and E). For example, to also 780accept codes "N", "R", and "W": 781 782 $parser->accept_codes( qw( N R W ) ); 783 784B<TODO: document how this interacts with =extend, and long element names> 785 786 787=item C<< $parser->accept_directive_as_data( I<directive_name> ) >> 788 789=item C<< $parser->accept_directive_as_verbatim( I<directive_name> ) >> 790 791=item C<< $parser->accept_directive_as_processed( I<directive_name> ) >> 792 793In the unlikely situation that you need to tell the parser that you will 794accept additional directives ("=foo" things), you need to first set the 795parser to treat its content as data (i.e., not really processed at 796all), or as verbatim (mostly just expanding tabs), or as processed text 797(parsing formatting codes like BE<lt>...E<gt>). 798 799For example, to accept a new directive "=method", you'd presumably 800use: 801 802 $parser->accept_directive_as_processed("method"); 803 804so that you could have Pod lines like: 805 806 =method I<$whatever> thing B<um> 807 808Making up your own directives breaks compatibility with other Pod 809formatters, in a way that using "=for I<target> ..." lines doesn't; 810however, you may find this useful if you're making a Pod superset 811format where you don't need to worry about compatibility. 812 813 814=item C<< $parser->nbsp_for_S( I<BOOLEAN> ); >> 815 816Setting this attribute to a true value (and by default it is false) will 817turn "SE<lt>...E<gt>" sequences into sequences of words separated by 818C<\xA0> (non-breaking space) characters. For example, it will take this: 819 820 I like S<Dutch apple pie>, don't you? 821 822and treat it as if it were: 823 824 I like DutchE<nbsp>appleE<nbsp>pie, don't you? 825 826This is handy for output formats that don't have anything quite like an 827"SE<lt>...E<gt>" code, but which do have a code for non-breaking space. 828 829There is currently no method for going the other way; but I can 830probably provide one upon request. 831 832 833=item C<< $parser->version_report() >> 834 835This returns a string reporting the $VERSION value from your module (and 836its classname) as well as the $VERSION value of Pod::Simple. Note that 837L<perlpodspec> requires output formats (wherever possible) to note 838this detail in a comment in the output format. For example, for 839some kind of SGML output format: 840 841 print OUT "<!-- \n", $parser->version_report, "\n -->"; 842 843 844=item C<< $parser->pod_para_count() >> 845 846This returns the count of Pod paragraphs seen so far. 847 848 849=item C<< $parser->line_count() >> 850 851This is the current line number being parsed. But you might find the 852"line_number" event attribute more accurate, when it is present. 853 854 855=item C<< $parser->nix_X_codes( I<SOMEVALUE> ) >> 856 857This attribute, when set to a true value (and it is false by default) 858ignores any "XE<lt>...E<gt>" sequences in the document being parsed. 859Many formats don't actually use the content of these codes, so have 860no reason to process them. 861 862=item C<< $parser->keep_encoding_directive( I<SOMEVALUE> ) >> 863 864This attribute, when set to a true value (it is false by default) 865will keep C<=encoding> and its content in the event structure. Most 866formats don't actually need to process the content of an C<=encoding> 867directive, even when this directive sets the encoding and the 868processor makes use of the encoding information. Indeed, it is 869possible to know the encoding without processing the directive 870content. 871 872=item C<< $parser->merge_text( I<SOMEVALUE> ) >> 873 874This attribute, when set to a true value (and it is false by default) 875makes sure that only one event (or token, or node) will be created 876for any single contiguous sequence of text. For example, consider 877this somewhat contrived example: 878 879 I just LOVE Z<>hotE<32>apple pie! 880 881When that is parsed and events are about to be called on it, it may 882actually seem to be four different text events, one right after another: 883one event for "I just LOVE ", one for "hot", one for " ", and one for 884"apple pie!". But if you have merge_text on, then you're guaranteed 885that it will be fired as one text event: "I just LOVE hot apple pie!". 886 887 888=item C<< $parser->code_handler( I<CODE_REF> ) >> 889 890This specifies code that should be called when a code line is seen 891(i.e., a line outside of the Pod). Normally this is undef, meaning 892that no code should be called. If you provide a routine, it should 893start out like this: 894 895 sub get_code_line { # or whatever you'll call it 896 my($line, $line_number, $parser) = @_; 897 ... 898 } 899 900Note, however, that sometimes the Pod events aren't processed in exactly 901the same order as the code lines are -- i.e., if you have a file with 902Pod, then code, then more Pod, sometimes the code will be processed (via 903whatever you have code_handler call) before the all of the preceding Pod 904has been processed. 905 906 907=item C<< $parser->cut_handler( I<CODE_REF> ) >> 908 909This is just like the code_handler attribute, except that it's for 910"=cut" lines, not code lines. The same caveats apply. "=cut" lines are 911unlikely to be interesting, but this is included for completeness. 912 913 914=item C<< $parser->pod_handler( I<CODE_REF> ) >> 915 916This is just like the code_handler attribute, except that it's for 917"=pod" lines, not code lines. The same caveats apply. "=pod" lines are 918unlikely to be interesting, but this is included for completeness. 919 920 921=item C<< $parser->whiteline_handler( I<CODE_REF> ) >> 922 923This is just like the code_handler attribute, except that it's for 924lines that are seemingly blank but have whitespace (" " and/or "\t") on them, 925not code lines. The same caveats apply. These lines are unlikely to be 926interesting, but this is included for completeness. 927 928 929=item C<< $parser->whine( I<linenumber>, I<complaint string> ) >> 930 931This notes a problem in the Pod, which will be reported in the "Pod 932Errors" section of the document and/or sent to STDERR, depending on the 933values of the attributes C<no_whining>, C<no_errata_section>, and 934C<complain_stderr>. 935 936=item C<< $parser->scream( I<linenumber>, I<complaint string> ) >> 937 938This notes an error like C<whine> does, except that it is not 939suppressible with C<no_whining>. This should be used only for very 940serious errors. 941 942 943=item C<< $parser->source_dead(1) >> 944 945This aborts parsing of the current document, by switching on the flag 946that indicates that EOF has been seen. In particularly drastic cases, 947you might want to do this. It's rather nicer than just calling 948C<die>! 949 950=item C<< $parser->hide_line_numbers( I<SOMEVALUE> ) >> 951 952Some subclasses that indiscriminately dump event attributes (well, 953except for ones beginning with "~") can use this object attribute for 954refraining to dump the "start_line" attribute. 955 956=item C<< $parser->no_whining( I<SOMEVALUE> ) >> 957 958This attribute, if set to true, will suppress reports of non-fatal 959error messages. The default value is false, meaning that complaints 960I<are> reported. How they get reported depends on the values of 961the attributes C<no_errata_section> and C<complain_stderr>. 962 963=item C<< $parser->no_errata_section( I<SOMEVALUE> ) >> 964 965This attribute, if set to true, will suppress generation of an errata 966section. The default value is false -- i.e., an errata section will be 967generated. 968 969=item C<< $parser->complain_stderr( I<SOMEVALUE> ) >> 970 971This attribute, if set to true will send complaints to STDERR. The 972default value is false -- i.e., complaints do not go to STDERR. 973 974=item C<< $parser->bare_output( I<SOMEVALUE> ) >> 975 976Some formatter subclasses use this as a flag for whether output should 977have prologue and epilogue code omitted. For example, setting this to 978true for an HTML formatter class should omit the 979"<html><head><title>...</title><body>..." prologue and the 980"</body></html>" epilogue. 981 982If you want to set this to true, you should probably also set 983C<no_whining> or at least C<no_errata_section> to true. 984 985=item C<< $parser->preserve_whitespace( I<SOMEVALUE> ) >> 986 987If you set this attribute to a true value, the parser will try to 988preserve whitespace in the output. This means that such formatting 989conventions as two spaces after periods will be preserved by the parser. 990This is primarily useful for output formats that treat whitespace as 991significant (such as text or *roff, but not HTML). 992 993=item C<< $parser->parse_empty_lists( I<SOMEVALUE> ) >> 994 995If this attribute is set to true, the parser will not ignore empty 996C<=over>/C<=back> blocks. The type of C<=over> will be I<empty>, documented 997above, L<events with an element_name of over-empty>. 998 999=back 1000 1001=head1 SEE ALSO 1002 1003L<Pod::Simple> -- event-based Pod-parsing framework 1004 1005L<Pod::Simple::Methody> -- like Pod::Simple, but each sort of event 1006calls its own method (like C<start_head3>) 1007 1008L<Pod::Simple::PullParser> -- a Pod-parsing framework like Pod::Simple, 1009but with a token-stream interface 1010 1011L<Pod::Simple::SimpleTree> -- a Pod-parsing framework like Pod::Simple, 1012but with a tree interface 1013 1014L<Pod::Simple::Checker> -- a simple Pod::Simple subclass that reads 1015documents, and then makes a plaintext report of any errors found in the 1016document 1017 1018L<Pod::Simple::DumpAsXML> -- for dumping Pod documents as tidily 1019indented XML, showing each event on its own line 1020 1021L<Pod::Simple::XMLOutStream> -- dumps a Pod document as XML (without 1022introducing extra whitespace as Pod::Simple::DumpAsXML does). 1023 1024L<Pod::Simple::DumpAsText> -- for dumping Pod documents as tidily 1025indented text, showing each event on its own line 1026 1027L<Pod::Simple::LinkSection> -- class for objects representing the values 1028of the TODO and TODO attributes of LE<lt>...E<gt> elements 1029 1030L<Pod::Escapes> -- the module that Pod::Simple uses for evaluating 1031EE<lt>...E<gt> content 1032 1033L<Pod::Simple::Text> -- a simple plaintext formatter for Pod 1034 1035L<Pod::Simple::TextContent> -- like Pod::Simple::Text, but 1036makes no effort for indent or wrap the text being formatted 1037 1038L<Pod::Simple::HTML> -- a simple HTML formatter for Pod 1039 1040L<perlpod|perlpod> 1041 1042L<perlpodspec|perlpodspec> 1043 1044L<perldoc> 1045 1046=head1 SUPPORT 1047 1048Questions or discussion about POD and Pod::Simple should be sent to the 1049pod-people@perl.org mail list. Send an empty email to 1050pod-people-subscribe@perl.org to subscribe. 1051 1052This module is managed in an open GitHub repository, 1053L<https://github.com/perl-pod/pod-simple/>. Feel free to fork and contribute, or 1054to clone L<https://github.com/perl-pod/pod-simple.git> and send patches! 1055 1056Patches against Pod::Simple are welcome. Please send bug reports to 1057<bug-pod-simple@rt.cpan.org>. 1058 1059=head1 COPYRIGHT AND DISCLAIMERS 1060 1061Copyright (c) 2002 Sean M. Burke. 1062 1063This library is free software; you can redistribute it and/or modify it 1064under the same terms as Perl itself. 1065 1066This program is distributed in the hope that it will be useful, but 1067without any warranty; without even the implied warranty of 1068merchantability or fitness for a particular purpose. 1069 1070=head1 AUTHOR 1071 1072Pod::Simple was created by Sean M. Burke <sburke@cpan.org>. 1073But don't bother him, he's retired. 1074 1075Pod::Simple is maintained by: 1076 1077=over 1078 1079=item * Allison Randal C<allison@perl.org> 1080 1081=item * Hans Dieter Pearcey C<hdp@cpan.org> 1082 1083=item * David E. Wheeler C<dwheeler@cpan.org> 1084 1085=back 1086 1087=for notes 1088Hm, my old podchecker version (1.2) says: 1089 *** WARNING: node 'http://search.cpan.org/' contains non-escaped | or / at line 38 in file Subclassing.pod 1090 *** WARNING: node 'http://lists.perl.org/showlist.cgi?name=pod-people' contains non-escaped | or / at line 41 in file Subclassing.pod 1091Yes, L<...> is hard. 1092 1093 1094=cut 1095