Jon Allen > Filter-Indent-HereDoc > Filter::Indent::HereDoc

Download:
Filter-Indent-HereDoc-1.01.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 1.01   Source  

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!

Changes to terminator strings

In addition to allowing indented here documents, Filter::Indent::HereDoc also provides support for a more permissive style of terminator string, as specified in Perl6 RFC111. The changes are:

You can force the module to revert to the standard Perl5 style of terminator string by specifying 'strict_terminators' when the module is use'd, e.g.

 use Filter::Indent::HereDoc;
 print << EOT
 Hello, World!
 EOT ;             # this will work
 
 use Filter::Indent::HereDoc 'strict_terminators';
 print << EOT
 Hello, World!
 EOT ;             # this will generate an error

CAVEATS ^

SEE ALSO ^

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

AUTHOR ^

Jon Allen, <jj@jonallen.info>

THANKS TO ^

Michael Schwern for the suggestions about Perl6 RFC111

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.

syntax highlighting: