1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
package Dist::Zilla::Plugin::PodWeaver;
BEGIN {
$Dist::Zilla::Plugin::PodWeaver::VERSION = '3.101641';
}
# ABSTRACT: weave your Pod together from configuration and Dist::Zilla
use Moose;
use Moose::Autobox;
use List::MoreUtils qw(any);
use Pod::Weaver 3.100710; # logging with proxies
with(
'Dist::Zilla::Role::FileMunger',
'Dist::Zilla::Role::FileFinderUser' => {
default_finders => [ ':InstallModules', ':ExecFiles' ],
},
);
use namespace::autoclean;
use PPI;
use Pod::Elemental;
use Pod::Elemental::Transformer::Pod5;
use Pod::Elemental::Transformer::Nester;
use Pod::Elemental::Selectors -all;
use Pod::Weaver::Config::Assembler;
sub weaver {
my ($self) = @_;
my @files = glob($self->zilla->root->file('weaver.*'));
my $arg = {
root => $self->zilla->root,
root_config => { logger => $self->logger },
};
if ($self->config_plugin) {
my $assembler = Pod::Weaver::Config::Assembler->new;
my $root = $assembler->section_class->new({ name => '_' });
$assembler->sequence->add_section($root);
$assembler->change_section( $self->config_plugin );
$assembler->end_section;
return Pod::Weaver->new_from_config_sequence($assembler->sequence, $arg);
} elsif (@files) {
return Pod::Weaver->new_from_config($arg);
} else {
return Pod::Weaver->new_with_default_config($arg);
}
}
has config_plugin => (
is => 'ro',
isa => 'Str',
);
sub munge_files {
my ($self) = @_;
$self->munge_file($_) for @{ $self->found_files };
}
sub munge_file {
my ($self, $file) = @_;
$self->log_debug([ 'weaving pod in %s', $file->name ]);
$self->munge_pod($file);
return;
}
sub munge_perl_string {
my ($self, $doc, $arg) = @_;
my $weaver = $self->weaver;
my $new_doc = $weaver->weave_document({
%$arg,
pod_document => $doc->{pod},
ppi_document => $doc->{ppi},
});
return {
pod => $new_doc,
ppi => $doc->{ppi},
}
}
sub munge_pod {
my ($self, $file) = @_;
my $content = $file->content;
my $new_content = $self->munge_perl_string(
$file->content,
{
zilla => $self->zilla,
filename => $file->name,
version => $self->zilla->version,
license => $self->zilla->license,
authors => $self->zilla->authors,
distmeta => $self->zilla->distmeta,
},
);
$file->content($new_content);
return;
}
with 'Pod::Elemental::PerlMunger';
__PACKAGE__->meta->make_immutable;
no Moose;
1;
__END__
=pod
=head1 NAME
Dist::Zilla::Plugin::PodWeaver - weave your Pod together from configuration and Dist::Zilla
=head1 VERSION
version 3.101641
=head1 DESCRIPTION
[PodWeaver] is the bridge between L<Dist::Zilla> and L<Pod::Weaver>. It rips
apart your kinda-Pod and reconstructs it as boring old real Pod.
=head1 METHODS
=head2 weaver
This method returns the Pod::Weaver object to be used. The current
implementation builds a new weaver on each invocation, because one or two core
Pod::Weaver plugins cannot be trusted to handle multiple documents per plugin
instance. In the future, when that is fixed, this may become an accessor of an
attribute with a builder. Until this is clearer, use caution when modifying
this method in subclasses.
=head1 CONFIGURATION
If the C<config_plugin> attribute is given, it will be treated like a
Pod::Weaver section heading. For example, C<@Default> could be given.
Otherwise, if a file matching C<./weaver.*> exists, Pod::Weaver will be told to
look for configuration in the current directory.
Otherwise, it will use the default configuration.
=head1 AUTHOR
Ricardo SIGNES <rjbs@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2010 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.
=cut
|