File Coverage

blib/lib/Pod/Weaver/Section/SourceGitHub.pm
Criterion Covered Total %
statement 9 33 27.2
branch 0 12 0.0
condition n/a
subroutine 3 7 42.8
pod 1 1 100.0
total 13 53 24.5


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