blib/lib/Dist/Zilla/Plugin/EmailNotify.pm

filter: Statementstmt 35.6% 31 / 87 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 53.8% 7 / 13 Podpod 66.6% 2 / 3 totaltotal 28.1% 40 / 142 CC 17 SCAR 39.6
CC
17
Cov
26%
extract_last_release
110.0
after_release
56.0
_build_to
6.0
CRAP 52.3
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Dist::Zilla::Plugin::EmailNotify;
4 # ABSTRACT: send an email on dist release
5 1 $Dist::Zilla::Plugin::EmailNotify::VERSION = '0.004';
6 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 with 'Dist::Zilla::Role::AfterRelease';
8  
9 1 ▶use Email::Stuffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 has to => (
15 is => 'ro',
16 isa => 'Str',
17 lazy_build => 1,
18 );
19  
20 1 has recipient => (
21 is => 'ro',
22 isa => 'ArrayRef[Str]',
23 predicate => 'has_recipient',
24 );
25  
26 1 has from => (
27 is => 'ro',
28 isa => 'Str',
29 required => 1,
30 );
31  
32 has cc => (
33 is => 'ro',
34 isa => 'ArrayRef[Str]',
35 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 1 );
37  
38 has bcc => (
39 is => 'ro',
40 isa => 'ArrayRef[Str]',
41 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 1 );
43  
44 1 has change_file => (
45 is => 'ro',
46 isa => 'Str',
47 default => 'Changes',
48 );
49  
50 0 ▶sub mvp_multivalue_args { qw/recipient cc bcc/ }
Subroutine mvp_multivalue_args: not called CC=1 SCAR=6.9
Pod documented
51  
52 0 ▶sub _build_to {
Subroutine _build_to: not called CC=2 SCAR=17.9
53 0 my $self = shift;
54  
55 0 ▶ $self->has_recipient
Branch: 1 branch
BranchTrueFalseTotal
$self->has_recipient or die "Must provide 'recipient' or 'to'\n" 0 0 0
56 or die "Must provide 'recipient' or 'to'\n";
57  
58 0 return join ', ', @{ $self->recipient };
59 }
60  
61 0 ▶sub after_release {
Subroutine after_release: not called CC=7 SCAR=40.3
Pod documented
62 0 my $self = shift;
63 0 my $archive = shift;
64 0 my $name = $self->zilla->name;
65 0 my $to = $self->to;
66 0 my $from = $self->from;
67 0 my $cc = join ', ', @{ $self->cc };
68 0 my $bcc = join ', ', @{ $self->bcc };
69  
70 0 $name =~ s/\.tar\.gz$//;
71 0 my $v = $self->zilla->version;
72  
73 # skip mail for developer's version
74 0 ▶ if ($v =~ /_/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /_/) 0 0 0
75 0 $self->log("No e-mail sent for a developer release") ;
76 0 return 1 ;
77 }
78  
79 0 my @body ;
80 0 push @body, "New version $v of $name is available with the following changes:";
81 0 push @body, '', $self->extract_last_release($self->change_file);
82  
83 0 ▶ my $res = $self->zilla->distmeta
Condition0%0/2
$self->zilla->distmeta || die('internal error')
l!l
00
MC/DC0%0/1
$self->zilla->distmeta || die('internal error')
$self->zilla->distmeta
Truth table0%0/2
A
A= $self->zilla->distmeta
Aresult
11
00
84 || die "internal error";
85  
86 0 my $repo = $res->{repository} ;
87 0 ▶ push @body,'', "Homepage: ".$res->{homepage} if $res->{homepage} ;
Branch: 1 branch
BranchTrueFalseTotal
if $res->{"homepage"} 0 0 0
88 0 ▶ push @body,"Repository: ".$repo->{web} if $repo->{web};
Branch: 1 branch
BranchTrueFalseTotal
if $repo->{"web"} 0 0 0
89  
90 0 push @body,'', "Authors:", map { " - $_"} @{ $self->zilla->authors };
91  
92 0 my $text_body = join("\n",@body);
93 0 $self->log($text_body);
94  
95 0 my $email
96 = Email::Stuffer->subject("$name $v released!")
97 ->from($from)
98 ->to($to)
99 ->text_body($text_body);
100  
101 0 ▶ $cc and $email->cc($cc);
Branch: 1 branch
BranchTrueFalseTotal
$cc and $email->cc($cc) 0 0 0
102 0 ▶ $bcc and $email->bcc($bcc);
Branch: 1 branch
BranchTrueFalseTotal
$bcc and $email->bcc($bcc) 0 0 0
103  
104 0 $self->log("Sending release email to $to") ;
105  
106 0 return $email->send;
107 }
108  
109 0 ▶sub extract_last_release {
Subroutine extract_last_release: not called CC=10 SCAR=47.0
Pod undocumented
110 0 my $self = shift;
111 0 my $file = shift;
112  
113 0 my $fh = IO::File->new;
114 0 $fh->open($file, 'r') ;
115  
116 0 my $preamble = '';
117 0 ▶ while (my $l = $fh->getline ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $l = $fh->getline) 0 0 0
118 0 ▶ last if $l =~ /^\w/ ; # first release line, preamble is done
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /^\w/ 0 0 0
119 0 $preamble .= $l;
120 } ;
121  
122 0 my @changes ;
123 0 ▶ while (my $l = $fh->getline ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $l = $fh->getline) 0 0 0
124 0 chomp $l;
125 0 ▶ if ($l =~ /^\s/ or $l =~ /^$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($l =~ /^\s/ or $l =~ /^$/) { } 0 0 0
elsif (join('', @changes) =~ /\w/ and $l =~ /^[\d\.]+\s+/) { } 0 0 0
Condition0%0/3
$l =~ /^\s/ or $l =~ /^$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$l =~ /^\s/ or $l =~ /^$/
$l =~ /^\s/ $l =~ /^$/
Truth table0%0/3
A or B
A= $l =~ /^\s/B= $l =~ /^$/
ABresult
1X1
011
000
126 # not at a release line
127 0 push @changes, $l;
128 }
129 ▶ elsif (join('',@changes) =~ /\w/ and $l =~ /^[\d\.]+\s+/) {
Condition0%0/3
join("", @changes) =~ /\w/ and $l =~ /^[\d\.]+\s+/
!ll&&!rl&&r
000
MC/DC0%0/2
join("", @changes) =~ /\w/ and $l =~ /^[\d\.]+\s+/
join("", @changes) =~ /\w/ $l =~ /^[\d\.]+\s+/
Truth table0%0/3
A and B
A= join("", @changes) =~ /\w/B= $l =~ /^[\d\.]+\s+/
ABresult
0X0
100
111
130 # quit if I have change info and a release
131 0 last;
132 };
133 } ;
134 0 $fh->close;
135  
136 # remove empty line from beginning and end of change lines
137 0 ▶ shift @changes while not $changes[0] ;
Branch: 1 branch
BranchTrueFalseTotal
$changes[0] or do { shift @changes } 0 0 0
138 0 ▶ pop @changes while not $changes[-1];
Branch: 1 branch
BranchTrueFalseTotal
$changes[-1] or do { pop @changes } 0 0 0
139  
140 0 return @changes;
141 }
142  
143  
144 1 __PACKAGE__->meta->make_immutable;
145 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
146  
147 1 1;
148  
149 __END__
↑ Summary