File Coverage

blib/lib/Pod/Weaver/Plugin/Encoding.pm
Criterion Covered Total %
statement 22 22 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 32 32 100.0


line stmt bran cond sub pod time code
1             package Pod::Weaver::Plugin::Encoding; # git description: v0.02-9-g9f8a221
2             # ABSTRACT: (DEPRECATED) Add an encoding command to your POD
3              
4             our $VERSION = '0.03';
5              
6 1     1   386216 use Moose;
  1         4  
  1         13  
7 1     1   9002 use List::Util 1.33 'any';
  1         39  
  1         96  
8 1     1   8 use MooseX::Types::Moose qw(Str);
  1         3  
  1         15  
9 1     1   6347 use aliased 'Pod::Elemental::Node';
  1         757  
  1         6  
10 1     1   522 use aliased 'Pod::Elemental::Element::Pod5::Command';
  1         3  
  1         4  
11 1     1   180 use namespace::autoclean -also => 'find_encoding_command';
  1         3  
  1         14  
12              
13             with 'Pod::Weaver::Role::Finalizer';
14              
15             #pod =head1 SYNOPSIS
16             #pod
17             #pod In your weaver.ini:
18             #pod
19             #pod [-Encoding]
20             #pod
21             #pod or
22             #pod
23             #pod [-Encoding]
24             #pod encoding = koi8-r
25             #pod
26             #pod =head1 DESCRIPTION
27             #pod
28             #pod This section will add an C<=encoding> command like
29             #pod
30             #pod =encoding UTF-8
31             #pod
32             #pod to your POD.
33             #pod
34             #pod =attr encoding
35             #pod
36             #pod The encoding to declare in the C<=encoding> command. Defaults to
37             #pod C<UTF-8>.
38             #pod
39             #pod =cut
40              
41             has encoding => (
42             is => 'ro',
43             isa => Str,
44             default => 'UTF-8',
45             );
46              
47             #pod =method finalize_document
48             #pod
49             #pod This method prepends an C<=encoding> command with the content of the
50             #pod C<encoding> attribute's value to the document's children.
51             #pod
52             #pod Does nothing if the document already has an C<=encoding> command.
53             #pod
54             #pod =cut
55              
56             sub finalize_document {
57 2     2 1 28786 my ($self, $document) = @_;
58              
59 2 100       71 return if find_encoding_command($document->children);
60              
61 1         57 unshift @{ $document->children },
  1         27  
62             Command->new({
63             command => 'encoding',
64             content => $self->encoding,
65             }),
66             }
67              
68             sub find_encoding_command {
69             my ($children) = @_;
70             return any {
71             ($_->isa(Command) && $_->command eq 'encoding')
72             || ($_->does(Node) && find_encoding_command($_->children));
73             } @$children;
74             }
75              
76             #pod =head1 SEE ALSO
77             #pod
78             #pod L<Pod::Weaver::Section::Encoding> is very similar to this module, but
79             #pod expects the encoding to be specified in a special comment within the
80             #pod document that's being woven.
81             #pod
82             #pod L<Pod::Weaver::Plugin::SingleEncoding> can be considered the successor to this
83             #pod module, and is a core part of L<Pod::Weaver> version 4. It is contained within
84             #pod L<[@Default]|Pod::Weaver::PluginBundle::Default>, and you should be using
85             #pod that plugin rather than this one.
86             #pod
87             #pod =cut
88              
89             __PACKAGE__->meta->make_immutable;
90              
91             1;
92              
93             __END__
94              
95             =pod
96              
97             =encoding UTF-8
98              
99             =head1 NAME
100              
101             Pod::Weaver::Plugin::Encoding - (DEPRECATED) Add an encoding command to your POD
102              
103             =head1 VERSION
104              
105             version 0.03
106              
107             =head1 SYNOPSIS
108              
109             In your weaver.ini:
110              
111             [-Encoding]
112              
113             or
114              
115             [-Encoding]
116             encoding = koi8-r
117              
118             =head1 DESCRIPTION
119              
120             This section will add an C<=encoding> command like
121              
122             =encoding UTF-8
123              
124             to your POD.
125              
126             =head1 ATTRIBUTES
127              
128             =head2 encoding
129              
130             The encoding to declare in the C<=encoding> command. Defaults to
131             C<UTF-8>.
132              
133             =head1 METHODS
134              
135             =head2 finalize_document
136              
137             This method prepends an C<=encoding> command with the content of the
138             C<encoding> attribute's value to the document's children.
139              
140             Does nothing if the document already has an C<=encoding> command.
141              
142             =head1 SEE ALSO
143              
144             L<Pod::Weaver::Section::Encoding> is very similar to this module, but
145             expects the encoding to be specified in a special comment within the
146             document that's being woven.
147              
148             L<Pod::Weaver::Plugin::SingleEncoding> can be considered the successor to this
149             module, and is a core part of L<Pod::Weaver> version 4. It is contained within
150             L<[@Default]|Pod::Weaver::PluginBundle::Default>, and you should be using
151             that plugin rather than this one.
152              
153             =head1 AUTHOR
154              
155             Florian Ragwitz <rafl@debian.org>
156              
157             =head1 CONTRIBUTORS
158              
159             =for stopwords Karen Etheridge Сергей Романов Graham Knop
160              
161             =over 4
162              
163             =item *
164              
165             Karen Etheridge <ether@cpan.org>
166              
167             =item *
168              
169             Сергей Романов <complefor@rambler.ru>
170              
171             =item *
172              
173             Graham Knop <haarg@haarg.org>
174              
175             =back
176              
177             =head1 COPYRIGHT AND LICENSE
178              
179             This software is copyright (c) 2010 by Florian Ragwitz.
180              
181             This is free software; you can redistribute it and/or modify it under
182             the same terms as the Perl 5 programming language system itself.
183              
184             =cut