blib/lib/SVN/Notify/Alternative.pm

filter: Statementstmt 100% 27 / 27 Branchbran 100% 8 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 100% 44 / 44 SCAR 17.9
CC
6
Cov
100%
output
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 6.0
« Build ↑ Summary blib/lib/SVN/Notify/Filter/Trac.pm »
1 package SVN::Notify::Alternative;
2  
3 32 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 32 ▶use SVN::Notify ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 32 $SVN::Notify::Alternative::VERSION = '1.0';
7 32 @SVN::Notify::Alternative::ISA = qw(SVN::Notify);
8  
9 32 __PACKAGE__->register_attributes(
10 alternatives => 'alternative|alt=s@',
11 );
12  
13 =head1 Name
14  
15 SVN::Notify::Alternative - MIME multipart/alternative notification
16  
17 =head1 Synopsis
18  
19 Use F<svnnotify> in F<post-commit>:
20  
21 svnnotify --repos-path "$1" --revision "$2" \
22 --to developers@example.com --handler Alternative [options]
23  
24 For example:
25  
26 svnnotify --repos-path "$1" --revision "$2" \
27 --to developers@example.com --handler Alternative \
28 --alternative HTML::ColorDiff
29  
30 Use the class in a custom script:
31  
32 use SVN::Notify::Alternative;
33  
34 my $notifier = SVN::Notify::Alternative->new(%params);
35 $notifier->prepare;
36 $notifier->execute;
37  
38 =head1 Description
39  
40 This subclass of L<SVN::Notify|SVN::Notify> sends MIME multipart/alternative
41 email messages for Subversion activity. The messages contain both the standard
42 SVN::Notify plain text change notification and one or more alternative formats
43 of the message. The default alternative format is L<HTML|SVN::Notify::HTML>.
44  
45 Note that this means that many or all of the processing of a subversion commit
46 will be executed multiple times, once for the plain text version and then
47 again for each alternative version. This will therefore increase resource
48 usage on your Subversion server (mainly processor time, but also possibly
49 memory).
50  
51 It also means that the size of the outgoing message will increase for each
52 alternative. If you're using C<--with-diff>, then those messages could be very
53 large indeed for large commits. If, however, you use C<--attach-diff>, the
54 diff will only be attached to the last alternative.
55  
56 =head1 Usage
57  
58 To use SVN::Notify::Alternative, simply follow the
59 L<instructions|SVN::Notify/Usage> in SVN::Notify, but when using F<svnnotify>,
60 use the C<--alternative> option to add one or more alternative formats.
61  
62 =cut
63  
64 ##############################################################################
65  
66 =head1 Class Interface
67  
68 =head2 Constructor
69  
70 =head3 new
71  
72 my $notifier = SVN::Notify::Alternative->new(%params);
73  
74 Constructs and returns a new SVN::Notify object. All parameters supported by
75 SVN::Notity are supported here, as are the options of all specified
76 alternative formats, but SVN::Notify::Alternative supports an additional
77 parameter:
78  
79 =over
80  
81 =item alternatives
82  
83 svnnotify --alternative HTML
84 svnnotify --alt HTML --alt HTML::ColorDiff
85  
86 An array reference that specifies the SVN::Notify handlers (subclasses) to be
87 used for formatting the alternative parts of the notification message. The
88 command-line option may be called as either C<--alternative> or C<--alt>, and
89 the value is the same as that of the SVN::Notify C<--handler> parameter, i.e.
90 the module name without the "SVN::Notify::" prefix. Specify the option
91 multiple times to specify multiple alternative handlers. Defaults to
92 C<['HTML']> if not specified.
93  
94 =back
95  
96 =cut
97  
98 ##############################################################################
99  
100 =head1 Instance Interface
101  
102 =head2 Instance Methods
103  
104 =head3 output
105  
106 $notifier->output($file_handle);
107  
108 Overrides the C<output()> method of SVN::Notify to replace the standard
109 message output with a MIME C<multipart/alternative> skeleton. It then creates
110 new instances of the standard SVN::Notify plain text formatter and each of the
111 configured alternative formatters, and uses those instances to fill in the
112 alternative parts of the message. If C<attach_diff> is true, it will be used
113 only in the last alternative to be output, which should also be the richest
114 format.
115  
116 =cut
117  
118 sub output {
119 109 ▶ my ($self, $out) = @_;
Subroutine output: called CC=6 SCAR=17.9
Pod documented
120  
121 # Output the headers. Leave out the attachment header.
122 109 my $attach = $self->attach_diff;
123 109 ▶ if ($attach) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attach) 10 99 109
124 10 $self->attach_diff(undef);
125 10 $self->with_diff(undef);
126 }
127 109 $self->output_headers($out);
128  
129 # Output the multipart/alternative header.
130 109 my $bound = join '', ('a'..'z', 'A'..'Z', 0..9)[ map { rand 62 } 0..10];
131 109 print $out qq{Content-Type: multipart/alternative; boundary="$bound"\n},
132 "Content-Transfer-Encoding: 8bit\n\n";
133  
134 # Determine all of the handlers to use.
135 109 my $alts = $self->{alternatives};
136 109 ▶ $alts = ['HTML'] unless $alts;
Branch: 1 branch
BranchTrueFalseTotal
unless $alts 72 37 109
137 109 unshift @$alts, ''; # Plain text first.
138  
139 # Now output each of the alternatives.
140 109 ▶ while (@$alts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$alts) 228 99 327
141 228 print $out "--$bound\n";
142 # Attach diff only to last version.
143 228 ▶ SVN::Notify->new(
Branch: 1 branch
BranchTrueFalseTotal
$attach && !@$alts ? : 10 218 228
Condition100%3/3
$attach and not @$alts
!ll&&!rl&&r
2081010
MC/DC100%2/2
$attach and not @$alts
$attach not @$alts
Truth table100%3/3
A and not(B)
A= $attachB= not @$alts
ABresult
0X0
100
111
144 %$self,
145 handler => shift @$alts,
146 ($attach && !@$alts ? ( attach_diff => 1) : ()),
147 )->output($out, 1);
148 }
149  
150 # Finish up!
151 99 print $out "--$bound--\n";
152 99 return $self;
153 }
154  
155 ##############################################################################
156  
157 =head2 Accessors
158  
159 In addition to those supported by L<SVN::Notify|SVN::Notify/Accessors>,
160 SVN::Notify::Alternative supports the following accessors:
161  
162 =head3 alternatives
163  
164 my $alts = $notify->alternatives;
165 $notify->alternatives($alts);
166  
167 Gets or sets the value of the C<alternatives> attribute, which must always be
168 set to an array reference.
169  
170 =cut
171  
172 32 1;
173 __END__
« Build ↑ Summary blib/lib/SVN/Notify/Filter/Trac.pm »