File Coverage

lib/Dist/Zilla/Plugin/Author/GSG.pm
Criterion Covered Total %
statement 37 37 100.0
branch 10 12 83.3
condition 6 6 100.0
subroutine 7 7 100.0
pod n/a
total 60 62 96.7


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::Author::GSG;
2 2     2   215493 use Moose;
  2         449330  
  2         24  
3             with qw(
4             Dist::Zilla::Role::Plugin
5             );
6 2     2   15144 use Git::Wrapper qw();
  2         4  
  2         71  
7 2     2   10 use version;
  2         4  
  2         22  
8 2     2   179 use namespace::autoclean;
  2         7  
  2         36  
9              
10             # ABSTRACT: Grant Street Group defaults CPAN dists
11 2     2   180 use version;
  2         4  
  2         10  
12             our $VERSION = 'v0.5.0'; # VERSION
13              
14             before 'BUILDARGS' => \&_BUILDARGS;
15              
16             sub _git_version_ok {
17 24     24   321365 my ($git_version) = @_;
18              
19             # Apple says: "2.21.1 (Apple Git-122.3)" so we need the regex
20 24 50       856 $git_version = $1 if $git_version =~ /^(\d+(?:\.\d+)*)/;
21              
22 24         1641 return version->parse("v$git_version") >= v1.7.5;
23             }
24              
25             # Use a named sub for Devel::Cover
26             sub _BUILDARGS {
27 23     23   956 my ($class, $args) = @_;
28              
29             $args->{zilla}->{authors}
30 23   100     355 ||= ['Grant Street Group <developers@grantstreet.com>'];
31              
32 23   100     323 $args->{zilla}->{_license_class} ||= 'Artistic_2_0';
33 23   100     316 $args->{zilla}->{_copyright_holder} ||= 'Grant Street Group';
34              
35 23 100       152 if ( not $args->{zilla}->{_copyright_year} ) {
36 22         807 my $git = Git::Wrapper->new( $args->{zilla}->root );
37              
38             # We need v1.7.5 of git in order to get all the flags
39             # necessary to do all the things.
40 22         2066 my $git_version = $git->version;
41              
42             $args->{zilla}
43 22 100       231247 ->log_fatal( "[Author::GSG] Git 1.7.5 or greater is required"
44             . ", only have $git_version." )
45             unless _git_version_ok($git_version);
46              
47 18         94 local $@;
48 18         77 my ( $commit, $date ) = eval { local $SIG{__DIE__};
  18         427  
49 18         576 $git->rev_list(qw( --max-parents=0 --pretty=format:%ai HEAD )) };
50              
51 18         263804 my $year = 1900 + (localtime)[5];
52 18 100       242 if ($date) {
53 8         126 my $this_year = $year;
54 8 50       443 $year = $1 if $date =~ /^(\d{4})/;
55 8 100       178 $year .= " - $this_year" unless $year == $this_year;
56             }
57             else {
58 10         434 $args->{zilla}->log("Didn't find copyright start date: $@");
59             }
60              
61 18         17853 $args->{zilla}->{_copyright_year} = $year;
62             }
63             }
64              
65             __PACKAGE__->meta->make_immutable;
66             1;
67              
68             __END__
69              
70             =pod
71              
72             =encoding UTF-8
73              
74             =head1 NAME
75              
76             Dist::Zilla::Plugin::Author::GSG - Grant Street Group defaults CPAN dists
77              
78             =head1 VERSION
79              
80             version v0.5.0
81              
82             =head1 SYNOPSIS
83              
84             If you don't want the whole L<Dist::Zilla::PluginBundle::Author::GSG>
85             you can get the licence and author default from this Plugin.
86              
87             name = Foo-Bar-GSG
88             [@Basic]
89             [Author::GSG]
90              
91             Which is the same as
92              
93             name = Foo-Bar-GSG
94             author = Grant Street Group <developers@grantstreet.com>
95             license = Artistic_2_0
96             copyright_holder = Grant Street Group
97             copyright_year = # detected from git
98              
99             [@Basic]
100              
101             =head1 DESCRIPTION
102              
103             Provides a default license L<Software::License::Artistic_2_0>,
104             as well as default authors, copyright holder, and copyright years from git.
105              
106             =head1 AUTHOR
107              
108             Grant Street Group <developers@grantstreet.com>
109              
110             =head1 COPYRIGHT AND LICENSE
111              
112             This software is Copyright (c) 2019 - 2023 by Grant Street Group.
113              
114             This is free software, licensed under:
115              
116             The Artistic License 2.0 (GPL Compatible)
117              
118             =cut