| 1 | package Pod::Weaver::Section::Bugs 4.022; | ||
| 2 | # ABSTRACT: a section for bugtracker info | ||
| 3 | |||
| 4 | use Moose; | ||
| 5 | use Text::Wrap (); | ||
| 6 | with 'Pod::Weaver::Role::Section'; | ||
| 7 | |||
| 8 | # BEGIN BOILERPLATE | ||
| 9 | use v5.22.0; | ||
| 10 | use warnings; | ||
| 11 | use utf8; | ||
| 12 | no feature 'switch'; | ||
| 13 | use experimental qw(postderef postderef_qq); # This experiment gets mainlined. | ||
| 14 | # END BOILERPLATE | ||
| 15 | |||
| 16 | #pod =head1 OVERVIEW | ||
| 17 | #pod | ||
| 18 | #pod This section plugin will produce a hunk of Pod giving bug reporting | ||
| 19 | #pod information for the document, like this: | ||
| 20 | #pod | ||
| 21 | #pod =head1 BUGS | ||
| 22 | #pod | ||
| 23 | #pod Please report any bugs or feature requests on the bugtracker website | ||
| 24 | #pod http://rt.cpan.org/Dist/Display.html?Queue=Pod-Weaver | ||
| 25 | #pod | ||
| 26 | #pod When submitting a bug or request, please include a test-file or a | ||
| 27 | #pod patch to an existing test-file that illustrates the bug or desired | ||
| 28 | #pod feature. | ||
| 29 | #pod | ||
| 30 | #pod This plugin requires a C<distmeta> parameter containing a hash reference of | ||
| 31 | #pod L<CPAN::Meta::Spec> distribution metadata and at least one of one of the | ||
| 32 | #pod parameters C<web> or C<mailto> defined in | ||
| 33 | #pod C<< $meta->{resources}{bugtracker} >>. | ||
| 34 | #pod | ||
| 35 | #pod =head2 Using Pod::Weaver::Section::Bugs with Dist::Zilla | ||
| 36 | #pod | ||
| 37 | #pod When the PodWeaver plugin is used, the C<distmeta> parameter comes from the | ||
| 38 | #pod dist's distmeta data. Since this section is skipped when no bugtracker data is | ||
| 39 | #pod in the distmeta, you'll need to make sure it's there. A number of plugins set | ||
| 40 | #pod this data up automatically. To manually configure your bugtracker data, you | ||
| 41 | #pod can add something like the following to C<dist.ini>: | ||
| 42 | #pod | ||
| 43 | #pod [MetaResources] | ||
| 44 | #pod bugtracker.web = http://rt.cpan.org/NoAuth/Bugs.html?Dist=Pod-Weaver-Example | ||
| 45 | #pod bugtracker.mailto = bug-pod-weaver-example@rt.cpan.org | ||
| 46 | #pod | ||
| 47 | #pod ; Perhaps add repository stuff here: | ||
| 48 | #pod repository.url = | ||
| 49 | #pod repository.web = | ||
| 50 | #pod repository.type = | ||
| 51 | #pod | ||
| 52 | #pod [PodWeaver] | ||
| 53 | #pod | ||
| 54 | #pod =attr header | ||
| 55 | #pod | ||
| 56 | #pod The title of the header to be added. | ||
| 57 | #pod (default: "BUGS") | ||
| 58 | #pod | ||
| 59 | #pod =cut | ||
| 60 | |||
| 61 | has header => ( | ||
| 62 | is => 'ro', | ||
| 63 | isa => 'Str', | ||
| 64 | default => 'BUGS', | ||
| 65 | ); | ||
| 66 | |||
| 67 | sub weave_section { | ||
| 68 | my ($self, $document, $input) = @_; | ||
| 69 | |||
| 70 | unless (exists $input->{distmeta}{resources}{bugtracker}) { | ||
| 71 | $self->log_debug('skipping section because there is no resources.bugtracker'); | ||
| 72 | return; | ||
| 73 | } | ||
| 74 | my $bugtracker = $input->{distmeta}{resources}{bugtracker}; | ||
| 75 | my ($web, $mailto) = $bugtracker->@{ qw(web mailto) }; | ||
| 76 | |||
| 77 | unless (defined $web || defined $mailto) { | ||
| 78 | $self->log_debug('skipping section because there is no web or mailto key under resources.bugtracker'); | ||
| 79 | return; | ||
| 80 | } | ||
| 81 | |||
| 82 | my $text = "Please report any bugs or feature requests "; | ||
| 83 | |||
| 84 | my $name = $self->header; | ||
| 85 | if (defined $web) { | ||
| 86 | $self->log_debug("including $web as bugtracker in $name section"); | ||
| 87 | $text .= "on the bugtracker website L<$web>"; | ||
| 88 | $text .= defined $mailto ? " or " : "\n"; | ||
| 89 | } | ||
| 90 | |||
| 91 | if (defined $mailto) { | ||
| 92 | $self->log_debug("including $mailto as bugtracker in $name section"); | ||
| 93 | $text .= "by email to L<$mailto|mailto:$mailto>\.\n"; | ||
| 94 | } | ||
| 95 | |||
| 96 | local $Text::Wrap::huge = 'overflow'; | ||
| 97 | $text = Text::Wrap::wrap(q{}, q{}, $text); | ||
| 98 | |||
| 99 | $text .= <<'HERE'; | ||
| 100 | |||
| 101 | When submitting a bug or request, please include a test-file or a | ||
| 102 | patch to an existing test-file that illustrates the bug or desired | ||
| 103 | feature. | ||
| 104 | HERE | ||
| 105 | |||
| 106 | push $document->children->@*, | ||
| 107 | Pod::Elemental::Element::Nested->new({ | ||
| 108 | command => 'head1', | ||
| 109 | content => $name, | ||
| 110 | children => [ | ||
| 111 | Pod::Elemental::Element::Pod5::Ordinary->new({ content => $text }), | ||
| 112 | ], | ||
| 113 | }); | ||
| 114 | } | ||
| 115 | |||
| 116 | __PACKAGE__->meta->make_immutable; | ||
| 117 | 1; | ||
| 118 | |||
| 119 | __END__ |