Debian Codegraph @

inc/AppendSection.pm

raw
1 # vim: set ft=perl ts=8 sts=2 sw=2 tw=100 et :
2 use strict;
3 use warnings;
4 package inc::AppendSection;
5
6 use Moose;
7 extends 'Pod::Weaver::Section::AllowOverride';
8
9 # Warning: dirty hack ahead!
10 # This chicanery is to allow for [GenerateSection] followed by [AllowOverride],
11 # where the intention is the content added by that GenerateSection should be appended to the
12 # original section that was generated by a weaver bundle (as opposed to appearing in the literal
13 # .pm file).
14 # This plugin does its initial work (to find the node to pluck out and later append) in
15 # transform_document, and the Transformer phase is run before GenerateSection's weave_section
16 # has a chance to create the node.
17 # So this hack just runs the plugin's transform_document again if nothing was found the first time.
18 # Because it picks the first node it finds (to relocate to the location of the second match), we
19 # will now run GenerateSection first, before calling the weaver bundle.
20
21 # All of this really should be replaced by a new plugin called something like AppendSection,
22 # which subclasses GenerateSection to add the options provided by AllowOverride, letting us
23 # append (or prepend) to an existing section rather than generating a new one.
24
25 before weave_section => sub {
26 my ($self, $document, $input) = @_;
27
28 # if we haven't already found a matching section, look again now
29 $self->transform_document($document) if not $self->_override_with;
30 };
31
32 1;