NAME

Filter::Indent::HereDoc - allows here documents to be indented within code blocks

SYNOPSIS

use Filter::Indent::HereDoc;
{
  {
    print <<EOT;
    Hello, World!
    EOT
  }
}
# This will print "Hello, World!" and stop at EOT
# even though the termination string is indented.

DESCRIPTION

When a 'here document' is used, the document text and the termination string must be flush with the left margin, even if the rest of the code block is indented.

Filter::Indent::HereDoc removes this restriction, and acts in a more DWIM kind of way - that if the terminator string is indented then that level of indent will apply to the whole document.

If there is no terminator string (so the here document stops at the first blank line), then enough whitespace will be stripped out so that the leftmost character of the document will be flush with the left margin, e.g.

print <<;
     Hello,
    World!

# This will print:
 Hello,
World!

CAVEATS

  • At present, Filter::Indent::HereDoc does not attempt to parse any of the Perl code, it just searches for the '<<' string to locate the start of a here document. Therefore if you need to write '<<' without starting a here document, you must first use no Filter::Indent::HereDoc; to stop the code from being filtered, e.g.

    use Filter::Indent::HereDoc;
    print <<EOT;
    This is a here document
    EOT
    
    no Filter::Indent::HereDoc;
    print "<<EOT";  # This will be printed as normal
  • Due to the way in which whitespace is removed, Filter::Indent::HereDoc can become confused if your editor replaces groups of spaces with tab characters. Different text editors use different tab stops, so for portability reasons it is probably best to avoid this feature.

SEE ALSO

Filter::Simple, http://perl.jonallen.info/modules, perlfaq4

AUTHOR

Jon Allen, <jj@jonallen.info>

COPYRIGHT AND LICENSE

Copyright 2003 by Jon Allen

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.