File Coverage

blib/lib/Pod/Weaver/Section/SourceGitHub.pm
Criterion Covered Total %
statement 20 20 100.0
branch 6 8 75.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 31 33 93.9


line stmt bran cond sub pod time code
1             package Pod::Weaver::Section::SourceGitHub;
2             $Pod::Weaver::Section::SourceGitHub::VERSION = '0.59';
3             # ABSTRACT: Add SOURCE pod section for a github repository
4              
5 2     2   1326576 use Moose;
  2         668452  
  2         19  
6              
7             with 'Pod::Weaver::Role::Section';
8              
9 2     2   17311 use Moose::Autobox;
  2         582361  
  2         55  
10              
11             has zilla => (
12             is => 'rw',
13             isa => 'Dist::Zilla'
14             );
15              
16             has repo_data => (
17             is => 'ro',
18             lazy => 1,
19             default => sub {
20             my $self = shift;
21              
22             my $url = $self->zilla->distmeta->{resources}{repository}{url}
23             or die "No repository URL found in distmeta";
24              
25             if ($url =~ /github\.com/i) {
26             $url =~ s{^(?:https?|git):/*}{}i;
27             $url =~ s{^git\@github.com:/*}{github.com/}i;
28             $url =~ s/\.git$//i;
29              
30             return [ "https://$url.git", "https://$url" ];
31             }
32              
33             return [];
34             }
35             );
36              
37             has repo_git => (
38             is => 'ro',
39             lazy => 1,
40             default => sub { shift->repo_data->[0] },
41             );
42              
43             has repo_web => (
44             is => 'ro',
45             lazy => 1,
46             default => sub { shift->repo_data->[1] },
47             );
48              
49              
50             sub weave_section {
51 6     6 1 335598 my ($self, $document, $input) = @_;
52              
53 6 100       74 my $zilla = $input->{zilla} or return;
54 5         304 $self->zilla($zilla);
55              
56 5 50       13 my $meta = eval { $zilla->distmeta }
  5         40  
57             or die "no distmeta data present";
58              
59             # pull repo out of distmeta resources.
60 5 50       489 my $repo = $meta->{resources}{repository}{url} or return;
61              
62 5 100       37 return unless $repo =~ /github\.com/i;
63              
64 4         224 my $repo_web = $self->repo_web;
65 4         217 my $repo_git = $self->repo_git;
66              
67 4         15 my $text =
68             "The development version is on github at L<$repo_web>\n".
69             "and may be cloned from L<$repo_git>\n";
70              
71 4         162 $document->children->push(
72             Pod::Elemental::Element::Nested->new({
73             command => 'head1',
74             content => 'SOURCE',
75             children => [
76             Pod::Elemental::Element::Pod5::Ordinary->new({content => $text}),
77             ],
78             }),
79             );
80             }
81              
82 2     2   3426 no Moose;
  2         5  
  2         16  
83             1;
84              
85             __END__
86              
87             =pod
88              
89             =encoding UTF-8
90              
91             =head1 NAME
92              
93             Pod::Weaver::Section::SourceGitHub - Add SOURCE pod section for a github repository
94              
95             =head1 VERSION
96              
97             version 0.59
98              
99             =head1 SYNOPSIS
100              
101             in C<weaver.ini>:
102              
103             [SourceGitHub]
104              
105             =head1 OVERVIEW
106              
107             This section plugin will produce a hunk of Pod that gives the github URL for
108             your module, as well as instructions on how to clone the repository.
109              
110             =head1 METHODS
111              
112             =head2 weave_section
113              
114             adds the C<SOURCE> section.
115              
116             =head1 SOURCE
117              
118             The development version is on github at L<https://github.com/mschout/pod-weaver-section-sourcegithub>
119             and may be cloned from L<https://github.com/mschout/pod-weaver-section-sourcegithub.git>
120              
121             =head1 BUGS
122              
123             Please report any bugs or feature requests on the bugtracker website
124             L<https://github.com/mschout/pod-weaver-section-sourcegithub/issues>
125              
126             When submitting a bug or request, please include a test-file or a
127             patch to an existing test-file that illustrates the bug or desired
128             feature.
129              
130             =head1 AUTHOR
131              
132             Michael Schout <mschout@cpan.org>
133              
134             =head1 COPYRIGHT AND LICENSE
135              
136             This software is copyright (c) 2026 by Michael Schout.
137              
138             This is free software; you can redistribute it and/or modify it under
139             the same terms as the Perl 5 programming language system itself.
140              
141             =cut