File Coverage

blib/lib/Dist/Zilla/Plugin/Author/Plicease/ReadmeAnyFromPod.pm
Criterion Covered Total %
statement 20 21 95.2
branch n/a
condition n/a
subroutine 7 8 87.5
pod 0 1 0.0
total 27 30 90.0


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::Author::Plicease::ReadmeAnyFromPod 2.73 {
2              
3 1     1   1037 use 5.020;
  1         5  
4 1     1   19 use Moose;
  1         3  
  1         8  
5 1     1   7592 use URI::Escape ();
  1         1656  
  1         61  
6 1     1   15 use File::Which ();
  1         4  
  1         32  
7 1     1   548 use Ref::Util qw( is_plain_hashref );
  1         1898  
  1         114  
8 1     1   13 use experimental qw( postderef );
  1         5  
  1         7  
9              
10             # ABSTRACT: Personal subclass of Dist::Zilla::Plugin::ReadmeAnyFromPod
11              
12              
13             extends 'Dist::Zilla::Plugin::ReadmeAnyFromPod';
14              
15             around BUILDARGS => sub {
16             my $orig = shift;
17             my $class = shift;
18              
19             my %args = @_ == 1 && is_plain_hashref($_[0]) ? $_[0]->%* : @_;
20             foreach my $key (keys %args)
21             {
22             die "removed key: $key"
23             if $key =~ /^(travis_.*|appveyor_user|appveyor)$/;
24             }
25              
26             return $class->$orig(@_);
27             };
28              
29             has cirrus_user => (
30             is => 'ro',
31             lazy => 1,
32             default => sub {
33             my($self) = @_;
34             $self->github_user;
35             },
36             );
37              
38             has github_user => (
39             is => 'ro',
40             default => 'plicease',
41             );
42              
43             has workflow => (
44             is => 'ro',
45             isa => 'ArrayRef[Str]',
46             default => sub { [] },
47             );
48              
49             has default_branch => (
50             is => 'ro',
51             lazy => 1,
52             default => sub {
53             my($self) = @_;
54             if(File::Which::which('git'))
55             {
56             my %b = map { $_ => 1 }
57             map { s/\s$//r }
58             map { s/^\*?\s*//r }
59             `git branch`;
60             if($b{main} && $b{master})
61             {
62             $self->log("!! You have both a main and master branch, please switch to just a main branch (or explicitly set default_branch) !!");
63             return 'main';
64             }
65             elsif($b{main})
66             {
67             $self->log("deteching main as default branch");
68             return 'main';
69             }
70             elsif($b{master})
71             {
72             $self->log("!! Please switch to using main as the main branch (or explicitly set default_branch) !!");
73             return 'master';
74             }
75             else
76             {
77             $self->log("!! cannot find either a main or master branch please create one or explicitly set default_branch !!");
78             return 'main';
79             }
80             }
81             $self->log("unable to detect default branch assuming main");
82             return 'main'; # may need to update the repo
83             },
84             );
85              
86 0     0 0   sub mvp_multivalue_args { qw( workflow ) }
87              
88             around get_readme_content => sub {
89             my $orig = shift;
90             my $self = shift;
91              
92             my $content = do {
93 1     1   886 no warnings 'redefine';
  1         6  
  1         531  
94             local *URI::Escape::uri_escape = sub {
95             my($uri) = @_;
96             $uri;
97             };
98              
99             $self->$orig(@_);
100             };
101              
102             return $content unless $self->type eq 'gfm';
103              
104             my $status = do {
105             my $name = $self->zilla->name;
106              
107             my $cirrus_status = -f $self->zilla->root->child('.cirrus.yml');
108              
109             my $status = '';
110             $status .= " [![Build Status](https://api.cirrus-ci.com/github/@{[ $self->cirrus_user ]}/$name.svg)](https://cirrus-ci.com/github/@{[ $self->cirrus_user ]}/$name)" if $cirrus_status;
111              
112             foreach my $workflow ($self->workflow->@*)
113             {
114             $status .= " ![$workflow](https://github.com/@{[ $self->github_user ]}/$name/workflows/$workflow/badge.svg)";
115             }
116             $status;
117             };
118              
119             $content =~ s{# NAME\s+(.*?) - (.*?#)}{# $1$status\n\n$2}s;
120             $content =~ s{# VERSION\s+version (\d+\.|)\d+\.\d+(\\_\d+|)\s+#}{#}a;
121             return $content;
122             };
123              
124             __PACKAGE__->meta->make_immutable;
125             }
126              
127             1;
128              
129             __END__
130              
131             =pod
132              
133             =encoding UTF-8
134              
135             =head1 NAME
136              
137             Dist::Zilla::Plugin::Author::Plicease::ReadmeAnyFromPod - Personal subclass of Dist::Zilla::Plugin::ReadmeAnyFromPod
138              
139             =head1 VERSION
140              
141             version 2.73
142              
143             =head1 SYNOPSIS
144              
145             [Author::Plicease::ReadmeAnyFromPod]
146              
147             =head1 SEE ALSO
148              
149             =over 4
150              
151             =item L<Dist::Zilla>
152              
153             =item L<Dist::Zilla::PluginBundle::Author::Plicease>
154              
155             =back
156              
157             =head1 AUTHOR
158              
159             Graham Ollis <plicease@cpan.org>
160              
161             =head1 COPYRIGHT AND LICENSE
162              
163             This software is copyright (c) 2012-2022 by Graham Ollis.
164              
165             This is free software; you can redistribute it and/or modify it under
166             the same terms as the Perl 5 programming language system itself.
167              
168             =cut