| 1 | package Dist::Zilla::Plugin::ReadmeFromPod; | ||||||||||||||||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:AVAR'; | |||||||||||||||||||||||||||
| 3 | 2 | $Dist::Zilla::Plugin::ReadmeFromPod::VERSION = '0.40'; | |||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use List::Util 1.33 qw( first ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | with 'Dist::Zilla::Role::InstallTool' => { -version => 5 }; # after PodWeaver | |||||||||||||||||||||||||||
| 7 | 2 | with 'Dist::Zilla::Role::FilePruner'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use IO::String; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Pod::Readme v1.2.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Path::Tiny 0.004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | has filename => ( | |||||||||||||||||||||||||||
| 14 | is => 'ro', | ||||||||||||||||||||||||||||
| 15 | isa => 'Str', | ||||||||||||||||||||||||||||
| 16 | lazy => 1, | ||||||||||||||||||||||||||||
| 17 | builder => '_build_filename', | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub _build_filename { | ||||||||||||||||||||||||||
|
Subroutine
_build_filename: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 21 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 22 | # copied from Dist::Zilla::Plugin::ReadmeAnyFromPod | ||||||||||||||||||||||||||||
| 23 | 0 | my $pm = $self->zilla->main_module->name; | |||||||||||||||||||||||||||
| 24 | 0 | (my $pod = $pm) =~ s/\.pm$/\.pod/; | |||||||||||||||||||||||||||
| 25 | 0 | ▶ | return -e $pod ? $pod : $pm; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | has type => ( | |||||||||||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||||||||||
| 30 | isa => 'Str', | ||||||||||||||||||||||||||||
| 31 | default => 'text', | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 2 | my %FORMATS = ( | |||||||||||||||||||||||||||
| 35 | 'gfm' => { class => 'Pod::Markdown::Github' }, | ||||||||||||||||||||||||||||
| 36 | 'github' => { class => 'Pod::Markdown::Github' }, | ||||||||||||||||||||||||||||
| 37 | 'html' => { class => 'Pod::Simple::HTML' }, | ||||||||||||||||||||||||||||
| 38 | 'markdown' => { class => 'Pod::Markdown' }, | ||||||||||||||||||||||||||||
| 39 | 'pod' => { class => undef }, | ||||||||||||||||||||||||||||
| 40 | 'rtf' => { class => 'Pod::Simple::RTF' }, | ||||||||||||||||||||||||||||
| 41 | 'text' => { class => 'Pod::Simple::Text' }, | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2 | has pod_class => ( | |||||||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||||||||
| 46 | isa => 'Maybe[Str]', | ||||||||||||||||||||||||||||
| 47 | lazy => 1, | ||||||||||||||||||||||||||||
| 48 | builder => '_build_pod_class', | ||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub _build_pod_class { | ||||||||||||||||||||||||||
|
Subroutine
_build_pod_class: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 52 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | my $fmt = $FORMATS{$self->type} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | or $self->log_fatal("Unsupported type: " . $self->type); | ||||||||||||||||||||||||||||
| 55 | 0 | $fmt->{class}; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 2 | has readme => ( | |||||||||||||||||||||||||||
| 59 | is => 'ro', | ||||||||||||||||||||||||||||
| 60 | isa => 'Str', | ||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub prune_files { | ||||||||||||||||||||||||||
|
Subroutine
prune_files: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | my $readme_file = first { $_->name =~ m{^README\z} } @{ $self->zilla->files }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ($readme_file and $readme_file->added_by =~ /Dist::Zilla::Plugin::Readme/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$readme_file and $readme_file->added_by =~ /Dist::Zilla::Plugin::Readme/
MC/DC0%0/2
$readme_file and $readme_file->added_by =~ /Dist::Zilla::Plugin::Readme/
$readme_file
$readme_file->added_by =~ /Dist::Zilla::Plugin::Readme/
Truth table0%0/3
A and B
A= $readme_fileB= $readme_file->added_by =~ /Dist::Zilla::Plugin::Readme/
| |||||||||||||||||||||||||||||
| 67 | 0 | $self->log_debug([ 'pruning %s', $readme_file->name ]); | |||||||||||||||||||||||||||
| 68 | 0 | $self->zilla->prune_file($readme_file); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub setup_installer { | ||||||||||||||||||||||||||
|
Subroutine
setup_installer: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 73 | 0 | my ($self, $arg) = @_; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | my $pod_class = $self->pod_class; | |||||||||||||||||||||||||||
| 76 | 0 | my $readme_name = $self->readme; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | ## guess pod_class from exisiting file, like GitHub will have README.md created | ||||||||||||||||||||||||||||
| 79 | 0 | my $readme_file; | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | if (not $readme_name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | my %ext = ( | |||||||||||||||||||||||||||
| 82 | 'md' => 'markdown', | ||||||||||||||||||||||||||||
| 83 | 'mkdn' => 'markdown', | ||||||||||||||||||||||||||||
| 84 | 'markdown' => 'markdown', | ||||||||||||||||||||||||||||
| 85 | 'html' => 'html', | ||||||||||||||||||||||||||||
| 86 | 'htm' => 'html', | ||||||||||||||||||||||||||||
| 87 | 'rtf' => 'rtf', | ||||||||||||||||||||||||||||
| 88 | 'txt' => 'text', | ||||||||||||||||||||||||||||
| 89 | '' => 'text', | ||||||||||||||||||||||||||||
| 90 | 'pod' => 'pod' | ||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||
| 92 | 0 | foreach my $e (keys %ext) { | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | my $test_readme_file = path($self->zilla->root)->child($e ? "README.$e" : 'README'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if (-e "$test_readme_file") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | $readme_file = $test_readme_file; | |||||||||||||||||||||||||||
| 96 | 0 | $pod_class = $FORMATS{ $ext{$e} }->{class}; | |||||||||||||||||||||||||||
| 97 | 0 | last; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | my $content; | |||||||||||||||||||||||||||
| 103 | 0 | my $prf = Pod::Readme->new( | |||||||||||||||||||||||||||
| 104 | input_file => $self->filename, | ||||||||||||||||||||||||||||
| 105 | translate_to_fh => IO::String->new($content), | ||||||||||||||||||||||||||||
| 106 | translation_class => $pod_class, | ||||||||||||||||||||||||||||
| 107 | force => 1, | ||||||||||||||||||||||||||||
| 108 | zilla => $self->zilla, | ||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||
| 110 | 0 | $prf->run(); | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ($readme_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | return $readme_file->spew_raw($content); | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | $readme_name ||= $prf->default_readme_file; | ||||||||||||||||||||||||||
|
Condition0%0/3
$readme_name ||= $prf->default_readme_file
MC/DC0%0/2
$readme_name ||= $prf->default_readme_file
$readme_name
$prf->default_readme_file
Truth table0%0/3
A ||= B
A= $readme_nameB= $prf->default_readme_file
| |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | my $file = first { $_->name eq $readme_name } @{ $self->zilla->files }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if ( $file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | $file->content( $content ); | |||||||||||||||||||||||||||
| 120 | 0 | $self->zilla->log("Override README from [ReadmeFromPod]"); | |||||||||||||||||||||||||||
| 121 | } else { | ||||||||||||||||||||||||||||
| 122 | 0 | require Dist::Zilla::File::InMemory; | |||||||||||||||||||||||||||
| 123 | 0 | $file = Dist::Zilla::File::InMemory->new({ | |||||||||||||||||||||||||||
| 124 | content => $content, | ||||||||||||||||||||||||||||
| 125 | name => "${readme_name}", # stringify, as it may be Path::Tiny | ||||||||||||||||||||||||||||
| 126 | }); | ||||||||||||||||||||||||||||
| 127 | 0 | $self->add_file($file); | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | return; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 2 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 134 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 2 | 1; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head1 NAME | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | Dist::Zilla::Plugin::ReadmeFromPod - dzil plugin to generate README from POD | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | # dist.ini | ||||||||||||||||||||||||||||
| 145 | [ReadmeFromPod] | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | # or | ||||||||||||||||||||||||||||
| 148 | [ReadmeFromPod] | ||||||||||||||||||||||||||||
| 149 | filename = lib/XXX.pod | ||||||||||||||||||||||||||||
| 150 | type = markdown | ||||||||||||||||||||||||||||
| 151 | readme = READTHIS.md | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | This plugin generates the F<README> from C<main_module> (or specified) | ||||||||||||||||||||||||||||
| 156 | by L<Pod::Readme>. | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =head2 Options | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | The following options are supported: | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =head3 C<filename> | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | The name of the file to extract the F<README> from. This defaults to | ||||||||||||||||||||||||||||
| 165 | the main module of the distribution. | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =head3 C<type> | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | The type of F<README> you want to generate. This defaults to "text". | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | Other options are "html", "pod", "markdown" and "rtf". | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =head3 C<pod_class> | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | This is the L<Pod::Simple> class used to translate a file to the | ||||||||||||||||||||||||||||
| 176 | format you want. The default is based on the L</type> setting, but if | ||||||||||||||||||||||||||||
| 177 | you want to generate an alternative type, you can set this option | ||||||||||||||||||||||||||||
| 178 | instead. | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =head3 C<readme> | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | The name of the file, which defaults to one based on the L</type>. | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =head2 Conflicts with Other Plugins | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | We will remove the README created by L<Dist::Zilla::Plugin::Readme> automatically. | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | Fayland Lam <fayland@gmail.com> and | ||||||||||||||||||||||||||||
| 191 | E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org> | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | Robert Rothenberg <rrwo@cpan.org> modified this plugin to use | ||||||||||||||||||||||||||||
| 194 | L<Pod::Readme>. | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | Copyright 2010-2015 Fayland Lam <fayland@gmail.com> and E<AElig>var | ||||||||||||||||||||||||||||
| 199 | ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org> | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | This program is free software, you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 202 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =cut | ||||||||||||||||||||||||||||