NAME

Pod::Elemental::PerlMunger - a thing that takes a string of Perl and rewrites its documentation

VERSION

version 0.200007

OVERVIEW

This role is to be included in classes that rewrite the documentation of a Perl document, stripping out all the Pod, munging it, and replacing it into the Perl.

The only relevant method is munge_perl_string, which must be implemented with a different interface than will be exposed.

When calling the munge_perl_string method, arguments should be passed like this:

  $object->munge_perl_string($perl_string, \%arg);

$perl_string should be a character string containing Perl source code.

%arg may contain any input for the underlying procedure. Defined keys for %arg are:

filename

the name of the file whose contents are being munged; optional, used for error messages

no_strip_bom

If given, the BOM character (U+FEFF) won't be stripped from the input. Probably best to leave this one off.

The method will return a character string containing the rewritten and combined document.

Classes including this role must implement a munge_perl_string that expects to be called like this:

  $object->munge_perl_string(\%doc, \%arg);

%doc will have two entries:

  ppi - a PPI::Document of the Perl document with all its Pod removed
  pod - a Pod::Elemental::Document with no transformations yet performed

This munge_perl_string method should return a hashref in the same format as %doc.

PERL VERSION

This library should run on perls released even a long time ago. It should work on any version of perl released in the last five years.

Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl.

ATTRIBUTES

replacer

The replacer is either a method name or code reference used to produces PPI elements used to replace removed Pod. By default, it is "replace_with_nothing", which just removes Pod tokens entirely. This means that the line numbers of the code in the newly-produced document are changed, if the Pod had been interleaved with the code.

See also "replace_with_comment" and "replace_with_blank".

If no further code follows the Pod being replaced, "post_code_replacer" is used instead.

post_code_replacer

This attribute is used just like "replacer", and defaults to its value, but is used for building replacements for Pod removed after the last hunk of code. The idea is that if you're only concerned about altering your code's line numbers, you can stop replacing stuff after there's no more code to be affected.

METHODS

replace_with_nothing

This method returns nothing. It's the default "replacer". It's not very interesting.

replace_with_comment

This replacer replaces removed Pod elements with a comment containing their text. In other words:

  =head1 A header!

  This is great!

  =cut

...is replaced with:

  # =head1 A header!
  #
  # This is great!
  #
  # =cut

replace_with_blank

This replacer replaces removed Pod elements with vertical whitespace of equal line count. In other words:

  =head1 A header!

  This is great!

  =cut

...is replaced with five blank lines.

AUTHOR

Ricardo SIGNES <cpan@semiotic.systems>

CONTRIBUTORS

  • Christopher J. Madsen <perl@cjmweb.net>

  • Dave Rolsky <autarch@urth.org>

  • Karen Etheridge <ether@cpan.org>

  • perlancar (on PC, Bandung) <perlancar@gmail.com>

  • Ricardo Signes <rjbs@semiotic.systems>

COPYRIGHT AND LICENSE

This software is copyright (c) 2022 by Ricardo SIGNES.

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