blib/lib/Dist/Zilla/Plugin/ChangelogFromGit/Debian.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 92 CC 11 SCAR 39.8
CC
11
Cov
0%
render_changelog
90.0
_build__build_id
12.0
BEGIN
2.0
CRAP 53.4
1 package Dist::Zilla::Plugin::ChangelogFromGit::Debian;
2 $Dist::Zilla::Plugin::ChangelogFromGit::Debian::VERSION = '0.10';
3 use Moose;
4  
5 # ABSTRACT: Debian formatter for Changelogs
6  
7 extends 'Dist::Zilla::Plugin::ChangelogFromGit';
8  
9 use DateTime::Format::Mail;
10 use Text::Wrap qw(wrap fill $columns $huge);
11  
12  
13 has 'allow_empty_head' => (
14 is => 'rw',
15 isa => 'Bool',
16 default => 1
17 );
18  
19  
20 has 'dist_name' => (
21 is => 'rw',
22 isa => 'Str',
23 default => 'stable'
24 );
25  
26  
27 has 'maintainer_email' => (
28 is => 'rw',
29 isa => 'Str',
30 default => defined($ENV{'DEBEMAIL'}) ? $ENV{'DEBEMAIL'} : 'cpan@example.com'
31 );
32  
33  
34 has 'maintainer_name' => (
35 is => 'rw',
36 isa => 'Str',
37 default => defined($ENV{'DEBFULLNAME'}) ? $ENV{'DEBFULLNAME'} : 'CPAN Author'
38 );
39  
40  
41 has 'package_name' => (
42 is => 'rw',
43 isa => 'Str',
44 lazy => 1,
45 default => sub {
46 my $self = shift;
47 return lc($self->zilla->name)
48 }
49 );
50  
51  
52 has _build_id => (
53 is => 'ro',
54 isa => 'Str',
55 lazy => 1,
56 builder => '_build__build_id',
57 );
58  
59 sub _build__build_id {
60 my $self = shift;
61  
62 my $build = ( defined $ENV{BUILD_ID} ) ? $ENV{BUILD_ID} : 0;
63 die "Invalid build identifier used" unless $build =~ m/^[a-zA-Z0-9]+$/;
64  
65 return $build;
66 }
67  
68 sub render_changelog {
69 my ($self) = @_;
70  
71 $Text::Wrap::huge = 'wrap';
72 $Text::Wrap::columns = $self->wrap_column;
73
74 my $changelog = '';
75
76 foreach my $release (reverse $self->all_releases) {
77  
78 # Don't output empty versions, unless it's HEAD cuz that might matter!
79 next if $release->has_no_changes && $release->version ne 'HEAD';
80 if($release->version eq 'HEAD') {
81 next unless $self->allow_empty_head;
82 }
83  
84 my $version = $release->version;
85 if($version eq 'HEAD') {
86 $version = $self->zilla->version;
87 } else {
88 my $tag_regexp = $self->tag_regexp();
89 $version =~ s/$tag_regexp/$1/;
90 }
91  
92 $version .= '.' . $self->_build_id if $self->_build_id;
93  
94 my $tag_line = $self->package_name.' ('.$version.') '.$self->dist_name.'; urgency=low';
95 $changelog .= (
96 "$tag_line\n"
97 );
98  
99 my $firstchange = undef;
100 foreach my $change (@{ $release->changes }) {
101 unless(defined($firstchange)) {
102 $firstchange = $change;
103 }
104 unless ($change->description =~ /^\s/) {
105 $changelog .= fill(" ", " ", '* '.$change->description)."\n";
106 }
107 }
108 if($release->has_no_changes) {
109 $firstchange = Software::Release::Change->new(
110 description => 'no changes',
111 date => DateTime->now
112 );
113 }
114 $changelog .= "\n -- ".$self->maintainer_name.' <'.$self->maintainer_email.'> '.DateTime::Format::Mail->format_datetime($firstchange->date)."\n\n";
115 }
116
117 return $changelog;
118 }
119  
120  
121 __PACKAGE__->meta->make_immutable;
122 no Moose;
123 1;
124  
125 __END__