blib/lib/SVN/Notify/HTML.pm

filter: Statementstmt 100% 132 / 132 Branchbran 91.3% 53 / 58 Conditioncond 87.5% 21 / 24 MC/DCmcdc 75.0% 12 / 16 Subroutinesub 100% 14 / 14 Podpod 100% 9 / 9 totaltotal 95.2% 241 / 253 SCAR 37.2
CC
41
Cov
96%
output_file_lists
11.0
output_log_message
10.0
output_diff
9.0
CRAP 41.1
« blib/lib/SVN/Notify.pm ↑ Summary blib/lib/SVN/Notify/HTML/ColorDiff.pm »
1 package SVN::Notify::HTML;
2  
3 198 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 198 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 198 ▶use SVN::Notify ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 198 $SVN::Notify::HTML::VERSION = '2.86';
8 198 @SVN::Notify::HTML::ISA = qw(SVN::Notify);
9  
10 198 __PACKAGE__->register_attributes(
11 linkize => 'linkize',
12 css_url => 'css-url=s',
13 wrap_log => 'wrap-log',
14 );
15  
16 =head1 Name
17  
18 SVN::Notify::HTML - Subversion activity HTML notification
19  
20 =head1 Synopsis
21  
22 Use F<svnnotify> in F<post-commit>:
23  
24 svnnotify --repos-path "$1" --revision "$2" \
25 --to developers@example.com --handler HTML [options]
26  
27 Use the class in a custom script:
28  
29 use SVN::Notify::HTML;
30  
31 my $notifier = SVN::Notify::HTML->new(%params);
32 $notifier->prepare;
33 $notifier->execute;
34  
35 =head1 Description
36  
37 This subclass of L<SVN::Notify|SVN::Notify> sends HTML formatted email
38 messages for Subversion activity, rather than the default plain text.
39  
40 =head1 Prerequisites
41  
42 In addition to the modules required by SVN::Notify, this class requires:
43  
44 =over
45  
46 =item HTML::Entities
47  
48 =back
49  
50 =head1 Usage
51  
52 To use SVN::Notify::HTML, simply follow the L<instructions|SVN::Notify/Usage>
53 in SVN::Notify, but when using F<svnnotify>, specify C<--handler HTML>.
54  
55 =cut
56  
57 ##############################################################################
58  
59 =head1 Class Interface
60  
61 =head2 Constructor
62  
63 =head3 new
64  
65 my $notifier = SVN::Notify::HTML->new(%params);
66  
67 Constructs and returns a new SVN::Notify object. All parameters supported by
68 SVN::Notity are supported here, but SVN::Notify::HTML supports a few
69 additional parameters:
70  
71 =over
72  
73 =item linkize
74  
75 svnnotify --linkize
76  
77 A boolean attribute to specify whether or not to "linkize" the SVN log
78 message--that is, to turn any URLs or email addresses in the log message into
79 links.
80  
81 =item css_url
82  
83 svnnotify --css-url http://example.com/svnnotify.css
84  
85 URL for a CSS file that will can style the HTML output by SVN::Notify::HTML or
86 its subclasses. Note that the URL will be added to the output via a
87 C<< <link rel="stylesheet"> >> tag I<after> the CSS generated by
88 SVN::Notify::HTML or its subclasses. What that means is that the CSS file
89 specified by C<css_url> need not completely style the HTML, but simply
90 override the default settings. This approach nicely takes advantage of the
91 "cascading" abilities of CSS.
92  
93 =item ticket_map
94  
95 svnnotify --ticket-map '(BUG-(\d+))=http://bugs.example.com/?show=%s'
96  
97 This attribute is inherited from L<SVN::Notify|SVN::Notify>, but its semantics
98 are slightly different: the regular expression passed as the regular
99 expression used for the key should return I<two> matches instead of one: the
100 text to link and the ticket ID itself. For example, '(BUG-(\d+))' will match
101 "BUG-1234567", and "BUG-1234567" will be used for the link text, while
102 "1234567" will be used to fill in the C<ticket_url> format string. The first
103 set of parentheses capture the whole string, while the parentheses around
104 C<\d+> match the number only. Also note that it is wise to use "\b" on either
105 side of the regular expression to insure that you don't get spurious matches.
106 So a better version would be '\b(BUG-(\d+))\b'.
107  
108 As a fallback, if your regular expression returns only a single match string,
109 it will be used both for the link text and for the the ticket URL generated
110 from C<ticket_url>. For example, '\bBUG-(\d+)\b' would make a link only of the
111 number in 'BUG-1234567', as only the number has been captured by the regular
112 expression. But two matches are of course recommended (and likely to work
113 better, as well).
114  
115 You can use more complicated regular expressions if commit messages are likely
116 to format ticket numbers in various ways. For example, this regular
117 expression:
118  
119 \b\[?\s*(Ticket\s*#\s*(\d+))\s*\]?\b'
120  
121 Will match:
122  
123 String Matched Link Text Ticket Number
124 --------------------|--------------------|---------------
125 [Ticket#1234] [Ticket#1234] 1234
126 [ Ticket # 1234 ] [ Ticket # 1234 ] 1234
127 Ticket #1234 Ticket #1234 1234
128 Ticket # 1234 Ticket #1234 1234
129  
130 In any of these cases, you can see that the match is successful, properly
131 creates the link text (simply using the text as typed in by the committer, and
132 correctly extracts the ticket number for use in the URL.
133  
134 To learn more about the power of Regular expressions, I highly recommend
135 _Mastering Regular Expressions, Second Edition_, by Jeffrey Friedl.
136  
137 =item wrap_log
138  
139 svnnotify --wrap-log
140  
141 A boolean attribute to specify whether or not to wrap the log message in the
142 output HTML. By default, log messages are I<not> wrapped, on the assumption
143 that they should appear exactly as typed. But if that's not the case, specify
144 this option to wrap the log message.
145  
146 =back
147  
148 =cut
149  
150 ##############################################################################
151  
152 =head2 Class Methods
153  
154 =head3 content_type
155  
156 Returns the content type of the notification message, "text/html". Used to set
157 the Content-Type header for the message.
158  
159 =cut
160  
161 1139 ▶sub content_type { 'text/html' }
Subroutine content_type: called CC=1 SCAR=0.0
Pod documented
162  
163 ##############################################################################
164  
165 =head1 Instance Interface
166  
167 =head2 Instance Methods
168  
169 =head3 start_html
170  
171 $notifier->start_html($file_handle);
172  
173 This method starts the HTML of the notification message. It outputs the
174 opening C<< <html> >>, C<< <head> >>, and C<< <body> >> tags. Note that if the
175 C<language> attribute is set to a value, it will be specified in the
176 C<< <html> >> tag.
177  
178 All of the HTML will be passed to any "start_html" output filters. See
179 L<Writing Output Filters|SVN::Notify/"Writing Output Filters"> for details on
180 filters.
181  
182 =cut
183  
184 sub start_html {
185 1077 ▶ my ($self, $out) = @_;
Subroutine start_html: called CC=3 SCAR=11.0
Pod documented
186 1077 my $lang = $self->language;
187 1077 my $char = lc $self->encoding;
188  
189 my @html = (
190 qq{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"\n},
191 qq{"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n},
192 qq{<html xmlns="http://www.w3.org/1999/xhtml"},
193 ($lang ? qq{ xml:lang="$lang"} : ()),
194 qq{>\n<head><meta http-equiv="content-type" content="text/html; },
195 qq{charset=$char" />\n},
196 ( $self->{css_url}
197 ? (
198 '<link rel="stylesheet" type="text/css" href="',
199 1077 ▶ encode_entities($self->{css_url}),
Branch: 2 branches
BranchTrueFalseTotal
$lang ? : 45 1032 1077
$self->{'css_url'} ? : 48 1029 1077
200 qq{" />\n}
201 ) : ()
202 ),
203 '<title>', encode_entities($self->subject, '<>&"'),
204 qq{</title>\n</head>\n<body>\n\n}
205 );
206  
207 1077 print $out @{ $self->run_filters( start_html => \@html ) };
208 1077 return $self;
209 }
210  
211 ##############################################################################
212  
213 =head3 start_body
214  
215 This method starts the body of the HTML notification message. It first calls
216 C<start_html()>, and then outputs the C<< <style> >> tag, calling
217 C<output_css()> between them. It then outputs an opening C<< <div> >> tag.
218  
219 If the C<header> attribute is set, C<start_body()> outputs it between
220 C<< <div> >> tags with the ID "header". Furthermore, if the header happens to
221 start with the character "E<lt>", C<start_body()> assumes that it contains
222 valid HTML and therefore will not escape it.
223  
224 If a "start_body" output filter has been specified, it will be passed the
225 lines with the C<< <div> >> tag and the header. To filter the CSS, use a "css"
226 filter, and to filter the declaration of the HTML document and its C<< <head>
227 >> section, use a "start_html" filter. See L<Writing Output
228 Filters|SVN::Notify/"Writing Output Filters"> for details on filters.
229  
230 =cut
231  
232 sub start_body {
233 1077 ▶ my ($self, $out) = @_;
Subroutine start_body: called CC=3 SCAR=11.0
Pod documented
234 1077 $self->start_html($out);
235 1077 print $out qq{<style type="text/css"><!--\n};
236 1077 $self->output_css( $out );
237 1077 print $out qq{--></style>\n};
238  
239 1077 my @html = ( qq{<div id="msg">\n} );
240 1077 ▶ if (my $header = $self->header) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $header = $self->header) 13 1064 1077
241 13 ▶ push @html, (
Branch: 1 branch
BranchTrueFalseTotal
$header =~ /^</ ? : 4 9 13
242 '<div id="header">',
243 ( $header =~ /^</ ? $header : encode_entities($header, '<>&"') ),
244 "</div>\n",
245 );
246 }
247  
248 1077 print $out @{ $self->run_filters( start_body => \@html ) };
249 1077 return $self;
250 }
251  
252 ##############################################################################
253  
254 =head3 output_css
255  
256 $notifier->output_css($file_handle);
257  
258 This method starts outputs the CSS for the HTML message. It is called by
259 C<start_body()>, and which wraps the output of C<output_css()> in the
260 appropriate C<< <style> >> tags.
261  
262 An output filter named "css" may be added to modify the output of CSS. The
263 filter subroutine name should be C<css> and expect an array reference of lines
264 of CSS. See L<Writing Output Filters|SVN::Notify/"Writing Output Filters"> for
265 details on filters.
266  
267 =cut
268  
269 sub output_css {
270 1077 ▶ my ($self, $out) = @_;
Subroutine output_css: called CC=1 SCAR=0.0
Pod documented
271 # We use _css() so that ColorDiff can override it and the filters then
272 # applied only one to all of the CSS.
273 1077 print $out @{ $self->run_filters( css => $self->_css ) };
274 1077 return $self;
275 }
276  
277 ##############################################################################
278  
279 =head3 output_metadata
280  
281 $notifier->output_metadata($file_handle);
282  
283 This method outputs a definition list containing the meta data of the commit,
284 including the revision number, author (user), and date of the revision. If the
285 C<revision_url> attribute has been set, then the appropriate URL for the
286 revision will be used to turn the revision number into a link.
287  
288 If there are any C<log_message> filters, this method will do no HTML
289 formatting, but redispatch to
290 L<SVN::Notify::output_metadata|SVN::Notify/"output_metadata">. See L<Writing
291 Output Filters|SVN::Notify/"Writing Output Filters"> for details on filters.
292  
293 =cut
294  
295 sub output_metadata {
296 1077 ▶ my ($self, $out) = @_;
Subroutine output_metadata: called CC=4 SCAR=13.9
Pod documented
297 1077 ▶ if ( $self->filters_for('metadata') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->filters_for("metadata")) 25 1052 1077
298 25 return $self->SUPER::output_metadata($out);
299 }
300  
301 1052 print $out qq{<dl class="meta">\n<dt>Revision</dt> <dd>};
302  
303 1052 my $rev = $self->revision;
304 1052 ▶ if (my $url = $self->revision_url) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $url = $self->revision_url) { } 192 860 1052
305 192 $url = encode_entities($url, '<>&"');
306 # Make the revision number a URL.
307 192 printf $out qq{<a href="$url">$rev</a>}, $rev;
308 } else {
309 # Just output the revision number.
310 860 print $out $rev;
311 }
312  
313 # Output the committer and a URL, if there is one.
314 1052 print $out "</dd>\n<dt>Author</dt> <dd>";
315 1052 my $user = encode_entities($self->user, '<>&"');
316 1052 ▶ if (my $url = $self->author_url) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $url = $self->author_url) { } 10 1042 1052
317 10 $url = encode_entities($url, '<>&"');
318 10 printf $out qq{<a href="$url">$user</a>}, $user;
319 } else {
320 # Just output the username
321 1042 print $out $user;
322 }
323  
324 1052 print $out (
325 "</dd>\n",
326 '<dt>Date</dt> <dd>',
327 encode_entities($self->date, '<>&"'), "</dd>\n",
328 "</dl>\n\n"
329 );
330  
331 1052 return $self;
332 }
333  
334 ##############################################################################
335  
336 =head3 output_log_message
337  
338 $notifier->output_log_message($file_handle);
339  
340 Outputs the commit log message in C<< <pre> >> tags, and the label "Log
341 Message" in C<< <h3> >> tags. If the C<bugzilla_url> attribute is set, then
342 any strings like "Bug 2" or "bug # 567" will be turned into links.
343  
344 If there are any C<log_message> filters, the filters will be assumed to escape
345 the HTML, create inline links, and link ticket URLs. Otherwise, this method
346 will do those things. See L<Writing Output Filters|SVN::Notify/"Writing Output
347 Filters"> for details on filters.
348  
349 =cut
350  
351 sub output_log_message {
352 1077 ▶ my ($self, $out) = @_;
Subroutine output_log_message: called CC=10 SCAR=23.0
Pod documented
353 1077 ▶ $self->_dbpnt( "Outputting log message as HTML") if $self->verbose > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose > 1 0 1077 1077
354  
355 # Assemble the message.
356 1077 my $filters = $self->filters_for('log_message');
357  
358 my $msg = $filters
359 ? join(
360 "\n",
361 31 @{ $self->run_filters( log_message => [ @{ $self->message } ] ) }
362 1077 ▶ ) : encode_entities( join( "\n", @{ $self->message } ), '<>&"');
Branch: 1 branch
BranchTrueFalseTotal
$filters ? : 31 1046 1077
363  
364 # Turn URLs and email addresses into links.
365 1077 ▶ if ($self->linkize) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->linkize) 410 667 1077
366 # These regular expressions modified from "Mastering Regular
367 # Expressions" 2ed., pp 70-75.
368  
369 # Make email links.
370 410 $msg =~ s{\b(\w[-.\w]*\@[-a-z0-9]+(?:\.[-a-z0-9]+)*\.[-a-z0-9]+)\b}
371 {<a href="mailto:$1">$1</a>}gi;
372  
373 # Make URLs linkable.
374 410 $msg =~ s{\b([a-z0-9]+://[-a-z0-9]+(?:\.[-a-z0-9]+)*\.[-a-z0-9]+\b(?:/(?:[-a-z0-9_:\@?=+,.!/~*I'%\$]|&amp;)*(?<![.,?!]))?)}
375 {<a href="$1">$1</a>}gi;
376 }
377  
378 # Make Revision links.
379 1077 ▶ if (my $url = $self->revision_url) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $url = $self->revision_url) 192 885 1077
380 192 $url = encode_entities($url, '<>&"');
381 192 $msg =~ s{\b((?:rev(?:ision)?\s*#?\s*|r)(\d+))\b}{sprintf qq{<a href="$url">$1</a>}, $2}ige;
382 }
383  
384 # Make ticketing system links.
385 1077 ▶ if (my $map = $self->ticket_map) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $map = $self->ticket_map) 39 1038 1077
386 $self->run_ticket_map ( sub {
387 176 ▶ my ($regex, $url) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
388 176 $url = encode_entities($url, '<>&"');
389 176 ▶ $msg =~ s{$regex}{ sprintf qq{<a href="$url">$1</a>}, $2 || $1 }ige;
Condition66%2/3
$2 || $1
l!l&&r!l&&!r
272780
MC/DC0%0/2
$2 || $1
$2 $1
Truth table66%2/3
A || B
A= $2B= $1
ABresult
1X1
011
000
390 39 });
391 }
392  
393 1077 print $out "<h3>Log Message</h3>\n";
394 1077 ▶ if ($filters || $self->wrap_log) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filters or $self->wrap_log) { } 39 1038 1077
Condition100%3/3
$filters or $self->wrap_log
l!l&&r!l&&!r
3181038
MC/DC100%2/2
$filters or $self->wrap_log
$filters $self->wrap_log
Truth table100%3/3
A or B
A= $filtersB= $self->wrap_log
ABresult
1X1
011
000
395 39 ▶ $msg = '<p>' . join( "</p>\n\n<p>", split /\n\s*\n/, $msg ) . '</p>'
Branch: 1 branch
BranchTrueFalseTotal
if not $filters and $self->wrap_log 8 31 39
Condition66%2/3
not $filters and $self->wrap_log
!ll&&!rl&&r
3108
MC/DC50%1/2
not $filters and $self->wrap_log
not $filters $self->wrap_log
Truth table66%2/3
not(A) and B
A= not $filtersB= $self->wrap_log
ABresult
0X0
100
111
396 if !$filters && $self->wrap_log;
397 39 print $out (
398 qq{<div id="logmsg">\n},
399 $msg,
400 qq{</div>\n\n},
401 )
402 } else {
403 1038 print $out "<pre>$msg</pre>\n\n";
404 }
405 1077 return $self;
406 }
407  
408 ##############################################################################
409  
410 =head3 output_file_lists
411  
412 $notifier->output_log_message($file_handle);
413  
414 Outputs the lists of modified, added, deleted, files, as well as the list of
415 files for which properties were changed as unordered lists. The labels used
416 for each group are pulled in from the C<file_label_map()> class method and
417 output in C<< <h3> >> tags.
418  
419 If there are any C<file_lists> filters, this method will do no HTML
420 formatting, but redispatch to
421 L<SVN::Notify::output_file_lists|SVN::Notify/"output_file_lists">. See
422 L<Writing Output Filters|SVN::Notify/"Writing Output Filters"> for details on
423 filters.
424  
425 =cut
426  
427 sub output_file_lists {
428 1077 ▶ my ($self, $out) = @_;
Subroutine output_file_lists: called CC=11 SCAR=24.0
Pod documented
429 1077 ▶ my $files = $self->files or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $files = $self->files or return $self 0 1077 1077
430  
431 1077 ▶ if ( $self->filters_for('file_lists') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->filters_for("file_lists")) 22 1055 1077
432 22 return $self->SUPER::output_file_lists($out);
433 }
434  
435 1055 my $map = $self->file_label_map;
436 # Create the lines that will go underneath the above in the message.
437 1055 my %dash = ( map { $_ => '-' x length($map->{$_}) } keys %$map );
438  
439 1055 foreach my $type (qw(U A D _)) {
440 # Skip it if there's nothing to report.
441 4220 ▶ next unless $files->{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless $files->{$type} 347 3873 4220
442  
443 # Identify the action and output each file.
444 3873 print $out "<h3>$map->{$type}</h3>\n<ul>\n";
445 3873 ▶ if ($self->with_diff && !$self->attach_diff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->with_diff and not $self->attach_diff) { } 1278 2595 3873
Condition100%3/3
$self->with_diff and not $self->attach_diff
!ll&&!rl&&r
22633321278
MC/DC100%2/2
$self->with_diff and not $self->attach_diff
$self->with_diff not $self->attach_diff
Truth table100%3/3
A and not(B)
A= $self->with_diffB= not $self->attach_diff
ABresult
0X0
100
111
446 1278 for (@{ $files->{$type} }) {
447 6175 my $file = encode_entities($_, '<>&"');
448 6175 ▶ if ($file =~ m{/$} && $type ne '_') {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ m[/$] and $type ne '_') { } 280 5895 6175
Condition66%2/3
$file =~ m[/$] and $type ne "_"
!ll&&!rl&&r
58950280
MC/DC50%1/2
$file =~ m[/$] and $type ne "_"
$file =~ m[/$] $type ne "_"
Truth table66%2/3
A and B
A= $file =~ m[/$]B= $type ne "_"
ABresult
0X0
100
111
449 # Directories don't link, unless it's a prop change.
450 280 print $out qq{<li>$file</li>\n};
451 } else {
452 # Strip out letters illegal for IDs.
453 5895 (my $id = $file) =~ s/[^\w_]//g;
454 5895 print $out qq{<li><a href="#$id">$file</a></li>\n};
455 }
456 }
457 } else {
458 print $out " <li>", encode_entities($_, '<>&"'), "</li>\n"
459 2595 for @{ $files->{$type} };
460 }
461 3873 print $out "</ul>\n\n";
462 }
463 }
464  
465 ##############################################################################
466  
467 =head3 end_body
468  
469 $notifier->end_body($file_handle);
470  
471 Closes out the body of the email by outputting the closing C<< </body> >> and
472 C<< </html> >> tags. Designed to be called when the body of the message is
473 complete, and before any call to C<output_attached_diff()>.
474  
475 If the C<footer> attribute is set, C<end_body()> outputs it between
476 C<< <div> >> tags with the ID "footer". Furthermore, if the footer happens to
477 end with the character "E<lt>", C<end_body()> assumes that it contains valid
478 HTML and therefore will not escape it.
479  
480 All of the HTML will be passed to any "end_body" output filters. See L<Writing
481 Output Filters|SVN::Notify/"Writing Output Filters"> for details on filters.
482  
483 =cut
484  
485 sub end_body {
486 1057 ▶ my ($self, $out) = @_;
Subroutine end_body: called CC=6 SCAR=17.9
Pod documented
487 1057 ▶ $self->_dbpnt( "Ending body") if $self->verbose > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose > 2 0 1057 1057
488 1057 my @html;
489 1057 ▶ if (my $footer = $self->footer) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $footer = $self->footer) 12 1045 1057
490 12 ▶ push @html, (
Branch: 1 branch
BranchTrueFalseTotal
$footer =~ /^</ ? : 5 7 12
491 '<div id="footer">',
492 ( $footer =~ /^</ ? $footer : encode_entities($footer, '<>&"') ),
493 "</div>\n",
494 );
495 }
496 1057 ▶ push @html, "\n</div>" unless $self->with_diff && !$self->attach_diff;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->with_diff and not $self->attach_diff 733 324 1057
Condition100%3/3
$self->with_diff and not $self->attach_diff
!ll&&!rl&&r
65380324
MC/DC100%2/2
$self->with_diff and not $self->attach_diff
$self->with_diff not $self->attach_diff
Truth table100%3/3
A and not(B)
A= $self->with_diffB= not $self->attach_diff
ABresult
0X0
100
111
497 1057 push @html, "\n</body>\n</html>\n";
498  
499 1057 print $out @{ $self->run_filters( end_body => \@html ) };
500 1057 return $self;
501 }
502  
503 ##############################################################################
504  
505 =head3 output_diff
506  
507 $notifier->output_diff($out_file_handle, $diff_file_handle);
508  
509 Sends the output of C<svnlook diff> to the specified file handle for inclusion
510 in the notification message. The diff is output between C<< <pre> >> tags, and
511 Each line of the diff file is escaped by C<HTML::Entities::encode_entities()>.
512 The diff data will be read from C<$diff_file_handle> and printed to
513 C<$out_file_handle>.
514  
515 If there are any C<diff> filters, this method will do no HTML formatting, but
516 redispatch to L<SVN::Notify::output_diff|SVN::Notify/"output_diff">. See
517 L<Writing Output Filters|SVN::Notify/"Writing Output Filters"> for details on
518 filters.
519  
520 =cut
521  
522 sub output_diff {
523 193 ▶ my ($self, $out, $diff) = @_;
Subroutine output_diff: called CC=9 SCAR=22.0
Pod documented
524 193 ▶ if ( $self->filters_for('diff') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->filters_for("diff")) 32 161 193
525 32 return $self->SUPER::output_diff($out, $diff);
526 }
527  
528 161 ▶ $self->_dbpnt( "Outputting HTML diff") if $self->verbose > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose > 1 0 161 161
529  
530 161 print $out qq{</div>\n<div id="patch"><pre>\n};
531 161 my ($length, %seen) = 0;
532 161 my $max = $self->max_diff_length;
533  
534 161 ▶ while (<$diff>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $diff)) 7318 121 7439
535 7318 ▶ if (!$max || ($length += length) < $max) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $max or ($length += length $_) < $max) { } 7278 40 7318
Condition100%3/3
not $max or ($length += length $_) < $max
l!l&&r!l&&!r
639888040
MC/DC100%2/2
not $max or ($length += length $_) < $max
not $max ($length += length $_) < $max
Truth table100%3/3
not(A) or B
A= not $maxB= ($length += length $_) < $max
ABresult
1X1
011
000
536 7278 s/[\n\r]+$//;
537 7278 ▶ if (/^(Modified|Added|Deleted|Copied|Property changes on): (.*)/
Branch: 1 branch
BranchTrueFalseTotal
if (/^(Modified|Added|Deleted|Copied|Property changes on): (.*)/ and not $seen{$2}++) { } 425 6853 7278
Condition100%3/3
/^(Modified|Added|Deleted|Copied|Property changes on): (.*)/ and not $seen{$2}++
!ll&&!rl&&r
679855425
MC/DC100%2/2
/^(Modified|Added|Deleted|Copied|Property changes on): (.*)/ and not $seen{$2}++
/^(Modified|Added|Deleted|Copied|Property changes on): (.*)/ not $seen{$2}++
Truth table100%3/3
A and not(B)
A= /^(Modified|Added|Deleted|Copied|Property changes on): (.*)/B= not $seen{$2}++
ABresult
0X0
100
111
538 && !$seen{$2}++) {
539 425 my $action = $1;
540 425 my $file = encode_entities($2, '<>&"');
541 425 (my $id = $file) =~ s/[^\w_]//g;
542 425 print $out qq{<a id="$id">$action: $file</a>\n};
543 }
544 else {
545 6853 print $out ( encode_entities($_, '<>&"'), "\n" );
546 }
547 } else {
548 40 print $out
549 "\n\@\@ Diff output truncated at $max characters. \@\@\n";
550 40 last;
551 }
552  
553 }
554 161 print $out "</pre></div>\n";
555  
556 161 ▶ close $diff or warn "Child process exited: $?\n";
Branch: 1 branch
BranchTrueFalseTotal
close $diff or warn "Child process exited: $?\n" 0 161 161
557 161 return $self;
558 }
559  
560 ##############################################################################
561  
562 =head2 Accessors
563  
564 In addition to those supported by L<SVN::Notify|SVN::Notify/Accessors>,
565 SVN::Notify::HTML supports the following accessors:
566  
567 =head3 linkize
568  
569 my $linkize = $notifier->linkize;
570 $notifier = $notifier->linkize($linkize);
571  
572 Gets or sets the value of the C<linkize> attribute.
573  
574 =head3 css_url
575  
576 my $css_url = $notifier->css_url;
577 $notifier = $notifier->css_url($css_url);
578  
579 Gets or sets the value of the C<css_url> attribute.
580  
581 =cut
582  
583 ##############################################################################
584  
585 sub _css {
586 return [
587 1077 ▶ q(#msg dl.meta { border: 1px #006 solid; background: #369; ),
Subroutine _css: called CC=1 SCAR=0.0
588 qq(padding: 6px; color: #fff; }\n),
589 qq(#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }\n),
590 qq(#msg dt:after { content:':';}\n),
591 q(#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: ),
592 qq(verdana,arial,helvetica,sans-serif; font-size: 10pt; }\n),
593 qq(#msg dl a { font-weight: bold}\n),
594 qq(#msg dl a:link { color:#fc3; }\n),
595 qq(#msg dl a:active { color:#ff0; }\n),
596 qq(#msg dl a:visited { color:#cc6; }\n),
597 q(h3 { font-family: verdana,arial,helvetica,sans-serif; ),
598 qq(font-size: 10pt; font-weight: bold; }\n),
599 q(#msg pre { white-space: pre-line; overflow: auto; background: #ffc; ),
600 qq(border: 1px #fa0 solid; padding: 6px; }\n),
601 qq(#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }\n),
602 qq(#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }\n),
603 qq(#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }\n),
604 qq(#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }\n),
605 qq(#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }\n),
606 qq{#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }\n},
607 qq{#logmsg ul { text-indent: -1em; padding-left: 1em; }},
608 qq{#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }\n},
609 qq(#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }\n),
610 qq(#logmsg pre { background: #eee; padding: 1em; }\n),
611 qq(#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}\n),
612 qq(#logmsg dl { margin: 0; }\n),
613 qq(#logmsg dt { font-weight: bold; }\n),
614 qq(#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }\n),
615 qq(#logmsg dd:before { content:'\\00bb';}\n),
616 qq(#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }\n),
617 qq(#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }\n),
618 qq(#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }\n),
619 qq(#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }\n),
620 qq(#logmsg table th.Corner { text-align: left; }\n),
621 qq(#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }\n),
622 q(#header, #footer { color: #fff; background: #636; ),
623 qq(border: 1px #300 solid; padding: 6px; }\n),
624 qq(#patch { width: 100%; }\n),
625 ];
626 }
627  
628 198 1;
629 __END__
« blib/lib/SVN/Notify.pm ↑ Summary blib/lib/SVN/Notify/HTML/ColorDiff.pm »