File Coverage

blib/lib/Pod/Weaver/Section/SourceGitHub.pm
Criterion Covered Total %
statement 2 4 50.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 4 6 66.6


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