Weaver.pm

filter: Statementstmt 100% 91 / 91 Branchbran 62.5% 5 / 8 Conditioncond 55.5% 5 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 21 / 21 Podpod 60.0% 3 / 5 totaltotal 90.6% 126 / 139 CC 15 SCAR 14.2
CC
15
Cov
94%
new_from_config_sequence
9.7
weave_document
6.0
new_from_config
2.0
CRAP 4.2
« Weaver/Plugin/Transformer.pm ↑ Summary Weaver/Section/Authors.pm »
1 package Pod::Weaver 4.022;
2 # ABSTRACT: weave together a Pod document from an outline
3  
4 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # BEGIN BOILERPLATE
8 10 ▶use v5.22.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶no feature 'switch';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use experimental qw(postderef postderef_qq); # This experiment gets mainlined.
Subroutine BEGIN: called CC=1 SCAR=0.0
13 # END BOILERPLATE
14  
15 #pod =head1 SYNOPSIS
16 #pod
17 #pod my $weaver = Pod::Weaver->new_with_default_config;
18 #pod
19 #pod my $document = $weaver->weave_document({
20 #pod pod_document => $pod_elemental_document,
21 #pod ppi_document => $ppi_document,
22 #pod
23 #pod license => $software_license,
24 #pod version => $version_string,
25 #pod authors => \@author_names,
26 #pod })
27 #pod
28 #pod =head1 DESCRIPTION
29 #pod
30 #pod Pod::Weaver is a system for building Pod documents from templates. It doesn't
31 #pod perform simple text substitution, but instead builds a
32 #pod Pod::Elemental::Document. Its plugins sketch out a series of sections
33 #pod that will be produced based on an existing Pod document or other provided
34 #pod information.
35 #pod
36 #pod =cut
37  
38 10 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 10 ▶use Log::Dispatchouli 1.100710; # proxy
Subroutine BEGIN: called CC=1 SCAR=0.0
40 10 ▶use Pod::Elemental 0.100220;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 10 ▶use Pod::Elemental::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 10 ▶use Pod::Weaver::Config::Finder;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 10 ▶use Pod::Weaver::Role::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 10 ▶use String::Flogger 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 #pod =attr logger
47 #pod
48 #pod This attribute stores the logger, which must provide a log method. The
49 #pod weaver's log method delegates to the logger's log method.
50 #pod
51 #pod =cut
52  
53 has logger => (
54 is => 'ro',
55 lazy => 1,
56 36 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
57 36 Log::Dispatchouli->new({
58 ident => 'Pod::Weaver',
59 to_stdout => 1,
60 log_pid => 0,
61 });
62 },
63 10 handles => [ qw(log log_fatal log_debug) ]
64 );
65  
66 #pod =attr plugins
67 #pod
68 #pod This attribute is an arrayref of objects that can perform the
69 #pod L<Pod::Weaver::Role::Plugin> role. In general, its contents are found through
70 #pod the C<L</plugins_with>> method.
71 #pod
72 #pod =cut
73  
74 has plugins => (
75 is => 'ro',
76 isa => 'ArrayRef[Pod::Weaver::Role::Plugin]',
77 required => 1,
78 lazy => 1,
79 init_arg => undef,
80 36 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
81 10 );
82  
83 #pod =method plugins_with
84 #pod
85 #pod my $plugins_array_ref = $weaver->plugins_with('-Section');
86 #pod
87 #pod This method will return an arrayref of plugins that perform the given role, in
88 #pod the order of their registration. If the role name begins with a hyphen, the
89 #pod method will prepend C<Pod::Weaver::Role::>.
90 #pod
91 #pod =cut
92  
93 178 ▶sub plugins_with {
Subroutine plugins_with: called CC=1 SCAR=0.0
Pod documented
94 178 my ($self, $role) = @_;
95  
96 178 $role =~ s/^-/Pod::Weaver::Role::/;
97 178 my @plugins = grep { $_->does($role) } $self->plugins->@*;
98  
99 178 return \@plugins;
100 }
101  
102 #pod =method weave_document
103 #pod
104 #pod my $document = $weaver->weave_document(\%input);
105 #pod
106 #pod This is the most important method in Pod::Weaver. Given a set of input
107 #pod parameters, it will weave a new document. Different section plugins will
108 #pod expect different input parameters to be present, but some common ones include:
109 #pod
110 #pod pod_document - a Pod::Elemental::Document for the original Pod document
111 #pod ppi_document - a PPI document for the source of the module being documented
112 #pod license - a Software::License object for the source module's license
113 #pod version - a version (string) to use in produced documentation
114 #pod
115 #pod The C<pod_document> should have gone through a L<Pod5
116 #pod transformer|Pod::Elemental::Transformer::Pod5>, and should probably have had
117 #pod its C<=head1> elements L<nested|Pod::Elemental::Transformer::Nester>.
118 #pod
119 #pod The method will return a new Pod::Elemental::Document. The input documents may
120 #pod be destructively altered during the weaving process. If they should be
121 #pod untouched, pass in copies.
122 #pod
123 #pod =cut
124  
125 36 ▶sub weave_document {
Subroutine weave_document: called CC=6 SCAR=17.9
Pod documented
126 36 my ($self, $input) = @_;
127  
128 36 my $document = Pod::Elemental::Document->new;
129  
130 36 for ($self->plugins_with(-Preparer)->@*) {
131 29 $_->prepare_input($input);
132 }
133  
134 36 for ($self->plugins_with(-Dialect)->@*) {
135 7 $_->translate_dialect($input->{pod_document});
136 }
137  
138 36 for ($self->plugins_with(-Transformer)->@*) {
139 49 $_->transform_document($input->{pod_document});
140 }
141  
142 36 for ($self->plugins_with(-Section)->@*) {
143 167 $_->weave_section($document, $input);
144 }
145  
146 34 for ($self->plugins_with(-Finalizer)->@*) {
147 32 $_->finalize_document($document, $input);
148 }
149  
150 34 return $document;
151 }
152  
153 #pod =method new_with_default_config
154 #pod
155 #pod This method returns a new Pod::Weaver with a stock configuration by using only
156 #pod L<Pod::Weaver::PluginBundle::Default>.
157 #pod
158 #pod =cut
159  
160 2 ▶sub new_with_default_config {
Subroutine new_with_default_config: called CC=1 SCAR=0.0
Pod documented
161 2 my ($class, $arg) = @_;
162  
163 2 my $assembler = Pod::Weaver::Config::Assembler->new;
164  
165 2 my $root = $assembler->section_class->new({ name => '_' });
166 2 $assembler->sequence->add_section($root);
167  
168 2 $assembler->change_section('@Default');
169 2 $assembler->end_section;
170  
171 2 return $class->new_from_config_sequence($assembler->sequence, $arg);
172 }
173  
174 1 ▶sub new_from_config {
Subroutine new_from_config: called CC=2 SCAR=7.0
Pod undocumented
175 1 my ($class, $arg, $new_arg) = @_;
176  
177 1 ▶ my $root = $arg->{root} || '.';
Condition50%1/2
$arg->{'root'} || '.'
l!l
10
MC/DC0%0/1
$arg->{'root'} || '.'
$arg->{'root'}
Truth table50%1/2
A
A= $arg->{'root'}
Aresult
11
00
178 1 my $name = File::Spec->catfile($root, 'weaver');
179 1 my ($sequence) = Pod::Weaver::Config::Finder->new->read_config($name);
180  
181 1 return $class->new_from_config_sequence($sequence, $new_arg);
182 }
183  
184 36 ▶sub new_from_config_sequence {
Subroutine new_from_config_sequence: called CC=9 SCAR=22.7
Pod undocumented
185 36 my ($class, $seq, $arg) = @_;
186 36 ▶ $arg ||= {};
Condition100%2/2
$arg ||= {}
l!l
729
MC/DC100%1/1
$arg ||= {}
$arg
Truth table100%2/2
A
A= $arg
Aresult
11
00
187  
188 36 ▶ my $merge = $arg->{root_config} || {};
Condition50%1/2
$arg->{'root_config'} || {}
l!l
036
MC/DC0%0/1
$arg->{'root_config'} || {}
$arg->{'root_config'}
Truth table50%1/2
A
A= $arg->{'root_config'}
Aresult
11
00
189  
190 36 ▶ confess("config must be a Config::MVP::Sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless $seq and $seq->isa("Config::MVP::Sequence") 0 36 36
Condition33%1/3
$seq and $seq->isa("Config::MVP::Sequence")
!ll&&!rl&&r
0036
MC/DC0%0/2
$seq and $seq->isa("Config::MVP::Sequence")
$seq $seq->isa("Config::MVP::Sequence")
Truth table33%1/3
A and B
A= $seqB= $seq->isa("Config::MVP::Sequence")
ABresult
0X0
100
111
191 unless $seq and $seq->isa('Config::MVP::Sequence');
192  
193 36 my $core_config = $seq->section_named('_')->payload;
194  
195 36 my $self = $class->new({
196 %$merge,
197 %$core_config,
198 });
199  
200 36 for my $section ($seq->sections) {
201 268 ▶ next if $section->name eq '_';
Branch: 1 branch
BranchTrueFalseTotal
if $section->name eq "_" 36 232 268
202  
203 232 my ($name, $plugin_class, $arg) = (
204 $section->name,
205 $section->package,
206 $section->payload,
207 );
208  
209 232 $self->log_debug("initializing plugin $name ($plugin_class)");
210  
211 confess "arguments attempted to override 'plugin_name'"
212 232 ▶ if defined $arg->{plugin_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg->{"plugin_name"} 0 232 232
213  
214 confess "arguments attempted to override 'weaver'"
215 232 ▶ if defined $arg->{weaver};
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg->{"weaver"} 0 232 232
216  
217 232 push $self->plugins->@*,
218 $plugin_class->new({
219 %$arg,
220 plugin_name => $name,
221 weaver => $self,
222 });
223 }
224  
225 36 return $self;
226 }
227  
228 10 __PACKAGE__->meta->make_immutable;
229 10 1;
230  
231 __END__
« Weaver/Plugin/Transformer.pm ↑ Summary Weaver/Section/Authors.pm »