Notify.pm

filter: Statementstmt 94.2% 477 / 506 Branchbran 80.3% 254 / 316 Conditioncond 66.6% 78 / 117 MC/DCmcdc 30.8% 21 / 68 Subroutinesub 94.5% 52 / 55 Podpod 100% 30 / 30 totaltotal 83.5% 912 / 1092 CC 214 SCAR 30.6
CC
214
Cov
86%
new
69.4
prepare_recipients
28.7
get_options
20.9
CRAP 21.3
« Notify/HTML/ColorDiff.pm ↑ Summary Notify/HTML.pm »
1 package SVN::Notify;
2  
3 293 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 293 require 5.006_000;
5 293 ▶use constant WIN32 => $^O eq 'MSWin32';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 293 ▶use constant PERL58 => $] > 5.007_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 293 require Encode if PERL58;
8 293 $SVN::Notify::VERSION = '2.87';
9  
10 # Make sure any output (such as from _dbpnt()) triggers no Perl warnings.
11 293 if (PERL58) {
12 # Dupe them?
13 293 binmode STDOUT, ':utf8';
14 293 binmode STDERR, ':utf8';
15 }
16  
17 =head1 Name
18  
19 SVN::Notify - Subversion activity notification
20  
21 =head1 Synopsis
22  
23 Use F<svnnotify> in F<post-commit>:
24  
25 svnnotify --repos-path "$1" --revision "$2" \
26 --to developers@example.com [options]
27  
28 svnnotify --repos-path "$1" --revision "$2" \
29 --to-cx-regex i10n@example.com=I10N [options]
30  
31 Use the class in a custom script:
32  
33 use SVN::Notify;
34  
35 my $notifier = SVN::Notify->new(%params);
36 $notifier->prepare;
37 $notifier->execute;
38  
39 =head1 Description
40  
41 This class may be used for sending email messages for Subversion repository
42 activity. There are a number of different modes supported, and SVN::Notify is
43 fully subclassable, to add new functionality, and offers L<comprehensive
44 content filtering|SVN::Notify::Filter> to easily modify the format of its
45 messages. By default, A list of all the files affected by the commit will be
46 assembled and listed in a single message. An additional option allows diffs to
47 be calculated for the changes and either appended to the message or added as
48 an attachment. See the C<with_diff> and C<attach_diff> options below.
49  
50 =head1 Usage
51  
52 To use SVN::Notify, simply add a call to F<svnnotify> to your Subversion
53 repository's F<post-commit> script. This script lives in the F<hooks>
54 directory at the root of the repository directory; consult the documentation
55 in F<post-commit.tmpl> for details. Make sure that you specify the complete
56 path to F<svnnotify>, as well as to F<svnlook> and F<sendmail> in the options
57 passed to F<svnnotify> so that everything executes properly. And if you
58 specify any string options, be sure that they are in the encoding specified by
59 the C<--encoding> option, or UTF-8 if you have not specified C<--encoding>.
60  
61 =head2 Windows Usage
62  
63 To get SVN::Notify to work properly in a F<post-commit> script, you must set
64 the following environment variables, as they will likely not be present inside
65 Apache:
66  
67 =over
68  
69 =item PATH=C:\perl\bin
70  
71 =item OS=Windows_NT
72  
73 =item SystemRoot=C:\WINDOWS
74  
75 =back
76  
77 See L<Windows Subversion + Apache + TortoiseSVN + SVN::Notify
78 HOWTO|http://svn.haxx.se/users/archive-2006-05/0593.shtml> for more detailed
79 information on getting SVN::Notify running on Windows. If you have issues with
80 asynchronous execution, try using
81 L<F<HookStart.exe>|http://www.koders.com/csharp/fidE2724F44EF2D47F1C0FE76C538006435FA20051D.aspx>
82 to run F<svnnotify>.
83  
84 =cut
85  
86 # Map the svnlook changed codes to nice labels.
87 293 my %map = (
88 U => 'Modified Paths',
89 A => 'Added Paths',
90 D => 'Removed Paths',
91 _ => 'Property Changed',
92 );
93  
94 293 my %filters;
95  
96 ##############################################################################
97  
98 =head1 Class Interface
99  
100 =head2 Constructor
101  
102 =head3 new
103  
104 my $notifier = SVN::Notify->new(%params);
105  
106 Constructs and returns a new SVN::Notify object. This object is a handle on
107 the whole process of collecting meta data and content for the commit email and
108 then sending it. As such, it takes a number of parameters to affect that
109 process.
110  
111 Each of these parameters has a corresponding command-line option that can be
112 passed to F<svnnotify>. The options have the same names as these parameters,
113 but any underscores you see here should be replaced with dashes when passed to
114 F<svnnotify>. Most also have a corresponding single-character option. On Perl
115 5.8 and higher, If you pass parameters to C<new()>, they B<must> be L<decoded
116 into Perl's internal form|Encode/"PERL ENCODING API"> if they have any
117 non-ASCII characters.
118  
119 Supported parameters:
120  
121 =over
122  
123 =item repos_path
124  
125 svnnotify --repos-path "$PATH"
126 svnnotify -p "$PATH"
127  
128 The path to the Subversion repository. The path is passed as the first
129 argument when Subversion executes F<post-commit>. So you can simply pass C<$1>
130 to this parameter if you like. See the documentation in F<post-commit> for
131 details. Required.
132  
133 =item revision
134  
135 svnnotify --revision "$REV"
136 svnnotify -r "$REV"
137  
138 The revision number for the current commit. The revision number is passed as
139 the second argument when Subversion executes F<post-commit>. So you can
140 simply pass C<$2> to this parameter if you like. See the documentation in
141 F<post-commit> for details. Required.
142  
143 =item to
144  
145 svnnotify --to commiters@example.com
146 svnnotify -t commiters@example.com --to managers@example.com
147  
148 The address or addresses to which to send the notification email. Can be used
149 multiple times to specify multiple addresses. This parameter is required
150 unless either C<to_regex_map> or C<to_email_map> is specified.
151  
152 =item to_regex_map
153  
154 svnnotify --to-regex-map translate@example.com=L18N \
155 -x legal@example.com=License
156  
157 This parameter specifies a hash reference of email addresses to regular
158 expression strings. SVN::Notify will compile the regular expression strings
159 into regular expression objects, and then send notification messages if and
160 only if the name of one or more of the paths affected by a commit matches the
161 regular expression. This is a good way to have a notification email sent to a
162 particular mail address (or comma-delimited list of addresses) only for
163 certain parts of the subversion tree. This parameter is required unless C<to>
164 or C<to_email_map> is specified.
165  
166 The command-line options, C<--to-regex_map> and C<-x>, can be specified any
167 number of times, once for each entry in the hash to be passed to C<new()>. The
168 value passed to the option must be in the form of the key and the value
169 separated by an equal sign. Consult the L<Getopt::Long> documentation for more
170 information.
171  
172 Here's an example complements of Matt Doar of how to use C<to_regex_map> to do
173 per-branch matching:
174  
175 author=`svnlook author $REPOS -r $REV`
176  
177 # The mail regexes should match all the top-level directories
178 /usr/bin/svnnotify --repos-path "$REPOS" --revision "$REV" \
179 -x eng-bar@example.com,${EXTRAS}="^Bar" \
180 -x eng-foo@example.com,${EXTRAS}="^trunk/Foo|^branches/Foo|^tags/Foo" \
181 -x $author@example.com="^users" --subject-cx
182  
183 =item to_email_map
184  
185 svnnotify --to-email-map L18N=translate@example.com \
186 --to-email-map License=legal@example.com
187  
188 The inverse of C<to_regex_map>: The regular expression is the hash key
189 and the email address or addresses are the value.
190  
191 =item from
192  
193 svnnotify --from somewhere@example.com
194 svnnotify -f elsewhere@example.com
195  
196 The email address to use in the "From" line of the email. If not specified,
197 SVN::Notify will use the username from the commit, as returned by C<svnlook
198 info>.
199  
200 =item user_domain
201  
202 svnnotify --user-domain example.com
203 svnnotify -D example.net
204  
205 A domain name to append to the username for the "From" header of the email.
206 During a Subversion commit, the username returned by C<svnlook info> is
207 usually something like a Unix login name. SVN::Notify will use this username
208 in the email "From" header unless the C<from> parameter is specified. If you
209 wish to have the username take the form of a real email address, specify a
210 domain name and SVN::Notify will append C<\@$domain_name> to the username in
211 order to create a real email address. This can be useful if all of your
212 committers have an email address that corresponds to their username at the
213 domain specified by the C<user_domain> parameter.
214  
215 =item svnlook
216  
217 svnnotify --svnlook /path/to/svnlook
218 svnnotify -l /path/to/svnlook
219  
220 The location of the F<svnlook> executable. If not specified, SVN::Notify will
221 search through the directories in the C<$PATH> environment variable, plus in
222 F</usr/local/bin> and F</usr/sbin>, for an F<svnlook> executable. Specify a
223 full path to F<svnlook> via this option or by setting the C<$SVNLOOK>
224 environment variable if F<svnlook> isn't in your path or to avoid loading
225 L<File::Spec|File::Spec>.
226  
227 It's important to provide a complete path to F<svnlook> because the
228 environment during the execution of F<post-commit> is anemic, with nary a
229 C<$PATH> environment variable to be found. So if F<svnnotify> appears not to
230 be working at all (and Subversion seems loathe to log when it dies!), make
231 sure that you have specified the complete path to a working F<svnlook>
232 executable.
233  
234 =item sendmail
235  
236 svnnotify --sendmail /path/to/sendmail
237 svnnotify -s /path/to/sendmail
238  
239 The location of the F<sendmail> executable. If neither the C<sendmail> nor the
240 C<smtp> parameter is specified, SVN::Notify will search through the
241 directories in the C<$PATH> environment variable, plus in F</usr/local/bin>
242 and F</usr/sbin>, for an F<sendmail> executable. Specify a full path to
243 F<sendmail> via this option or by setting the C<$SENDMAIL> environment
244 variable if F<sendmail> isn't in your path or to avoid loading
245 L<File::Spec|File::Spec>. The same caveats as applied to the location of the
246 F<svnlook> executable apply here.
247  
248 =item set_sender
249  
250 svnnotify --set-sender
251 svnnotify -E
252  
253 Uses the C<-f> option to C<sendmail> to set the envelope sender address of the
254 email to the same address as is used for the "From" header. If you're also
255 using the C<from> option, be sure to make it B<only> an email address. Don't
256 include any other junk in it, like a sender's name. Ignored when using
257 C<smtp>.
258  
259 =item smtp
260  
261 svnnotify --smtp smtp.example.com
262  
263 The address for an SMTP server through which to send the notification email.
264 If unspecified, SVN::Notify will use F<sendmail> to send the message. If
265 F<sendmail> is not installed locally (such as on Windows boxes!), you I<must>
266 specify an SMTP server.
267  
268 =item smtp_tls
269  
270 svnnotify --smtp-tls
271  
272 Use TLS authentication and encrypted channels for connecting with the server.
273 Usually, TLS servers will require user/password authentication.
274  
275 =item smtp_user
276  
277 svnnotify --smtp-user myuser
278  
279 The user name for SMTP authentication. If this option is specified,
280 SVN::Notify will use L<Net::SMTP_auth|Net::SMTP_auth> to send the notification
281 message, and will of course authenticate to the SMTP server.
282  
283 =item smtp_pass
284  
285 svnnotify --smtp-pass mypassword
286  
287 The password for SMTP authentication. Use in parallel with C<smtp_user>.
288  
289 =item smtp_port
290  
291 svnnotify --smtp-port 465
292  
293 The port for an SMTP server through which to send the notification email. The
294 default port is 25.
295  
296 =item smtp_authtype
297  
298 svnnotify --smtp-authtype authtype
299  
300 Deprecated in SVN::Notify 2.83, where it has become a no-op. The auth type is
301 determined by the contents returned by the SMTP server's response to the
302 C<EHLO> command. See L<Net::SMTP::TLS/TLS and AUTHentication> for details.
303  
304 =item encoding
305  
306 svnnotify --encoding UTF-8
307 svnnotify -c Big5
308  
309 The character set typically used on the repository for log messages, file
310 names, and file contents. Used to specify the character set in the email
311 Content-Type headers and, when the C<language> parameter is specified, the
312 C<$LANG> environment variable when launching C<sendmail>. See L</"Character
313 Encoding Support"> for more information. Defaults to "UTF-8".
314  
315 =item charset
316  
317 svnnotify --charset UTF-8
318  
319 Deprecated. Use C<encoding> instead.
320  
321 =item svn_encoding
322  
323 svnnotify --svn-encoding euc-jp
324  
325 The character set used in files and log messages managed in Subversion. It's
326 useful to set this option if you store files in Subversion using one character
327 set but want to send notification messages in a different character set.
328 Therefore C<encoding> would be used for the notification message, and
329 C<svn_encoding> would be used to read in data from Subversion. See
330 L</"Character Encoding Support"> for more information. Defaults to the value
331 stored in C<encoding>.
332  
333 =item diff_encoding
334  
335 svnnotify --diff-encoding iso-2022-jp
336  
337 The character set used by files in Subversion, and thus present in the the
338 diff. It's useful to set this option if you store files in Subversion using
339 one character write log messages in a different character set. Therefore
340 C<svn_encoding> would be used to read the log message and C<diff_encoding>
341 would be used to read the diff from Subversion. See L</"Character Encoding
342 Support"> for more information. Defaults to the value stored in
343 C<svn_encoding>.
344  
345 =item language
346  
347 svnnotify --language fr
348 svnnotify -g i-klingon
349  
350 The language typically used on the repository for log messages, file names,
351 and file contents. Used to specify the email Content-Language header and to
352 set the C<$LANG> environment variable to C<< $notify->language . '.' .
353 $notify->encoding >> before executing C<svnlook> and C<sendmail> (but not for
354 sending data to Net::SMTP). Undefined by default, meaning that no
355 Content-Language header is output and the C<$LANG> environment variable will
356 not be set. See L</"Character Encoding Support"> for more information.
357  
358 =item with_diff
359  
360 svnnotify --with-diff
361 svnnotify -d
362  
363 A boolean value specifying whether or not to include the output of C<svnlook
364 diff> in the notification email. The diff will be inline at the end of the
365 email unless the C<attach_diff> parameter specifies a true value.
366  
367 =item attach_diff
368  
369 svnnotify --attach-diff
370 svnnotify -a
371  
372 A boolean value specifying whether or not to attach the output of C<svnlook
373 diff> to the notification email. Rather than being inline in the body of the
374 email, this parameter causes SVN::Notify to attach the diff as a separate
375 file, named for the user who triggered the commit and the date and time UTC at
376 which the commit took place. Specifying this parameter to a true value
377 implicitly sets the C<with_diff> parameter to a true value.
378  
379 =item diff_switches
380  
381 svnnotify --diff-switches '--no-diff-added'
382 svnnotify -w '--no-diff-deleted'
383  
384 Switches to pass to C<svnlook diff>, such as C<--no-diff-deleted> and
385 C<--no-diff-added>. And who knows, maybe someday it will support the same
386 options as C<svn diff>, such as C<--diff-cmd> and C<--extensions>. Only
387 relevant when used with C<with_diff> or C<attach_diff>.
388  
389 =item diff_content_type
390  
391 svnnotify --diff-content-type 'text/x-diff'
392  
393 Sets the Content-Type header for attached diffs. The default, if this parameter
394 is not passed, is 'text/plain'. This parameter has no effect if '--attach-diff'
395 is not specified.
396  
397 =item reply_to
398  
399 svnnotify --reply-to devlist@example.com
400 svnnotify -R developers@example.net
401  
402 The email address to use in the "Reply-To" header of the notification email.
403 No "Reply-To" header will be added to the email if no value is specified for
404 the C<reply_to> parameter.
405  
406 =item add_headers
407  
408 svnnotify --add-header X-Approve=letMeIn
409  
410 Add a header to the notification email message. The header name and its value
411 must be separated by an equals sign. Specify the option multiple times in
412 order to add multiple headers. Headers with the same names are allowed. Not to
413 be confused with the C<--header> option, which adds introductory text to the
414 beginning of the email body.
415  
416 =item subject_prefix
417  
418 svnnotify --subject-prefix [Devlist]
419 svnnotify -P [%d (Our-Developers)]
420  
421 An optional string to prepend to the beginning of the subject line of the
422 notification email. If it contains '%d', it will be used to place the revision
423 number; otherwise it will simply be prepended to the subject, which will
424 contain the revision number in brackets.
425  
426 =item subject_cx
427  
428 svnnotify --subject-cx
429 svnnotify -C
430  
431 A boolean value indicating whether or not to include a the context of the
432 commit in the subject line of the email. In a commit that affects multiple
433 files, the context will be the name of the shortest directory affected by the
434 commit. This should indicate up to how high up the Subversion repository tree
435 the commit had an effect. If the commit affects a single file, then the
436 context will simply be the name of that file.
437  
438 =item strip_cx_regex
439  
440 svnnotify --strip-cx-regex '^trunk/'
441 svnnotify --strip-cx-regex '^trunk/' --strip-cx-regex '^branches/'
442 svnnotify -X '^trunk'
443 svnnotify -X '^trunk' -X '^branches'
444  
445 One or more regular expressions to be used to strip out parts of the subject
446 context. This can be useful for very deep Subversion trees, where the commits
447 you're sending will always be sent from a particular subtree, so you'd like to
448 remove part of the tree. Used only if C<subject_cx> is set to a true value.
449 Pass an array reference if calling C<new()> directly.
450  
451 =item no_first_line
452  
453 svnnotify --no-first-line
454 svnnotify -O
455  
456 Omits the first line of the log message from the subject. This is most useful
457 when used in combination with the C<subject_cx> parameter, so that just the
458 commit context is displayed in the subject and no part of the log message.
459  
460 =item header
461  
462 svnnotify --header 'SVN::Notify is brought to you by Kineticode.
463  
464 Adds a specified text to each message as a header at the beginning of the body
465 of the message. Not to be confused with the C<--add-header> option, which adds
466 a header to the headers section of the email.
467  
468 =item footer
469  
470 svnnotify --footer 'Copyright (R) by Kineticode, Inc.'
471  
472 Adds a specified text to each message as a footer at the end of the body of
473 the message.
474  
475 =item max_sub_length
476  
477 svnnotify --max-sub-length 72
478 svnnotify -i 76
479  
480 The maximum length of the notification email subject line. SVN::Notify
481 includes the first line of the commit log message, or the first sentence of
482 the message (defined as any text up to the string ". "), whichever is
483 shorter. This could potentially be quite long. To prevent the subject from
484 being over a certain number of characters, specify a maximum length here, and
485 SVN::Notify will truncate the subject to the last word under that length.
486  
487 =item max_diff_length
488  
489 svnnotify --max-diff-length 1024
490  
491 The maximum length of the diff (attached or in the body). The diff output is
492 truncated at the last line under the maximum character count specified and
493 then outputs an additional line indicating that the maximum diff size was
494 reached and output truncated. This is helpful when a large diff output could
495 cause a message to bounce due to message size.
496  
497 =item handler
498  
499 svnnotify --handler HTML
500 svnnotify -H HTML
501  
502 Specify the subclass of SVN::Notify to be constructed and returned, and
503 therefore to handle the notification. Of course you can just use a subclass
504 directly, but this parameter is designed to make it easy to just use
505 C<< SVN::Notify->new >> without worrying about loading subclasses, such as in
506 F<svnnotify>. Be sure to read the documentation for your subclass of choice,
507 as there may be additional parameters and existing parameters may behave
508 differently.
509  
510 =item filters
511  
512 svnnotify --filter Trac -F My::Filter
513  
514 SVN::Notify->new( %params, filters => ['Markdown', 'My::Filter'] );
515  
516 Specify a more module to be loaded in the expectation that it defines output
517 filters. For example, L<SVN::Notify::Filter::Trac|SVN::Notify::Filter::Trac>
518 loads a filter that converts log messages from Trac's markup format to HTML.
519 L<SVN::Notify::Filter::Markdown|SVN::Notify::Filter::Markdown>, available on
520 CPAN, does the same for Markdown format. Check CPAN for other SVN::Notify
521 filter modules.
522  
523 This command-line option can be specified more than once to load multiple
524 filters. The C<filters> parameter to C<new()> should be an array reference of
525 modules names. If a value contains "::", it is assumed to be a complete module
526 name. Otherwise, it is assumed to be in the SVN::Notify::Filter name space.
527 See L<SVN::Notify::Filter|SVN::Notify::Filter> for details on writing your own
528 output filters (it's really easy, I promise!).
529  
530 =item author_url
531  
532 svnnotify --author-url 'http://svn.example.com/changelog/~author=%s/repos'
533 svnnotify --A 'mailto:%s@example.com'
534  
535 If a URL is specified for this parameter, then it will be used to create a
536 link for the current author. The URL can have the "%s" format where the
537 author's username should be put into the URL.
538  
539 =item revision_url
540  
541 svnnotify --revision-url 'http://svn.example.com/changelog/?cs=%s'
542 svnnotify -U 'http://svn.example.com/changelog/?cs=%s'
543  
544 If a URL is specified for this parameter, then it will be used to create a
545 link to the Subversion browser URL corresponding to the current revision
546 number. It will also be used to create links to any other revision numbers
547 mentioned in the commit message. The URL must have the "%s" format where the
548 Subversion revision number should be put into the URL.
549  
550 =item svnweb_url
551  
552 svnnotify --svnweb-url 'http://svn.example.com/index.cgi/revision/?rev=%s'
553 svnnotify -S 'http://svn.example.net/index.cgi/revision/?rev=%s'
554  
555 Deprecated. Use C<revision_url> instead.
556  
557 =item viewcvs_url
558  
559 svnnotify --viewcvs-url 'http://svn.example.com/viewcvs/?rev=%s&view=rev'
560  
561 Deprecated. Use C<revision_url> instead.
562  
563 =item ticket_map
564  
565 svnnotify --ticket-map '\[?#\s*(\d+)\s*\]?=http://example.com/ticket?id=%s' \
566 --ticket-map 'rt=http://rt.cpan.org/NoAuth/Bugs.html?id=%s' \
567 --ticket-map '\b([A-Z0-9]+-\d+)\b=http://jira/browse/%s'
568  
569 Specifies a mapping between a regular expression and a URL. The regular
570 expression should return a single match to be interpolated into the URL, which
571 should be a C<sprintf> format using "%s" to place the match (usually the
572 ticket identifier) from the regex. The command-line option may be specified
573 any number of times for different ticketing systems. To the API, it must be
574 passed as a hash reference.
575  
576 The first example matches "[#1234]" or "#1234" or "[# 1234]". This regex
577 should be as specific as possible, preferably wrapped in "\b" to match word
578 boundaries. If you're using L<SVN::Notify::HTML|SVN::Notify::HTML>, be sure to
579 read its documentation for a different regular expression requirement!
580  
581 Optionally, the key value can be a placeholder for a regular expression used
582 internally by SVN::Notify to match strings typically used for well-known
583 ticketing systems. Those keys are:
584  
585 =over
586  
587 =item rt
588  
589 Matches Request Tracker (RT) ticket references of the form "Ticket # 12",
590 "ticket 6", "RT # 52", "rt 52", "RT-Ticket # 213" or even "Ticket#1066".
591  
592 =item bugzilla
593  
594 Matches Bugzilla bug references of the form "Bug # 12" or "bug 6" or even
595 "Bug#1066".
596  
597 =item jira
598  
599 Matches JIRA references of the form "JRA-1234".
600  
601 =item gnats
602  
603 Matches GnatsWeb references of the form "PR 1234".
604  
605 =back
606  
607 =item rt_url
608  
609 svnnotify --rt-url 'http://rt.cpan.org/NoAuth/Bugs.html?id=%s'
610 svnnotify -T 'http://rt.perl.org/NoAuth/Bugs.html?id=%s'
611  
612 A shortcut for C<--ticket-map 'rt=$url'> provided for backwards compatibility.
613  
614 =item bugzilla_url
615  
616 svnnotify --bugzilla-url 'http://bugzilla.mozilla.org/show_bug.cgi?id=%s'
617 svnnotify -B 'http://bugs.bricolage.cc/show_bug.cgi?id=%s'
618  
619 A shortcut for C<--ticket-map 'bugzilla=$url'> provided for backwards
620 compatibility.
621  
622 =item jira_url
623  
624 svnnotify --jira-url 'http://jira.atlassian.com/secure/ViewIssue.jspa?key=%s'
625 svnnotify -J 'http://nagoya.apache.org/jira/secure/ViewIssue.jspa?key=%s'
626  
627 A shortcut for C<--ticket-map 'jira=$url'> provided for backwards
628 compatibility.
629  
630 =item gnats_url
631  
632 svnnotify --gnats-url 'http://gnatsweb.example.com/cgi-bin/gnatsweb.pl?cmd=view&pr=%s'
633 svnnotify -G 'http://gnatsweb.example.com/cgi-bin/gnatsweb.pl?cmd=view&pr=%s'
634  
635 A shortcut for C<--ticket-map 'gnats=$url'> provided for backwards
636 compatibility.
637  
638 =item ticket_url
639  
640 svnnotify --ticket-url 'http://ticket.example.com/showticket.html?id=%s'
641  
642 Deprecated. Use C<ticket_map>, instead.
643  
644 =item ticket_regex
645  
646 svnnotify --ticket-regex '\[?#\s*(\d+)\s*\]?'
647  
648 Deprecated. Use C<ticket_map>, instead.
649  
650 =item verbose
651  
652 svnnotify --verbose -V
653  
654 A value between 0 and 3 specifying how verbose SVN::Notify should be. The
655 default is 0, meaning that SVN::Notify will be silent. A value of 1 causes
656 SVN::Notify to output some information about what it's doing, while 2 and 3
657 each cause greater verbosity. To set the verbosity on the command line, simply
658 pass the C<--verbose> or C<-V> option once for each level of verbosity, up to
659 three times. Output from SVN::Notify is sent to C<STDOUT>.
660  
661 =item boundary
662  
663 The boundary to use between email body text and attachments. This is normally
664 generated by SVN::Notify.
665  
666 =item subject
667  
668 The subject of the email to be sent. This attribute is normally generated by
669 C<prepare_subject()>.
670  
671 =back
672  
673 =cut
674  
675 # XXX Sneakily used by SVN::Notify::HTML. Change to use class methods?
676 293 our %_ticket_regexen = (
677 rt => '\b((?:rt|(?:rt-)?ticket:?)\s*#?\s*(\d+))\b',
678 bugzilla => '\b(bug\s*#?\s*(\d+))\b',
679 jira => '\b([A-Z0-9]+-\d+)\b',
680 gnats => '\b(PR\s*(\d+))\b',
681 );
682  
683 3406 ▶sub new {
Subroutine new: called CC=51 SCAR=42.4
Pod documented
684 3406 my ($class, %params) = @_;
685  
686 # Delegate to a subclass if requested.
687 3406 ▶ if (my $handler = delete $params{handler}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = delete $params{"handler"}) 346 3060 3406
688 346 my $subclass = __PACKAGE__ . "::$handler";
689 346 ▶ unless ($subclass eq $class) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($subclass eq $class) 346 0 346
690 346 ▶ eval "require $subclass" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $subclass" or die $@ 346 0 346
691 346 return $subclass->new(%params);
692 }
693 }
694  
695 # Load any filters.
696 3060 ▶ $params{filters} ||= {};
Condition100%2/2
$params{"filters"} ||= {}
l!l
9442116
MC/DC100%1/1
$params{"filters"} ||= {}
$params{"filters"}
Truth table100%2/2
A
A= $params{"filters"}
Aresult
11
00
697 3060 ▶ if (ref $params{filters} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $params{"filters"} eq "ARRAY") 716 2344 3060
698 716 my $filts = {};
699 716 for my $pkg ( @{ $params{filters} } ) {
700 778 ▶ $pkg = "SVN::Notify::Filter::$pkg" if $pkg !~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg =~ /::/ 777 1 778
701 778 ▶ if ($filters{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filters{$pkg}) { } 308 470 778
702 308 ▶ while (my ($k, $v) = each %{ $filters{$pkg} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$filters{$pkg};}) 568 308 876
703 568 ▶ $filts->{$k} ||= [];
Condition50%1/2
$filts->{$k} ||= []
l!l
0568
MC/DC0%0/1
$filts->{$k} ||= []
$filts->{$k}
Truth table50%1/2
A
A= $filts->{$k}
Aresult
11
00
704 568 push @{ $filts->{$k} }, $v;
705 }
706 } else {
707 470 ▶ eval "require $pkg" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $pkg" or die $@ 470 0 470
708 470 $filters{$pkg} = {};
709 293 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
710 470 ▶ while ( my ($k, $v) = each %{ "$pkg\::" } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{"${pkg}::";}) 885 470 1355
711 885 ▶ my $code = ref \$v eq 'GLOB' ? *{$v}{CODE}
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'CODE' ? : 0 0 0
712 : ref $v eq 'CODE' ? $v
713 0 ▶ : *{ "$pkg\::$k" }{CODE} or next;
Branch: 2 branches
BranchTrueFalseTotal
my $code = ref \$v eq "GLOB" ? *{$v;}{"CODE"} : (ref $v eq "CODE" ? $v : *{"${pkg}::$k";}{"CODE"}) or next 769 116 885
ref \$v eq 'GLOB' ? : 885 0 885
714 769 $filters{$pkg}->{$k} = $code;
715 769 ▶ $filts->{$k} ||= [];
Condition100%2/2
$filts->{$k} ||= []
l!l
62707
MC/DC100%1/1
$filts->{$k} ||= []
$filts->{$k}
Truth table100%2/2
A
A= $filts->{$k}
Aresult
11
00
716 769 push @{ $filts->{$k} }, $code;
717 }
718 }
719 }
720 716 $params{filters} = $filts;
721 }
722  
723 # Make sure that the tos are an arrayref.
724 3060 ▶ $params{to} = [ $params{to} || () ] unless ref $params{to};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $params{"to"} 966 2094 3060
Condition66%2/3
$params{'to'} || ()
l!l&&r!l&&!r
96303
MC/DC50%1/2
$params{'to'} || ()
$params{'to'} ()
Truth table66%2/3
A || B
A= $params{'to'}B= ()
ABresult
1X1
011
000
725  
726 # Check for required parameters.
727 $class->_dbpnt( "Checking required parameters to new()")
728 3060 ▶ if $params{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"verbose"} 3 3057 3060
729 _usage( qq{Missing required "repos_path" parameter} )
730 3060 ▶ unless $params{repos_path};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"repos_path"} 1 3059 3060
731 _usage( qq{Missing required "revision" parameter} )
732 3059 ▶ unless $params{revision};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"revision"} 1 3058 3059
733  
734 # Set up default values.
735 3058 ▶ $params{svnlook} ||= $ENV{SVNLOOK} || $class->find_exe('svnlook');
Condition16%1/6
$params{"svnlook"} ||= $ENV{"SVNLOOK"} || $class->find_exe("svnlook")
l!l&&r!l&&!r
305800
$ENV{'SVNLOOK'} || $class->find_exe('svnlook')
l!l&&r!l&&!r
000
MC/DC0%0/3
$params{"svnlook"} ||= $ENV{"SVNLOOK"} || $class->find_exe("svnlook")
$params{"svnlook"} $ENV{'SVNLOOK'} $class->find_exe('svnlook')
Truth table0%0/4
A ||= B || C
A= $params{"svnlook"}B= $ENV{'SVNLOOK'}C= $class->find_exe('svnlook')
ABCresult
1XX1
01X1
0011
0000
736 3058 ▶ $params{with_diff} ||= $params{attach_diff};
Condition100%3/3
$params{"with_diff"} ||= $params{"attach_diff"}
l!l&&r!l&&!r
6741812203
MC/DC100%2/2
$params{"with_diff"} ||= $params{"attach_diff"}
$params{"with_diff"} $params{"attach_diff"}
Truth table100%3/3
A ||= B
A= $params{"with_diff"}B= $params{"attach_diff"}
ABresult
1X1
011
000
737 3058 ▶ $params{verbose} ||= 0;
Condition100%2/2
$params{"verbose"} ||= 0
l!l
33055
MC/DC100%1/1
$params{"verbose"} ||= 0
$params{"verbose"}
Truth table100%2/2
A
A= $params{"verbose"}
Aresult
11
00
738 3058 ▶ $params{encoding} ||= $params{charset} || 'UTF-8';
Condition60%3/5
$params{"encoding"} ||= $params{"charset"} || "UTF-8"
l!l&&r!l&&!r
31227460
$params{'charset'} || 'UTF-8'
l!l
02746
MC/DC0%0/2
$params{"encoding"} ||= $params{"charset"} || "UTF-8"
$params{"encoding"} $params{'charset'}
Truth table33%1/3
A ||= B
A= $params{"encoding"}B= $params{'charset'}
ABresult
1X1
011
000
739 3058 ▶ $params{svn_encoding} ||= $params{encoding};
Condition66%2/3
$params{"svn_encoding"} ||= $params{"encoding"}
l!l&&r!l&&!r
25728010
MC/DC0%0/2
$params{"svn_encoding"} ||= $params{"encoding"}
$params{"svn_encoding"} $params{"encoding"}
Truth table66%2/3
A ||= B
A= $params{"svn_encoding"}B= $params{"encoding"}
ABresult
1X1
011
000
740 3058 ▶ $params{diff_encoding} ||= $params{svn_encoding};
Condition66%2/3
$params{"diff_encoding"} ||= $params{"svn_encoding"}
l!l&&r!l&&!r
25728010
MC/DC0%0/2
$params{"diff_encoding"} ||= $params{"svn_encoding"}
$params{"diff_encoding"} $params{"svn_encoding"}
Truth table66%2/3
A ||= B
A= $params{"diff_encoding"}B= $params{"svn_encoding"}
ABresult
1X1
011
000
741 3058 ▶ $params{diff_content_type} ||= $params{diff_content_type} || 'text/plain';
Condition60%3/5
$params{"diff_content_type"} ||= $params{"diff_content_type"} || "text/plain"
l!l&&r!l&&!r
22828300
$params{'diff_content_type'} || 'text/plain'
l!l
02830
MC/DC0%0/2
$params{"diff_content_type"} ||= $params{"diff_content_type"} || "text/plain"
$params{"diff_content_type"} $params{'diff_content_type'}
Truth table33%1/3
A ||= B
A= $params{"diff_content_type"}B= $params{'diff_content_type'}
ABresult
1X1
011
000
742 $params{sendmail} ||= $ENV{SENDMAIL} || $class->find_exe('sendmail')
743 3058 ▶ unless $params{smtp};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"smtp"} 3050 8 3058
Condition16%1/6
$params{"sendmail"} ||= $ENV{"SENDMAIL"} || $class->find_exe("sendmail")
l!l&&r!l&&!r
305000
$ENV{'SENDMAIL'} || $class->find_exe('sendmail')
l!l&&r!l&&!r
000
MC/DC0%0/3
$params{"sendmail"} ||= $ENV{"SENDMAIL"} || $class->find_exe("sendmail")
$params{"sendmail"} $ENV{'SENDMAIL'} $class->find_exe('sendmail')
Truth table0%0/4
A ||= B || C
A= $params{"sendmail"}B= $ENV{'SENDMAIL'}C= $class->find_exe('sendmail')
ABCresult
1XX1
01X1
0011
0000
744  
745 _usage( qq{Cannot find sendmail and no "smtp" parameter specified} )
746 3058 ▶ unless $params{sendmail} || $params{smtp};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"sendmail"} or $params{"smtp"} 0 3058 3058
Condition66%2/3
$params{"sendmail"} or $params{"smtp"}
l!l&&r!l&&!r
305080
MC/DC0%0/2
$params{"sendmail"} or $params{"smtp"}
$params{"sendmail"} $params{"smtp"}
Truth table66%2/3
A or B
A= $params{"sendmail"}B= $params{"smtp"}
ABresult
1X1
011
000
747  
748 # Set up the environment locale.
749 3058 ▶ if ( $params{language} && !$ENV{LANG} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"language"} and not $ENV{"LANG"}) 210 2848 3058
Condition66%2/3
$params{"language"} and not $ENV{"LANG"}
!ll&&!rl&&r
28480210
MC/DC50%1/2
$params{"language"} and not $ENV{"LANG"}
$params{"language"} not $ENV{"LANG"}
Truth table66%2/3
A and not(B)
A= $params{"language"}B= not $ENV{"LANG"}
ABresult
0X0
100
111
750 210 ( my $lang_country = $params{language} ) =~ s/-/_/g;
751 210 for my $p (qw(encoding svn_encoding)) {
752 420 my $encoding = $params{$p};
753 420 ▶ $encoding =~ s/-//g if uc($encoding) ne 'UTF-8';
Branch: 1 branch
BranchTrueFalseTotal
if uc $encoding ne "UTF-8" 0 420 420
754 420 (my $label = $p ) =~ s/(_?)encoding/$1/;
755 420 $params{"${label}env_lang"} = "$lang_country.$encoding";
756 }
757 }
758  
759 # Set up the revision URL.
760 $params{revision_url} ||= delete $params{svnweb_url}
761 3058 ▶ || delete $params{viewcvs_url};
Condition100%6/6
$params{"revision_url"} ||= delete $params{"svnweb_url"} || delete $params{"viewcvs_url"}
l!l&&r!l&&!r
622732723
delete $params{'svnweb_url'} || delete $params{'viewcvs_url'}
l!l&&r!l&&!r
941792723
MC/DC0%0/3
$params{"revision_url"} ||= delete $params{"svnweb_url"} || delete $params{"viewcvs_url"}
$params{"revision_url"} delete $params{'svnweb_url'} delete $params{'viewcvs_url'}
Truth table0%0/4
A ||= B || C
A= $params{"revision_url"}B= delete $params{'svnweb_url'}C= delete $params{'viewcvs_url'}
ABCresult
1XX1
01X1
0011
0000
762 3058 ▶ if ($params{revision_url} && $params{revision_url} !~ /%s/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"revision_url"} and not $params{"revision_url"} =~ /%s/) 0 3058 3058
Condition66%2/3
$params{"revision_url"} and not $params{"revision_url"} =~ /%s/
!ll&&!rl&&r
27233350
MC/DC0%0/2
$params{"revision_url"} and not $params{"revision_url"} =~ /%s/
$params{"revision_url"} not $params{"revision_url"} =~ /%s/
Truth table66%2/3
A and not(B)
A= $params{"revision_url"}B= not $params{"revision_url"} =~ /%s/
ABresult
0X0
100
111
763 0 warn "--revision-url must have '%s' format\n";
764 0 $params{revision_url} .= '/revision/?rev=%s&view=rev'
765 }
766  
767 # Set up the issue tracking links.
768 3058 my $track = $params{ticket_map};
769 3058 ▶ if ($params{ticket_regex}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"ticket_regex"}) 77 2981 3058
770 77 $track->{ delete $params{ticket_regex} } = delete $params{ticket_url};
771 }
772  
773 3058 for my $system (qw(rt bugzilla jira gnats)) {
774 12232 my $param = $system . '_url';
775 12232 ▶ if ($params{ $param }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{$param}) 283 11949 12232
776 283 $track->{ $system } = delete $params{ $param };
777 warn "--$system-url must have '%s' format\n"
778 283 ▶ unless $track->{ $system } =~ /%s/;
Branch: 1 branch
BranchTrueFalseTotal
unless $track->{$system} =~ /%s/ 0 283 283
779 }
780 }
781 3058 ▶ $params{ticket_map} = $track if $track;
Branch: 1 branch
BranchTrueFalseTotal
if $track 77 2981 3058
782  
783 # Make it so!
784 3058 ▶ $class->_dbpnt( "Instantiating $class object") if $params{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"verbose"} 3 3055 3058
785 3058 return bless \%params, $class;
786 }
787  
788 ##############################################################################
789  
790 =head2 Class Methods
791  
792 =head3 content_type
793  
794 my $content_type = SVN::Notify->content_type;
795  
796 Returns the content type of the notification message, "text/plain". Used to
797 set the Content-Type header for the message.
798  
799 =cut
800  
801 1617 ▶sub content_type { 'text/plain' }
Subroutine content_type: called CC=1 SCAR=0.0
Pod documented
802  
803 ##############################################################################
804  
805 =head3 register_attributes
806  
807 SVN::Notify::Subclass->register_attributes(
808 foo_attr => 'foo-attr=s',
809 bar => 'bar',
810 bat => undef,
811 );
812  
813 This class method is used by subclasses to register new attributes. Pass in a
814 list of key/value pairs, where the keys are the attribute names and the values
815 are option specifications in the format required by Getopt::Long. SVN::Notify
816 will create accessors for each attribute, and if the corresponding value is
817 defined, it will be used by the C<get_options()> class method to get a
818 command-line option value.
819  
820 See <LSVN::Notify::HTML|SVN::Notify::HTML> for an example usage of
821 C<register_attributes()>.
822  
823 =cut
824  
825 293 my %OPTS;
826  
827 269 ▶sub register_attributes {
Subroutine register_attributes: called CC=3 SCAR=11.0
Pod documented
828 269 my $class = shift;
829 269 my @attrs;
830 269 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 665 269 934
831 665 push @attrs, shift;
832 665 ▶ if (my $opt = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $opt = shift()) 665 0 665
833 665 $OPTS{$attrs[-1]} = $opt;
834 }
835 }
836 269 $class->_accessors(@attrs);
837 }
838  
839 ##############################################################################
840  
841 =head3 get_options
842  
843 my $options = SVN::Notify->get_options;
844  
845 Parses the command-line options in C<@ARGV> to a hash reference suitable for
846 passing as the parameters to C<new()>. See L<"new"> for a complete list of the
847 supported parameters and their corresponding command-line options.
848  
849 This method use Getopt::Long to parse C<@ARGV>. It then looks for any
850 C<handler> and C<filter> options and, if it finds any, loads the appropriate
851 classes and parses any options they requires from C<@ARGV>. Subclasses and
852 filter classes should use C<register_attributes()> to register any attributes
853 and options they require.
854  
855 After that, on Perl 5.8 and later, it decodes all of the string option from
856 the encoding specified by the C<encoding> option or UTF-8. This allows options
857 to be passed to SVN::Notify in that encoding and end up being displayed
858 properly in the resulting notification message.
859  
860 =cut
861  
862 4 ▶sub get_options {
Subroutine get_options: called CC=16 SCAR=30.4
Pod documented
863 4 my $class = shift;
864 4 my $opts = {};
865 4 require Getopt::Long;
866  
867 # Enable bundling and, at the same time, case-sensitive matching of
868 # single character options. Also enable pass-through so that subclasses
869 # can grab more options.
870 4 Getopt::Long::Configure (qw(bundling pass_through));
871  
872 # Get options.
873 Getopt::Long::GetOptions(
874 'repos-path|p=s' => \$opts->{repos_path},
875 'revision|r=s' => \$opts->{revision},
876 'to|t=s@' => \$opts->{to},
877 'to-regex-map|x=s%' => \$opts->{to_regex_map},
878 'to-email-map=s%' => \$opts->{to_email_map},
879 'from|f=s' => \$opts->{from},
880 'user-domain|D=s' => \$opts->{user_domain},
881 'svnlook|l=s' => \$opts->{svnlook},
882 'sendmail|s=s' => \$opts->{sendmail},
883 'set-sender|E' => \$opts->{set_sender},
884 'smtp=s' => \$opts->{smtp},
885 'smtp-port=i' => \$opts->{smtp_port},
886 'smtp-tls!' => \$opts->{smtp_tls},
887 'encoding|charset|c=s'=> \$opts->{encoding},
888 'diff-encoding=s' => \$opts->{diff_encoding},
889 'svn-encoding=s' => \$opts->{svn_encoding},
890 'language|g=s' => \$opts->{language},
891 'with-diff|d' => \$opts->{with_diff},
892 'attach-diff|a' => \$opts->{attach_diff},
893 'diff-switches|w=s' => \$opts->{diff_switches},
894 'diff-content-type=s' => \$opts->{diff_content_type},
895 'reply-to|R=s' => \$opts->{reply_to},
896 'subject-prefix|P=s' => \$opts->{subject_prefix},
897 'subject-cx|C' => \$opts->{subject_cx},
898 'strip-cx-regex|X=s@' => \$opts->{strip_cx_regex},
899 'no-first-line|O' => \$opts->{no_first_line},
900 'max-sub-length|i=i' => \$opts->{max_sub_length},
901 'max-diff-length|e=i' => \$opts->{max_diff_length},
902 'handler|H=s' => \$opts->{handler},
903 'filter|F=s@' => \$opts->{filters},
904 'author-url|A=s' => \$opts->{author_url},
905 'ticket-regex=s' => \$opts->{ticket_regex},
906 'ticket-map=s%' => \$opts->{ticket_map},
907 'verbose|V+' => \$opts->{verbose},
908 'help|h' => \$opts->{help},
909 'man|m' => \$opts->{man},
910 'version|v' => \$opts->{version},
911 'header=s' => \$opts->{header},
912 'footer=s' => \$opts->{footer},
913 'smtp-user=s' => \$opts->{smtp_user},
914 'smtp-pass=s' => \$opts->{smtp_pass},
915 'smtp-authtype=s' => \$opts->{smtp_authtype},
916 6 ▶ 'add-header=s%' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
917 6 shift; push @{ $opts->{add_headers}{+shift} }, shift
918 },
919 'revision-url|U|svnweb-url|S|viewcvs-url=s' => \$opts->{revision_url},
920 'rt-url|T|bugzilla-url|B|jira-url|J|gnats-url|G|ticket-url=s'
921 => \$opts->{ticket_url},
922 4 ▶ ) or return;
Branch: 1 branch
BranchTrueFalseTotal
Getopt::Long::GetOptions("repos-path|p=s", \$opts->{"repos_path"}, "revision|r=s", \$opts->{"revision"}, "to|t=s\@", \$opts->{"to"}, "to-regex-map|x=s%", \$opts->{"to_regex_map"}, "to-email-map=s%", \$opts->{"to_email_map"}, "from|f=s", \$opts->{"from"}, "user-domain|D=s", \$opts->{"user_domain"}, "svnlook|l=s", \$opts->{"svnlook"}, "sendmail|s=s", \$opts->{"sendmail"}, "set-sender|E", \$opts->{"set_sender"}, "smtp=s", \$opts->{"smtp"}, "smtp-port=i", \$opts->{"smtp_port"}, "smtp-tls!", \$opts->{"smtp_tls"}, "encoding|charset|c=s", \$opts->{"encoding"}, "diff-encoding=s", \$opts->{"diff_encoding"}, "svn-encoding=s", \$opts->{"svn_encoding"}, "language|g=s", \$opts->{"language"}, "with-diff|d", \$opts->{"with_diff"}, "attach-diff|a", \$opts->{"attach_diff"}, "diff-switches|w=s", \$opts->{"diff_switches"}, "diff-content-type=s", \$opts->{"diff_content_type"}, "reply-to|R=s", \$opts->{"reply_to"}, "subject-prefix|P=s", \$opts->{"subject_prefix"}, "subject-cx|C", \$opts->{"subject_cx"}, "strip-cx-regex|X=s\@", \$opts->{"strip_cx_regex"}, "no-first-line|O", \$opts->{"no_first_line"}, "max-sub-length|i=i", \$opts->{"max_sub_length"}, "max-diff-length|e=i", \$opts->{"max_diff_length"}, "handler|H=s", \$opts->{"handler"}, "filter|F=s\@", \$opts->{"filters"}, "author-url|A=s", \$opts->{"author_url"}, "ticket-regex=s", \$opts->{"ticket_regex"}, "ticket-map=s%", \$opts->{"ticket_map"}, "verbose|V+", \$opts->{"verbose"}, "help|h", \$opts->{"help"}, "man|m", \$opts->{"man"}, "version|v", \$opts->{"version"}, "header=s", \$opts->{"header"}, "footer=s", \$opts->{"footer"}, "smtp-user=s", \$opts->{"smtp_user"}, "smtp-pass=s", \$opts->{"smtp_pass"}, "smtp-authtype=s", \$opts->{"smtp_authtype"}, "add-header=s%", sub { shift(); push @{$opts->{"add_headers"}{shift()};}, shift(); } , "revision-url|U|svnweb-url|S|viewcvs-url=s", \$opts->{"revision_url"}, "rt-url|T|bugzilla-url|B|jira-url|J|gnats-url|G|ticket-url=s", \$opts->{"ticket_url"}) or return 4 0 4
923  
924 # Load a subclass if one has been specified.
925 4 ▶ if (my $hand = $opts->{handler}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hand = $opts->{"handler"}) 1 3 4
926 1 ▶ eval "require " . __PACKAGE__ . "::$hand" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval 'require SVN::Notify' . "::$hand" or die $@ 1 0 1
927 1 ▶ if ($hand eq 'Alternative') {
Branch: 1 branch
BranchTrueFalseTotal
if ($hand eq "Alternative") 0 1 1
928 # Load the alternative subclasses.
929 Getopt::Long::GetOptions(
930 0 map { delete $OPTS{$_} => \$opts->{$_} } keys %OPTS
931 );
932 0 ▶ for my $alt (@{ $opts->{alternatives} || ['HTML']}) {
Condition0%0/2
$opts->{'alternatives'} || ['HTML']
l!l
00
MC/DC0%0/1
$opts->{'alternatives'} || ['HTML']
$opts->{'alternatives'}
Truth table0%0/2
A
A= $opts->{'alternatives'}
Aresult
11
00
933 0 ▶ eval "require " . __PACKAGE__ . "::$alt" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval 'require SVN::Notify' . "::$alt" or die $@ 0 0 0
934 }
935 }
936 }
937  
938 # Load any filters.
939 4 ▶ if ($opts->{filters}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"filters"}) 1 3 4
940 1 for my $pkg ( @{ $opts->{filters} } ) {
941 1 ▶ $pkg = "SVN::Notify::Filter::$pkg" if $pkg !~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg =~ /::/ 1 0 1
942 1 ▶ eval "require $pkg" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $pkg" or die $@ 1 0 1
943 }
944 }
945  
946 # Disallow pass-through so that any invalid options will now fail.
947 4 Getopt::Long::Configure (qw(no_pass_through));
948 4 my @to_decode;
949 4 ▶ if (%OPTS) {
Branch: 1 branch
BranchTrueFalseTotal
if (%OPTS) { } 2 2 4
950 # Get a list of string options we'll need to decode.
951 0 @to_decode = map { $OPTS{$_} } grep { /=s$/ } keys %OPTS
952 if PERL58;
953  
954 # Load any other options.
955 Getopt::Long::GetOptions(
956 2 map { delete $OPTS{$_} => \$opts->{$_} } keys %OPTS
957 );
958 } else {
959 # Call GetOptions() again so that invalid options will be properly
960 # caught.
961 2 Getopt::Long::GetOptions();
962 }
963  
964 4 if (PERL58) {
965 # Decode all string options.
966 4 ▶ my $encoding = $opts->{encoding} || 'UTF-8';
Condition50%1/2
$opts->{'encoding'} || 'UTF-8'
l!l
04
MC/DC0%0/1
$opts->{'encoding'} || 'UTF-8'
$opts->{'encoding'}
Truth table50%1/2
A
A= $opts->{'encoding'}
Aresult
11
00
967 4 for my $opt ( qw(
968 repos_path
969 revision
970 from
971 user_domain
972 svnlook
973 sendmail
974 smtp
975 smtp_tls
976 smtp_port
977 diff_switches
978 reply_to
979 subject_prefix
980 handler
981 author_url
982 ticket_regex
983 header
984 footer
985 smtp_user
986 smtp_pass
987 revision_url
988 ticket_url
989 ), @to_decode ) {
990 $opts->{$opt} = Encode::decode( $encoding, $opts->{$opt} )
991 84 ▶ if $opts->{$opt};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{$opt} 26 58 84
992 }
993 }
994  
995 # Clear the extra options specifications and return.
996 4 %OPTS = ();
997 4 return $opts;
998 }
999  
1000 ##############################################################################
1001  
1002 =head3 file_label_map
1003  
1004 my $map = SVN::Notify->file_label_map;
1005  
1006 Returns a hash reference of the labels to be used for the lists of files. A
1007 hash reference of file lists is stored in the C<files> attribute after
1008 C<prepare_files()> has been called. The hash keys in that list correspond to
1009 Subversion status codes, and these are mapped to their appropriate labels by
1010 the hash reference returned by this method:
1011  
1012 { U => 'Modified Paths',
1013 A => 'Added Paths',
1014 D => 'Removed Paths',
1015 _ => 'Property Changed'
1016 }
1017  
1018 =cut
1019  
1020 2662 ▶sub file_label_map { \%map }
Subroutine file_label_map: called CC=1 SCAR=0.0
Pod documented
1021  
1022 ##############################################################################
1023  
1024 =head3 find_exe
1025  
1026 my $exe = SVN::Notify->find_exe($exe_name);
1027  
1028 This method searches through the system path, as well as the extra directories
1029 F</usr/local/bin> and F</usr/sbin> (because they're common paths for
1030 C<svnlook> and C<sendmail> for an executable file with the name C<$exe_name>.
1031 The first one it finds is returned with its full path. If none is found,
1032 C<find_exe()> returns undef.
1033  
1034 =cut
1035  
1036 1 ▶sub find_exe {
Subroutine find_exe: called CC=4 SCAR=14.0
Pod documented
1037 1 my ($class, $exe) = @_;
1038 1 $exe .= '.exe' if WIN32;
1039 1 require File::Spec;
1040 1 require Config;
1041 1 for my $path (
1042 File::Spec->path,
1043 qw(/usr/local/bin /usr/bin /usr/sbin),
1044 'C:\\program files\\subversion\\bin',
1045 $Config::Config{installbin},
1046 $Config::Config{installscript},
1047 ) {
1048 3 my $file = File::Spec->catfile($path, $exe);
1049 3 ▶ return $file if -f $file && -x _;
Branch: 1 branch
BranchTrueFalseTotal
if -f $file and -x _ 1 2 3
Condition66%2/3
-f $file and -x _
!ll&&!rl&&r
201
MC/DC50%1/2
-f $file and -x _
-f $file -x _
Truth table66%2/3
A and B
A= -f $fileB= -x _
ABresult
0X0
100
111
1050 }
1051 0 return;
1052 }
1053  
1054 ##############################################################################
1055  
1056 =head1 Instance Interface
1057  
1058 =head2 Instance Methods
1059  
1060 =head3 prepare
1061  
1062 $notifier->prepare;
1063  
1064 Prepares the SVN::Notify object, collecting all the data it needs in
1065 preparation for sending the notification email. Really it's just a shortcut
1066 for:
1067  
1068 $notifier->prepare_recipients;
1069 $notifier->prepare_contents;
1070 $notifier->prepare_files;
1071 $notifier->prepare_subject;
1072  
1073 Only it returns after the call to C<prepare_recipients()> if there are no
1074 recipients (that is, as when recipients are specified solely by the
1075 C<to_regex_map> or C<to_email_map> parameter and none of the regular
1076 expressions match any of the affected directories).
1077  
1078 =cut
1079  
1080 2714 ▶sub prepare {
Subroutine prepare: called CC=5 SCAR=16.2
Pod documented
1081 2714 my $self = shift;
1082 2714 $self->run_filters('pre_prepare');
1083 _usage(
1084 qq{Missing required "to", "to_regex_map", or "to_email_map" parameter}
1085 2714 ▶ ) unless @{$self->{to}} || $self->{to_regex_map} || $self->{to_email_map};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"to"};} or $self->{"to_regex_map"} or $self->{"to_email_map"} 1 2713 2714
Condition66%4/6
@{$self->{"to"};} or $self->{"to_regex_map"} or $self->{"to_email_map"}
l!l&&r!l&&!r
271301
@{$self->{"to"};} or $self->{"to_regex_map"}
l!l&&r!l&&!r
271301
MC/DC33%1/3
@{$self->{"to"};} or $self->{"to_regex_map"} or $self->{"to_email_map"}
@{$self->{"to"};} $self->{"to_regex_map"} $self->{"to_email_map"}
Truth table50%2/4
A or B or C
A= @{$self->{"to"};}B= $self->{"to_regex_map"}C= $self->{"to_email_map"}
ABCresult
1XX1
01X1
0011
0000
1086 2713 $self->prepare_recipients;
1087 2707 ▶ return $self unless @{ $self->{to} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"to"};} 0 2707 2707
1088 2707 $self->prepare_contents;
1089 2624 $self->prepare_files;
1090 2541 $self->prepare_subject;
1091 2541 $self->run_filters('post_prepare');
1092 2541 return $self;
1093 }
1094  
1095 ##############################################################################
1096  
1097 =head3 prepare_recipients
1098  
1099 $notifier->prepare_recipients;
1100  
1101 Collects and prepares a list of the notification recipients. The recipients
1102 are a combination of the value passed to the C<to> parameter as well as any
1103 email addresses specified as keys in the hash reference passed C<to_regex_map>
1104 parameter or values passed to the C<to_email_map> parameter, where the
1105 corresponding regular expressions stored in the hash matches one or more of
1106 the names of the directories affected by the commit.
1107  
1108 If the F<subject_cx> parameter to C<new()> has a true value,
1109 C<prepare_recipients()> also determines the directory name to use for the
1110 context.
1111  
1112 =cut
1113  
1114 2799 ▶sub prepare_recipients {
Subroutine prepare_recipients: called CC=27 SCAR=33.6
Pod documented
1115 2799 my $self = shift;
1116 2799 ▶ $self->_dbpnt( "Preparing recipients list") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 3 2796 2799
1117 2799 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"to_regex_map"} or $self->{"subject_cx"} or $self->{"to_email_map"}) 2493 306 2799
Condition100%6/6
$self->{"to_regex_map"} or $self->{"subject_cx"} or $self->{"to_email_map"}
l!l&&r!l&&!r
235712493
$self->{"to_regex_map"} or $self->{"subject_cx"}
l!l&&r!l&&!r
751602564
MC/DC100%3/3
$self->{"to_regex_map"} or $self->{"subject_cx"} or $self->{"to_email_map"}
$self->{"to_regex_map"} $self->{"subject_cx"} $self->{"to_email_map"}
Truth table100%4/4
A or B or C
A= $self->{"to_regex_map"}B= $self->{"subject_cx"}C= $self->{"to_email_map"}
ABCresult
1XX1
01X1
0011
0000
1118 $self->{to_regex_map}
1119 || $self->{subject_cx}
1120 || $self->{to_email_map}
1121 ) {
1122 2493 $self->{to} = $self->run_filters( recipients => $self->{to} );
1123 2493 return $self;
1124 }
1125  
1126 # Prevent duplication.
1127 306 my $tos = $self->{to} = [ @{ $self->{to} } ];
1128  
1129 my $regexen = $self->{to_regex_map} && $self->{to_email_map}
1130 0 ▶ ? [ %{ $self->{to_regex_map} }, reverse %{ $self->{to_email_map } } ]
Branch: 1 branch
BranchTrueFalseTotal
$self->{'to_regex_map'} ? : 75 231 306
1131 75 ▶ : $self->{to_regex_map} ? [ %{ $self->{to_regex_map} } ]
Branch: 1 branch
BranchTrueFalseTotal
$self->{'to_email_map'} ? : 71 160 231
1132 306 ▶ : $self->{to_email_map} ? [ reverse %{ $self->{to_email_map } } ]
Branch: 1 branch
BranchTrueFalseTotal
$self->{'to_regex_map'} && $self->{'to_email_map'} ? : 0 306 306
Condition66%2/3
$self->{"to_regex_map"} and $self->{"to_email_map"}
!ll&&!rl&&r
231750
MC/DC0%0/2
$self->{"to_regex_map"} and $self->{"to_email_map"}
$self->{"to_regex_map"} $self->{"to_email_map"}
Truth table66%2/3
A and B
A= $self->{"to_regex_map"}B= $self->{"to_email_map"}
ABresult
0X0
100
111
1133 : undef;
1134  
1135 306 ▶ if ($regexen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($regexen) { } 146 160 306
1136 $self->_dbpnt( "Compiling regex_map regular expressions")
1137 146 ▶ if $self->{verbose} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 0 146 146
1138 146 ▶ for (my $i = 1; $i < @$regexen; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$regexen) 438 146 584
1139 438 ▶ $self->_dbpnt( qq{Compiling "$_"}) if $self->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 2 0 438 438
1140 # Remove initial slash and compile.
1141 438 $regexen->[$i] =~ s|^\^[/\\]|^|;
1142 438 $regexen->[$i] = qr/$regexen->[$i]/;
1143 }
1144 } else {
1145 160 $regexen = [];
1146 }
1147  
1148 306 ▶ local $ENV{LANG} = "$self->{svn_env_lang}" if $self->{svn_env_lang};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"svn_env_lang"} 0 306 306
1149 my $fh = $self->_pipe(
1150 $self->{svn_encoding},
1151 '-|', $self->{svnlook},
1152 'changed',
1153 $self->{repos_path},
1154 '-r', $self->{revision},
1155 306 );
1156  
1157 # Read in a list of the files changed.
1158 300 my ($cx, %seen);
1159 300 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 4993 300 5293
1160 4993 s/^.\s*//;
1161 4993 s/[\n\r\/\\]+$//;
1162 4993 ▶ for (my $i = 0; $i < @$regexen; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$regexen) 8640 4993 13633
1163 8640 my ($email, $rx) = @{$regexen}[$i, $i + 1];
1164 # If the file matches the regex, save the email.
1165 8640 ▶ if (/$rx/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/$rx/) 2448 6192 8640
1166 2448 ▶ $self->_dbpnt( qq{"$_" matched $rx}) if $self->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 2 0 2448 2448
1167 2448 ▶ push @$tos, $email unless $seen{$email}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$email}++ 288 2160 2448
1168 }
1169 }
1170 # Grab the context if it's needed for the subject.
1171 4993 ▶ if ($self->{subject_cx}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"subject_cx"}) 2113 2880 4993
1172 # XXX Do we need to set utf8 here?
1173 2113 my $l = length;
1174 2113 ▶ $cx ||= $_;
Condition66%2/3
$cx ||= $_
l!l&&r!l&&!r
17513620
MC/DC0%0/2
$cx ||= $_
$cx $_
Truth table66%2/3
A ||= B
A= $cxB= $_
ABresult
1X1
011
000
1175 2113 ▶ $cx =~ s{[/\\]?[^/\\]+$}{} until !$cx || m{^\Q$cx\E(?:$|/|\\)};
Branch: 1 branch
BranchTrueFalseTotal
(not $cx or m[^\Q$cx\E(?:$|/|\\)]) or do { $cx =~ s([/\\]?[^/\\]+$)[] } 2113 1339 3452
Condition100%3/3
not $cx or m[^\Q$cx\E(?:$|/|\\)]
l!l&&r!l&&!r
20619071339
MC/DC100%2/2
not $cx or m[^\Q$cx\E(?:$|/|\\)]
not $cx m[^\Q$cx\E(?:$|/|\\)]
Truth table100%3/3
not(A) or B
A= not $cxB= m[^\Q$cx\E(?:$|/|\\)]
ABresult
1X1
011
000
1176 }
1177 }
1178 $self->_dbpnt( qq{Context is "$cx"})
1179 300 ▶ if $self->{subject_cx} && $self->{verbose} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"subject_cx"} and $self->{"verbose"} > 1 0 300 300
Condition66%2/3
$self->{"subject_cx"} and $self->{"verbose"} > 1
!ll&&!rl&&r
1441560
MC/DC0%0/2
$self->{"subject_cx"} and $self->{"verbose"} > 1
$self->{"subject_cx"} $self->{"verbose"} > 1
Truth table66%2/3
A and B
A= $self->{"subject_cx"}B= $self->{"verbose"} > 1
ABresult
0X0
100
111
1180 300 ▶ close $fh or warn "Child process exited: $?\n";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or warn "Child process exited: $?\n" 300 0 300
1181 300 $self->{cx} = $cx;
1182 300 $tos = $self->run_filters( recipients => $tos );
1183 $self->_dbpnt( 'Recipients: "', join(', ', @$tos), '"')
1184 300 ▶ if $self->{verbose} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 0 300 300
1185 300 return $self;
1186 }
1187  
1188 ##############################################################################
1189  
1190 =head3 prepare_contents
1191  
1192 $notifier->prepare_contents;
1193  
1194 Prepares the contents of the commit message, including the name of the user
1195 who triggered the commit (and therefore the contents of the "From" header to
1196 be used in the email) and the log message.
1197  
1198 =cut
1199  
1200 2793 ▶sub prepare_contents {
Subroutine prepare_contents: called CC=6 SCAR=17.9
Pod documented
1201 2793 my $self = shift;
1202 2793 ▶ $self->_dbpnt( "Preparing contents") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 3 2790 2793
1203 2793 ▶ local $ENV{LANG} = "$self->{svn_env_lang}" if $self->{svn_env_lang};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"svn_env_lang"} 210 2583 2793
1204 my $lines = $self->_read_pipe($self->{svnlook}, 'info', $self->{repos_path},
1205 2793 '-r', $self->{revision});
1206 2709 $self->{user} = shift @$lines;
1207 2709 $self->{date} = shift @$lines;
1208 2709 $self->{message_size} = shift @$lines;
1209 2709 $self->{message} = $lines;
1210  
1211 # Set up the from address.
1212 2709 ▶ unless ($self->{from}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"from"}) 2709 0 2709
1213 $self->{from} = $self->{user}
1214 2709 ▶ . ( $self->{user_domain} ? "\@$self->{user_domain}" : '' );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'user_domain'} ? : 43 2666 2709
1215 }
1216 2709 $self->{from} = $self->run_filters( from => $self->{from} );
1217  
1218 2709 ▶ if ($self->{verbose} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"} > 1) 2 2707 2709
1219 2 $self->_dbpnt( "From: $self->{from}");
1220 2 $self->_dbpnt( "Message: @$lines");
1221 }
1222 2709 return $self;
1223 }
1224  
1225 ##############################################################################
1226  
1227 =head3 prepare_files
1228  
1229 $notifier->prepare_files;
1230  
1231 Prepares the lists of files affected by the commit, sorting them into their
1232 categories: modified files, added files, and deleted files. It also compiles a
1233 list of files wherein a property was set, which might have some overlap with
1234 the list of modified files (if a single commit both modified a file and set a
1235 property on it).
1236  
1237 If the C<subject_cx> parameter was specified and a single file was affected by
1238 the commit, then C<prepare_files()> will also specify that file name as the
1239 context to be used in the subject line of the commit email.
1240  
1241 =cut
1242  
1243 2709 ▶sub prepare_files {
Subroutine prepare_files: called CC=12 SCAR=24.9
Pod documented
1244 2709 my $self = shift;
1245 2709 ▶ $self->_dbpnt( "Preparing file lists") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 2 2707 2709
1246 2709 my %files;
1247 2709 ▶ local $ENV{LANG} = "$self->{svn_env_lang}" if $self->{svn_env_lang};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"svn_env_lang"} 207 2502 2709
1248 my $fh = $self->_pipe(
1249 $self->{svn_encoding},
1250 '-|', $self->{svnlook},
1251 'changed',
1252 $self->{repos_path},
1253 '-r', $self->{revision},
1254 2709 );
1255  
1256 # Read in a list of changed files.
1257 2625 my $cx = $_ = <$fh>;
1258 2625 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = readline $fh) and do { do { s/[\n\r]+$//; if (s/^(.)(.)\s+//) { $self->_dbpnt("$1,$2 => $_") if $self->{"verbose"} > 2; push @{$files{$1};}, $_; push @{$files{"_"};}, $_ if $2 ne " " and $1 ne "_"; } } } 44136 2625 46761
1259 46761 s/[\n\r]+$//;
1260 46761 ▶ if (s/^(.)(.)\s+//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^(.)(.)\s+//) 46761 0 46761
1261 46761 ▶ $self->_dbpnt( "$1,$2 => $_") if $self->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 2 0 46761 46761
1262 46761 push @{$files{$1}}, $_;
1263 46761 ▶ push @{$files{_}}, $_ if $2 ne ' ' && $1 ne '_';
Branch: 1 branch
BranchTrueFalseTotal
if $2 ne " " and $1 ne "_" 2404 44357 46761
Condition100%3/3
$2 ne " " and $1 ne "_"
!ll&&!rl&&r
32699116582404
MC/DC100%2/2
$2 ne " " and $1 ne "_"
$2 ne " " $1 ne "_"
Truth table100%3/3
A and B
A= $2 ne " "B= $1 ne "_"
ABresult
0X0
100
111
1264 }
1265 } while (<$fh>);
1266  
1267 2625 ▶ if ($self->{subject_cx} && $. == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"subject_cx"} and $. == 1) 51 2574 2625
Condition100%3/3
$self->{"subject_cx"} and $. == 1
!ll&&!rl&&r
24779751
MC/DC100%2/2
$self->{"subject_cx"} and $. == 1
$self->{"subject_cx"} $. == 1
Truth table100%3/3
A and B
A= $self->{"subject_cx"}B= $. == 1
ABresult
0X0
100
111
1268 # There's only one file; it's the context.
1269 51 $cx =~ s/[\n\r]+$//;
1270 51 ($self->{cx} = $cx) =~ s/^..\s+//;
1271 $self->_dbpnt( qq{File context is "$self->{cx}"})
1272 51 ▶ if $self->{verbose} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 0 51 51
1273 }
1274 # Wait till we get here to close the file handle, otherwise $. gets reset
1275 # to 0!
1276 2625 ▶ close $fh or warn "Child process exited: $?\n";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or warn "Child process exited: $?\n" 2625 0 2625
1277 2625 $self->{files} = \%files;
1278 2625 return $self;
1279 }
1280  
1281 ##############################################################################
1282  
1283 =head3 prepare_subject
1284  
1285 $notifier->prepare_subject;
1286  
1287 Prepares the subject line for the notification email. This method B<must> be
1288 called after C<prepare_recipients()> and C<prepare_files()>, since each of
1289 those methods potentially sets up the context for use in the the subject
1290 line. The subject may have a prefix defined by the C<subject_prefix> parameter
1291 to C<new()>, it has the revision number, it might have the context if the
1292 C<subject_cx> specified a true value, and it will have the first sentence or
1293 line of the commit, whichever is shorter. The subject may then be truncated to
1294 the maximum length specified by the C<max_sub_length> parameter.
1295  
1296 =cut
1297  
1298 2625 ▶sub prepare_subject {
Subroutine prepare_subject: called CC=15 SCAR=27.1
Pod documented
1299 2625 my $self = shift;
1300 2625 ▶ $self->_dbpnt( "Preparing subject") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 1 2624 2625
1301  
1302 2625 $self->{subject} = '';
1303  
1304 # Start with the optional message and revision number..
1305 2625 ▶ if ( defined $self->{subject_prefix} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'subject_prefix'}) { } 127 2498 2625
1306 127 ▶ if ( index($self->{subject_prefix}, '%d') > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($self->{'subject_prefix'}, '%d') > 0) { } 59 68 127
1307 $self->{subject} .=
1308 59 sprintf $self->{subject_prefix}, $self->{revision};
1309 } else {
1310 $self->{subject} .=
1311 68 $self->{subject_prefix} . "[$self->{revision}] ";
1312 }
1313 } else {
1314 2498 $self->{subject} .= "[$self->{revision}] ";
1315 }
1316  
1317 # Add the context if there is one.
1318 2625 ▶ if ($self->{cx}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cx"}) 148 2477 2625
1319 148 ▶ if (my $rx = $self->{strip_cx_regex}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rx = $self->{"strip_cx_regex"}) 42 106 148
1320 42 $self->{cx} =~ s/$_// for @$rx;
1321 }
1322 148 ▶ my $space = $self->{no_first_line} ? '' : ': ';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'no_first_line'} ? : 42 106 148
1323 148 ▶ $self->{subject} .= $self->{cx} . $space if $self->{cx};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"cx"} 148 0 148
1324 }
1325  
1326 # Add the first sentence/line from the log message.
1327 2625 ▶ unless ($self->{no_first_line}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"no_first_line"}) 2583 42 2625
1328 # Truncate to first period after a minimum of 10 characters.
1329 2583 my $min = length $self->{message}[0];
1330 2583 ▶ $min = 10 if $min > 10;
Branch: 1 branch
BranchTrueFalseTotal
if $min > 10 2583 0 2583
1331 2583 my $i = index substr($self->{message}[0], $min), '. ';
1332 $self->{subject} .= $i > 0
1333 ? substr($self->{message}[0], 0, $i + 11)
1334 2583 ▶ : $self->{message}[0];
Branch: 1 branch
BranchTrueFalseTotal
$i > 0 ? : 2538 45 2583
1335 }
1336  
1337 # Truncate to the last word under 72 characters.
1338 $self->{subject} =~ s/^(.{0,$self->{max_sub_length}})\s+.*$/$1/m
1339 if $self->{max_sub_length}
1340 2625 ▶ && length $self->{subject} > $self->{max_sub_length};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"max_sub_length"} and length $self->{"subject"} > $self->{"max_sub_length"} 45 2580 2625
Condition66%2/3
$self->{"max_sub_length"} and length $self->{"subject"} > $self->{"max_sub_length"}
!ll&&!rl&&r
2580045
MC/DC50%1/2
$self->{"max_sub_length"} and length $self->{"subject"} > $self->{"max_sub_length"}
$self->{"max_sub_length"} length $self->{"subject"} > $self->{"max_sub_length"}
Truth table66%2/3
A and B
A= $self->{"max_sub_length"}B= length $self->{"subject"} > $self->{"max_sub_length"}
ABresult
0X0
100
111
1341  
1342 # Now filter it.
1343 2625 $self->{subject} = $self->run_filters( subject => $self->{subject} );
1344 2625 ▶ $self->_dbpnt( qq{Subject is "$self->{subject}"}) if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 1 2624 2625
1345  
1346 2625 return $self;
1347 }
1348  
1349 ##############################################################################
1350  
1351 =head3 execute
1352  
1353 $notifier->execute;
1354  
1355 Sends the notification message. This involves opening a file handle to
1356 F<sendmail> or a tied file handle connected to an SMTP server and passing it
1357 to C<output()>. This is the main method used to send notifications or execute
1358 any other actions in response to Subversion activity.
1359  
1360 =cut
1361  
1362 2625 ▶sub execute {
Subroutine execute: called CC=8 SCAR=20.9
Pod documented
1363 2625 my $self = shift;
1364 2625 ▶ $self->_dbpnt( "Sending message") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 1 2624 2625
1365 2625 $self->run_filters('pre_execute');
1366 2625 ▶ return $self unless @{ $self->{to} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"to"};} 0 2625 2625
1367  
1368 2625 ▶ my $out = $self->{smtp} ? SVN::Notify::SMTP->get_handle($self) : do {
Branch: 1 branch
BranchTrueFalseTotal
$self->{'smtp'} ? : 4 2621 2625
1369 2621 ▶ local $ENV{LANG} = $self->{env_lang} if $self->{env_lang};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"env_lang"} 204 2417 2621
1370 $self->_pipe(
1371 $self->{encoding},
1372 '|-', $self->{sendmail},
1373 '-oi', '-t',
1374 2621 ▶ ($self->{set_sender} ? ('-f', $self->{from}) : ())
Branch: 1 branch
BranchTrueFalseTotal
$self->{'set_sender'} ? : 0 2621 2621
1375 );
1376 };
1377  
1378 # Output the message.
1379 2543 $self->output($out);
1380  
1381 2514 ▶ close $out or warn "Child process exited: $?\n";
Branch: 1 branch
BranchTrueFalseTotal
close $out or warn "Child process exited: $?\n" 2514 0 2514
1382 2514 ▶ $self->_dbpnt( 'Message sent' ) if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 1 2513 2514
1383 2514 $self->run_filters('post_execute');
1384 2514 return $self;
1385 }
1386  
1387 ##############################################################################
1388  
1389 =head3 output
1390  
1391 $notifier->output($file_handle);
1392 $notifier->output($file_handle, $no_headers);
1393  
1394 Called internally by C<execute()> to output a complete email message. The file
1395 a file handle, so that C<output()> and its related methods can print directly
1396 to the email message. The optional second argument, if true, will suppress the
1397 output of the email headers.
1398  
1399 Really C<output()> is a simple wrapper around a number of other method calls.
1400 It is thus essentially a shortcut for:
1401  
1402 $notifier->output_headers($out) unless $no_headers;
1403 $notifier->output_content_type($out);
1404 $notifier->start_body($out);
1405 $notifier->output_metadata($out);
1406 $notifier->output_log_message($out);
1407 $notifier->output_file_lists($out);
1408 if ($notifier->with_diff) {
1409 my $diff_handle = $self->diff_handle;
1410 if ($notifier->attach_diff) {
1411 $notifier->end_body($out);
1412 $notifier->output_attached_diff($out, $diff_handle);
1413 } else {
1414 $notifier->output_diff($out, $diff_handle);
1415 $notifier->end_body($out);
1416 }
1417 } else {
1418 $notifier->end_body($out);
1419 }
1420 $notifier->end_message($out);
1421  
1422 =cut
1423  
1424 2662 ▶sub output {
Subroutine output: called CC=5 SCAR=16.1
Pod documented
1425 2662 my ($self, $out, $no_headers) = @_;
1426 2662 ▶ $self->_dbpnt( "Outputting notification message") if $self->{verbose} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 1 2661 2662
1427 2662 ▶ $self->output_headers($out) unless $no_headers;
Branch: 1 branch
BranchTrueFalseTotal
unless $no_headers 2434 228 2662
1428 2662 $self->output_content_type($out);
1429 2662 $self->start_body($out);
1430 2662 $self->output_metadata($out);
1431 2662 $self->output_log_message($out);
1432 2662 $self->output_file_lists($out);
1433 2662 ▶ if ($self->{with_diff}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'with_diff'}) { } 704 1958 2662
1434 # Get a handle on the diff output.
1435 704 my $diff = $self->diff_handle;
1436 675 ▶ if ($self->{attach_diff}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'attach_diff'}) { } 155 520 675
1437 155 $self->end_body($out);
1438 155 $self->output_attached_diff($out, $diff);
1439 } else {
1440 520 $self->output_diff($out, $diff);
1441 520 $self->end_body($out);
1442 }
1443 } else {
1444 1958 $self->end_body($out);
1445 }
1446 2633 $self->end_message($out);
1447  
1448 2633 return $self;
1449 }
1450  
1451 ##############################################################################
1452  
1453 =head3 output_headers
1454  
1455 $notifier->output_headers($file_handle);
1456  
1457 Outputs the headers for the notification message headers. Should be called
1458 only once for a single email message.
1459  
1460 =cut
1461  
1462 2543 ▶sub output_headers {
Subroutine output_headers: called CC=8 SCAR=20.9
Pod documented
1463 2543 my ($self, $out) = @_;
1464 2543 ▶ $self->_dbpnt( "Outputting headers") if $self->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 2 0 2543 2543
1465  
1466 # Q-Encoding (RFC 2047)
1467 my $subj = PERL58 && $self->{subject} =~ /(?:\P{ASCII}|=)/s
1468 ? Encode::encode( 'MIME-Q', $self->{subject} )
1469 2543 ▶ : $self->{subject};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'subject'} =~ /(?:\P{ASCII}|=)/s ? : 2155 388 2543
1470  
1471 # Q-Encode the phrase part of recipient headers.
1472 2543 my $norm;
1473 2543 if (PERL58) {
1474 2543 require Email::Address::XS;
1475 5150 ▶ $norm = sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
1476 return join ', ' => map {
1477 5150 my $addr = Email::Address::XS->parse($_);
1478 5434 ▶ if ($addr->is_valid()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($addr->is_valid) { } 2932 2502 5434
1479 2932 ▶ if (my $phrase = $addr->phrase) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $phrase = $addr->phrase) 0 2932 2932
1480 0 $addr->phrase(Encode::encode( 'MIME-Q', $phrase ));
1481 }
1482 2932 $addr->format;
1483 } else {
1484 2502 $_;
1485 }
1486 } @_;
1487 2543 };
1488 } else {
1489 0 ▶ $norm = sub { join ', ' => @_ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1490 }
1491 2543 my $from = $norm->($self->{from});
1492 2543 my $to = $norm->(@{ $self->{to} });
1493  
1494 2543 my @headers = (
1495 "MIME-Version: 1.0\n",
1496 "X-Mailer: SVN::Notify " . $self->VERSION
1497 . ": http://search.cpan.org/dist/SVN-Notify/\n",
1498 "From: $from\n",
1499 "Errors-To: $from\n",
1500 "To: $to\n",
1501 "Subject: $subj\n"
1502 );
1503  
1504 push @headers, 'Reply-To: ' . $norm->($self->{reply_to}) . "\n"
1505 2543 ▶ if $self->{reply_to};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"reply_to"} 64 2479 2543
1506  
1507 2543 ▶ if (my $heads = $self->{add_headers}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $heads = $self->{"add_headers"}) 1 2542 2543
1508 1 ▶ while (my ($k, $v) = each %{ $heads }) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$heads;}) 2 1 3
1509 2 ▶ push @headers, "$k: $_\n" for ref $v ? @{ $v } : $v;
Branch: 1 branch
BranchTrueFalseTotal
ref $v ? : 1 1 2
1510 }
1511 }
1512  
1513 2543 print $out @{ $self->run_filters( headers => \@headers ) };
1514 2543 return $self;
1515 }
1516  
1517 ##############################################################################
1518  
1519 =head3 output_content_type
1520  
1521 $notifier->output_content_type($file_handle);
1522  
1523 Outputs the content type and transfer encoding headers. These demarcate the
1524 body of the message. If the C<attach_diff> parameter was set to true, then a
1525 boundary string will be generated and the Content-Type set to
1526 "multipart/mixed" and stored as the C<boundary> attribute.
1527  
1528 After that, this method outputs the content type returned by
1529 C<content_type()>, the character set specified by the C<encoding> attribute,
1530 and a Content-Transfer-Encoding of "8bit". Subclasses can either rely on this
1531 functionality or override this method to provide their own content type
1532 headers.
1533  
1534 =cut
1535  
1536 2662 ▶sub output_content_type {
Subroutine output_content_type: called CC=6 SCAR=18.0
Pod documented
1537 2662 my ($self, $out) = @_;
1538 2662 ▶ $self->_dbpnt( "Outputting content type") if $self->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 2 0 2662 2662
1539 # Output the content type.
1540 2662 ▶ if ($self->{attach_diff}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"attach_diff"}) 159 2503 2662
1541 # We need a boundary string.
1542 159 ▶ $self->{boundary} ||= join '', ('a'..'z', 'A'..'Z', 0..9)[ map { rand 62 } 0..10];
Condition66%2/3
$self->{"boundary"} ||= join("", (("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"), ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"), 0..9)[map {rand 62;} 0..10])
l!l&&r!l&&!r
73860
MC/DC0%0/2
$self->{"boundary"} ||= join("", (("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"), ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"), 0..9)[map {rand 62;} 0..10])
$self->{"boundary"} join("", (("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"), ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"), 0..9)[map {rand 62;} 0..10])
Truth table66%2/3
A ||= B
A= $self->{"boundary"}B= join("", (("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"), ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"), 0..9)[map {rand 62;} 0..10])
ABresult
1X1
011
000
1543 159 print $out
1544 qq{Content-Type: multipart/mixed; boundary="$self->{boundary}"\n\n};
1545 }
1546  
1547 2662 my $ctype = $self->content_type;
1548 2662 ▶ print $out "--$self->{boundary}\n" if $self->{attach_diff};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attach_diff"} 159 2503 2662
1549 print $out "Content-Type: $ctype; charset=$self->{encoding}\n",
1550 2662 ▶ ($self->{language} ? "Content-Language: $self->{language}\n" : ()),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'language'} ? : 201 2461 2662
1551 "Content-Transfer-Encoding: 8bit\n\n";
1552 2662 return $self;
1553 }
1554  
1555 ##############################################################################
1556  
1557 =head3 start_body
1558  
1559 $notifier->start_body($file_handle);
1560  
1561 This method starts the body of the notification message, which means that it
1562 outputs the contents of the C<header> attribute, if there are any. Otherwise
1563 it outputs nothing, but see subclasses for other behaviors.
1564  
1565 =cut
1566  
1567 1585 ▶sub start_body {
Subroutine start_body: called CC=4 SCAR=13.9
Pod documented
1568 1585 my ($self, $out) = @_;
1569 1585 ▶ my $start = [ $self->{header} ? ("$self->{header}\n") : () ];
Branch: 1 branch
BranchTrueFalseTotal
$self->{'header'} ? : 15 1570 1585
1570 1585 $start = $self->run_filters( start_body => $start );
1571 1585 ▶ print $out @$start, "\n" if $start && @$start;
Branch: 1 branch
BranchTrueFalseTotal
if $start and @$start 62 1523 1585
Condition66%2/3
$start and @$start
!ll&&!rl&&r
0152362
MC/DC50%1/2
$start and @$start
$start @$start
Truth table66%2/3
A and B
A= $startB= @$start
ABresult
0X0
100
111
1572 1585 return $self;
1573 }
1574  
1575 ##############################################################################
1576  
1577 =head3 output_metadata
1578  
1579 $notifier->output_metadata($file_handle);
1580  
1581 This method outputs the metadata of the commit, including the revision number,
1582 author (user), and date of the revision. If the C<author_url> or
1583 C<revision_url> attributes have been set, then the appropriate URL(s) for the
1584 revision will also be output.
1585  
1586 =cut
1587  
1588 1610 ▶sub output_metadata {
Subroutine output_metadata: called CC=3 SCAR=11.0
Pod documented
1589 1610 my ($self, $out) = @_;
1590 1610 my @lines = ("Revision: $self->{revision}\n");
1591 1610 ▶ if (my $url = $self->{revision_url}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $url = $self->{"revision_url"}) 103 1507 1610
1592 103 push @lines, sprintf " $url\n", $self->{revision};
1593 }
1594  
1595 # Output the Author any any relevant URL.
1596 1610 push @lines, "Author: $self->{user}\n";
1597 1610 ▶ if (my $url = $self->{author_url}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $url = $self->{"author_url"}) 32 1578 1610
1598 32 push @lines, sprintf " $url\n", $self->{user};
1599 }
1600  
1601 1610 push @lines, "Date: $self->{date}\n";
1602  
1603 1610 print $out @{ $self->run_filters( metadata => \@lines ) };
1604 1610 return $self;
1605 }
1606  
1607 ##############################################################################
1608  
1609 =head3 output_log_message
1610  
1611 $notifier->output_log_message($file_handle);
1612  
1613 Outputs the commit log message, as well as the label "Log Message".
1614  
1615 =cut
1616  
1617 1585 ▶sub output_log_message {
Subroutine output_log_message: called CC=6 SCAR=17.9
Pod documented
1618 1585 my ($self, $out) = @_;
1619 1585 ▶ $self->_dbpnt( "Outputting log message") if $self->{verbose} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 1 1584 1585
1620 my $msg = join "\n", @{
1621 1585 $self->run_filters( log_message => $self->{message} )
1622 1585 };
1623  
1624 1585 print $out "Log Message:\n-----------\n$msg\n";
1625  
1626 # Make Revision links.
1627 1585 ▶ if (my $url = $self->{revision_url}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $url = $self->{"revision_url"}) 103 1482 1585
1628 103 ▶ if (my @matches = $msg =~ /\b(?:(?:rev(?:ision)?\s*#?\s*|r)(\d+))\b/ig) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@matches) = $msg =~ /\b(?:(?:rev(?:ision)?\s*#?\s*|r)(\d+))\b/gi) 103 0 103
1629 103 print $out "\nRevision Links:\n--------------\n";
1630 103 printf $out " $url\n", $_ for @matches;
1631 }
1632 }
1633  
1634 # Make ticketing system links.
1635 1585 ▶ if (my $map = $self->ticket_map) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $map = $self->ticket_map) 26 1559 1585
1636 26 my $has_header = 0;
1637 156 ▶ $self->run_ticket_map( sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
1638 156 my ($regex, $url) = @_;
1639 156 ▶ while ($msg =~ /$regex/ig) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg =~ /$regex/gi) 234 156 390
1640 234 ▶ unless ($has_header) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($has_header) 26 208 234
1641 26 print $out "\nTicket Links:\n------------\n";
1642 26 $has_header = 1;
1643 }
1644 234 ▶ printf $out " $url\n", $2 || $1;
Condition66%2/3
$2 || $1
l!l&&r!l&&!r
1301040
MC/DC0%0/2
$2 || $1
$2 $1
Truth table66%2/3
A || B
A= $2B= $1
ABresult
1X1
011
000
1645 }
1646 26 } );
1647 }
1648  
1649 1585 return $self;
1650 }
1651  
1652 ##############################################################################
1653  
1654 =head3 output_file_lists
1655  
1656 $notifier->output_file_lists($file_handle);
1657  
1658 Outputs the lists of modified, added, and deleted files, as well as the list
1659 of files for which properties were changed. The labels used for each group are
1660 pulled in from the C<file_label_map()> class method.
1661  
1662 =cut
1663  
1664 1607 ▶sub output_file_lists {
Subroutine output_file_lists: called CC=6 SCAR=18.0
Pod documented
1665 1607 my ($self, $out) = @_;
1666 1607 ▶ my $files = $self->{files} or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $files = $self->{"files"} or return $self 1607 0 1607
1667 1607 ▶ $self->_dbpnt( "Outputting file lists") if $self->{verbose} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 1 1606 1607
1668 1607 my $map = $self->file_label_map;
1669 # Create the underlines.
1670 1607 my %dash = ( map { $_ => '-' x length($map->{$_}) } keys %$map );
1671  
1672 1607 foreach my $type (qw(U A D _)) {
1673 # Skip it if there's nothing to report.
1674 6428 ▶ next unless $files->{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless $files->{$type} 369 6059 6428
1675 $self->_dbpnt( " Outputting $map->{$type} file list")
1676 6059 ▶ if $self->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 2 0 6059 6059
1677  
1678 # Identify the action and output each file.
1679 6059 print $out "\n", @{ $self->run_filters(
1680 file_lists => [
1681 "$map->{$type}:\n",
1682 "$dash{$type}\n",
1683 6059 map { " $_\n" } @{ $files->{$type} }
1684 ]
1685 ) };
1686 }
1687 1607 print $out "\n";
1688 1607 return $self;
1689 }
1690  
1691 ##############################################################################
1692  
1693 =head3 end_body
1694  
1695 $notifier->end_body($file_handle);
1696  
1697 Closes out the body of the email by outputting the contents of the C<footer>
1698 attribute, if any, and then a couple of newlines. Designed to be called when
1699 the body of the message is complete, and before any call to
1700 C<output_attached_diff()>.
1701  
1702 =cut
1703  
1704 1576 ▶sub end_body {
Subroutine end_body: called CC=5 SCAR=16.2
Pod documented
1705 1576 my ($self, $out) = @_;
1706 1576 ▶ $self->_dbpnt( "Ending body") if $self->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 2 0 1576 1576
1707 1576 ▶ my $end = [ $self->{footer} ? ("$self->{footer}\n") : () ];
Branch: 1 branch
BranchTrueFalseTotal
$self->{'footer'} ? : 15 1561 1576
1708 1576 $end = $self->run_filters( end_body => $end );
1709 1576 ▶ print $out @$end, "\n" if $end && @$end;
Branch: 1 branch
BranchTrueFalseTotal
if $end and @$end 62 1514 1576
Condition66%2/3
$end and @$end
!ll&&!rl&&r
0151462
MC/DC50%1/2
$end and @$end
$end @$end
Truth table66%2/3
A and B
A= $endB= @$end
ABresult
0X0
100
111
1710 1576 return $self;
1711 }
1712  
1713 ##############################################################################
1714  
1715 =head3 output_diff
1716  
1717 $notifier->output_diff($out_file_handle, $diff_file_handle);
1718  
1719 Reads diff data from C<$diff_file_handle> and outputs it to to
1720 C<$out_file_handle>.
1721  
1722 =cut
1723  
1724 228 ▶sub output_diff {
Subroutine output_diff: called CC=2 SCAR=7.1
Pod documented
1725 228 my $self = shift;
1726 228 ▶ $self->_dbpnt( "Outputting diff") if $self->{verbose} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 1 0 228 228
1727 228 $self->_dump_diff(@_);
1728 }
1729  
1730 ##############################################################################
1731  
1732 =head3 output_attached_diff
1733  
1734 $notifier->output_attached_diff($out_file_handle, $diff_file_handle);
1735  
1736 Reads diff data from C<$diff_file_handle> and outputs it to to
1737 C<$out_file_handle> as an attachment.
1738  
1739 =cut
1740  
1741 155 ▶sub output_attached_diff {
Subroutine output_attached_diff: called CC=3 SCAR=11.0
Pod documented
1742 155 my ($self, $out, $diff) = @_;
1743 155 ▶ $self->_dbpnt( "Attaching diff") if $self->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 2 0 155 155
1744 print $out "\n--$self->{boundary}\n",
1745 "Content-Disposition: attachment; filename=",
1746 "r$self->{revision}-$self->{user}.diff\n",
1747 "Content-Type: $self->{diff_content_type}; charset=$self->{encoding}\n",
1748 155 ▶ ($self->{language} ? "Content-Language: $self->{language}\n" : ()),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'language'} ? : 75 80 155
1749 "Content-Transfer-Encoding: 8bit\n\n";
1750 155 $self->_dump_diff($out, $diff);
1751 }
1752  
1753 ##############################################################################
1754  
1755 =head3 end_message
1756  
1757 $notifier->end_message($file_handle);
1758  
1759 Outputs the final part of the message,. In this case, that means only a
1760 boundary if the C<attach_diff> parameter is true. Designed to be called after
1761 any call to C<output_attached_diff()>.
1762  
1763 =cut
1764  
1765 2633 ▶sub end_message {
Subroutine end_message: called CC=2 SCAR=6.9
Pod documented
1766 2633 my ($self, $out) = @_;
1767 2633 ▶ print $out "--$self->{boundary}--\n" if $self->{attach_diff};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attach_diff"} 155 2478 2633
1768 2633 return $self;
1769 }
1770  
1771 ##############################################################################
1772  
1773 =head3 run_ticket_map
1774  
1775 $notifier->run_ticket_map( \&callback, @params );
1776  
1777 Loops over the ticket systems you have defined, calling the C<$callback>
1778 function for each one, passing to it the regex, url and @params specified as
1779 its parameters.
1780  
1781 =cut
1782  
1783 65 ▶sub run_ticket_map {
Subroutine run_ticket_map: called CC=4 SCAR=14.0
Pod documented
1784 65 my ($self, $callback, @params) = @_;
1785  
1786 # Make ticketing system links.
1787 65 ▶ my $map = $self->ticket_map or return;
Branch: 1 branch
BranchTrueFalseTotal
my $map = $self->ticket_map or return 65 0 65
1788 65 my $has_header = 0;
1789 65 ▶ while (my ($regex, $url) = each %$map) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$map) 332 65 397
1790 332 ▶ $regex = $_ticket_regexen{ $regex } || $regex;
Condition66%2/3
$SVN::Notify::_ticket_regexen{$regex} || $regex
l!l&&r!l&&!r
241910
MC/DC0%0/2
$SVN::Notify::_ticket_regexen{$regex} || $regex
$SVN::Notify::_ticket_regexen{$regex} $regex
Truth table66%2/3
A || B
A= $SVN::Notify::_ticket_regexen{$regex}B= $regex
ABresult
1X1
011
000
1791 332 $callback->( $regex, $url, @params );
1792 }
1793 }
1794  
1795 ##############################################################################
1796  
1797 =head3 run_filters
1798  
1799 $data = $notifier->run_filters( $output_type => $data );
1800  
1801 Runs the filters for C<$output_type> on $data. Used internally by SVN::Notify
1802 and by subclasses.
1803  
1804 =cut
1805  
1806 38181 ▶sub run_filters {
Subroutine run_filters: called CC=3 SCAR=11.0
Pod documented
1807 38181 my ($self, $type, $data) = @_;
1808 38181 ▶ my $filters = $self->{filters}{$type} or return $data;
Branch: 1 branch
BranchTrueFalseTotal
my $filters = $self->{"filters"}{$type} or return $data 1329 36852 38181
1809 1329 $data = $_->($self, $data) for @$filters;
1810 1329 return $data;
1811 }
1812  
1813 ##############################################################################
1814  
1815 =head3 filters_for
1816  
1817 my $filters = $notifier->filters_for( $output_type );
1818  
1819 Returns an array reference of of the filters loaded for C<$output_type>.
1820 Returns C<undef> if there are no filters have been loaded for C<$output_type>.
1821  
1822 =cut
1823  
1824 3579 ▶sub filters_for {
Subroutine filters_for: called CC=1 SCAR=0.0
Pod documented
1825 3579 shift->{filters}{+shift};
1826 }
1827  
1828 ##############################################################################
1829  
1830 =head3 diff_handle
1831  
1832 my $diff = $notifier->diff_handle;
1833 while (<$diff>) { print }
1834  
1835 Returns a file handle reference providing access to the the commit diff. It
1836 will usually be passed as the second argument to C<output_diff()> or
1837 C<output_attached_diff()>.
1838  
1839 =cut
1840  
1841 704 ▶sub diff_handle {
Subroutine diff_handle: called CC=3 SCAR=11.3
Pod documented
1842 704 my $self = shift;
1843 # To avoid svnlook output except for diff contents, such as "Modified"
1844 # etc., to be output in the localized string encoded with another encoding
1845 # from diff contents. HTML and HTML::ColorDiff also expect the terms
1846 # printed in English.
1847 704 local $ENV{LANG} = 'C';
1848  
1849 return $self->_pipe(
1850 $self->{diff_encoding},
1851 '-|' => $self->{svnlook},
1852 'diff' => $self->{repos_path},
1853 '-r' => $self->{revision},
1854 ( $self->{diff_switches}
1855 48 ▶ ? grep { defined && $_ ne '' }
Condition33%1/3
defined $_ && $_ ne ''
!ll&&!rl&&r
0048
MC/DC0%0/2
defined $_ && $_ ne ''
defined $_ $_ ne ''
Truth table33%1/3
A && B
A= defined $_B= $_ ne ''
ABresult
0X0
100
111
1856 # Allow quoting of arguments, but strip out the quotes.
1857 split /(?:'([^']+)'|"([^"]+)")?\s+(?:'([^']+)'|"([^"]+)")?/,
1858 $self->{diff_switches}
1859 : ()
1860 704 ▶ ),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'diff_switches'} ? : 48 656 704
1861 );
1862 }
1863  
1864 ##############################################################################
1865 # This method actually dumps the output of C<svnlook diff>. It's a separate
1866 # method because output_attached_diff() and output_diff() do essentially the
1867 # same thing, so they can both call it. The diff output will be truncated at
1868 # max_diff_length, if specified.
1869 ##############################################################################
1870  
1871 383 ▶sub _dump_diff {
Subroutine _dump_diff: called CC=6 SCAR=17.9
1872 383 my ($self, $out, $diff) = @_;
1873 383 $diff = $self->run_filters( diff => $diff );
1874  
1875 383 ▶ if (my $max = $self->{max_diff_length}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $max = $self->{'max_diff_length'}) { } 12 371 383
1876 12 my $length = 0;
1877 12 ▶ while (<$diff>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $diff)) 288 0 288
1878 288 s/[\n\r]+$//;
1879 288 ▶ if (($length += length) < $max) {
Branch: 1 branch
BranchTrueFalseTotal
if (($length += length $_) < $max) { } 276 12 288
1880 276 print $out $_, "\n";
1881 }
1882 else {
1883 12 print $out
1884 "\n\@\@ Diff output truncated at $max characters. \@\@\n";
1885 12 last;
1886 }
1887 }
1888 }
1889  
1890 else {
1891 371 ▶ while (<$diff>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $diff)) 12765 371 13136
1892 12765 s/[\n\r]+$//;
1893 12765 print $out $_, "\n";
1894 }
1895 }
1896 383 ▶ close $diff or warn "Child process exited: $?\n";
Branch: 1 branch
BranchTrueFalseTotal
close $diff or warn "Child process exited: $?\n" 383 0 383
1897 383 return $self;
1898 }
1899  
1900 ##############################################################################
1901  
1902 293 __PACKAGE__->_accessors(qw(
1903 repos_path
1904 revision
1905 to_regex_map
1906 to_email_map
1907 from
1908 user_domain
1909 svnlook
1910 sendmail
1911 set_sender
1912 add_headers
1913 smtp
1914 encoding
1915 diff_encoding
1916 svn_encoding
1917 env_lang
1918 svn_env_lang
1919 language
1920 with_diff
1921 attach_diff
1922 diff_switches
1923 reply_to
1924 subject_prefix
1925 subject_cx
1926 max_sub_length
1927 max_diff_length
1928 author_url
1929 revision_url
1930 ticket_url
1931 ticket_regex
1932 ticket_map
1933 header
1934 footer
1935 verbose
1936 boundary
1937 user
1938 date
1939 message
1940 message_size
1941 subject
1942 files
1943 ));
1944  
1945 ##############################################################################
1946 # This method is used to create accessors for the list of attributes passed to
1947 # it. It creates them both for SVN::Notify (just above) and for all subclasses
1948 # in register_attributes().
1949 ##############################################################################
1950  
1951 562 ▶sub _accessors {
Subroutine _accessors: called CC=2 SCAR=6.9
1952 562 my $class = shift;
1953 562 for my $attr (@_) {
1954 293 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1955 12385 ▶ *{"$class\::$attr"} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
1956 32782 my $self = shift;
1957 32782 ▶ return $self->{$attr} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 32729 53 32782
1958 53 $self->{$attr} = shift;
1959 53 return $self;
1960 12385 };
1961 }
1962 }
1963  
1964 # Aliases for deprecated attributes.
1965 84 ▶sub svnweb_url { shift->revision_url(@_) }
Subroutine svnweb_url: called CC=1 SCAR=0.0
Pod documented
1966 84 ▶sub viewcvs_url { shift->revision_url(@_) }
Subroutine viewcvs_url: called CC=1 SCAR=0.0
Pod documented
1967 0 ▶sub charset { shift->encoding(@_) }
Subroutine charset: not called CC=1 SCAR=6.9
Pod documented
1968  
1969 # Deprecated ticket URL systems.
1970 293 for my $tick (qw(rt bugzilla jira gnats)) {
1971 293 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1972 1172 ▶ *{$tick . '_url'} = sub {
Subroutine __ANON__: called CC=4 SCAR=20.1
1973 156 my $self = shift;
1974 156 ▶ my $map = $self->{ticket_map} || {};
Condition50%1/2
$self->{'ticket_map'} || {}
l!l
0156
MC/DC0%0/1
$self->{'ticket_map'} || {}
$self->{'ticket_map'}
Truth table50%1/2
A
A= $self->{'ticket_map'}
Aresult
11
00
1975 156 ▶ return $map->{$tick} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 156 0 156
1976 0 ▶ if (my $url = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $url = shift()) { } 0 0 0
1977 0 $map->{$tick} = $url;
1978 } else {
1979 0 delete $map->{$tick};
1980 }
1981 0 $self->{ticket_map} = $map;
1982 0 return $self;
1983 1172 };
1984 }
1985  
1986 293 for my $attr (qw(to strip_cx_regex)) {
1987 293 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1988 586 ▶ *{__PACKAGE__ . "::$attr"} = sub {
Subroutine __ANON__: called CC=3 SCAR=12.7
1989 117 my $self = shift;
1990 117 ▶ return wantarray ? @{ $self->{$attr} } : $self->{$attr}[0] unless @_;
Branch: 2 branches
BranchTrueFalseTotal
unless @_ 117 0 117
wantarray ? : 117 0 117
1991 0 $self->{$attr}= \@_;
1992 0 return $self;
1993 586 };
1994 }
1995  
1996 =head2 Accessors
1997  
1998 =head3 repos_path
1999  
2000 my $repos_path = $notifier->repos_path;
2001 $notifier = $notifier->repos_path($repos_path);
2002  
2003 Gets or sets the value of the C<repos_path> attribute.
2004  
2005 =head3 revision
2006  
2007 my $revision = $notifier->revision;
2008 $notifier = $notifier->revision($revision);
2009  
2010 Gets or sets the value of the C<revision> attribute.
2011  
2012 =head3 to
2013  
2014 my $to = $notifier->to;
2015 $notifier = $notifier->to($to);
2016 my @tos = $notifier->to;
2017 $notifier = $notifier->to(@tos);
2018  
2019 Gets or sets the list of values stored in the C<to> attribute. In a scalar
2020 context, it returns only the first value in the list, for backwards
2021 compatibility with older versions of SVN::Notify. In list context, it of
2022 course returns the entire list. Pass in one or more values to set all of the
2023 values for the C<to> attribute.
2024  
2025 =head3 to_regex_map
2026  
2027 my $to_regex_map = $notifier->to_regex_map;
2028 $notifier = $notifier->to_regex_map($to_regex_map);
2029  
2030 Gets or sets the value of the C<to_regex_map> attribute, which is a hash
2031 reference of email addresses mapped to regular expressions.
2032  
2033 =head3 to_email_map
2034  
2035 my $to_email_map = $notifier->to_email_map;
2036 $notifier = $notifier->to_email_map($to_email_map);
2037  
2038 Gets or sets the value of the C<to_email_map> attribute, which is a hash
2039 reference of regular expressions mapped to email addresses.
2040  
2041 =head3 from
2042  
2043 my $from = $notifier->from;
2044 $notifier = $notifier->from($from);
2045  
2046 Gets or sets the value of the C<from> attribute.
2047  
2048 =head3 user_domain
2049  
2050 my $user_domain = $notifier->user_domain;
2051 $notifier = $notifier->user_domain($user_domain);
2052  
2053 Gets or sets the value of the C<user_domain> attribute.
2054  
2055 =head3 svnlook
2056  
2057 my $svnlook = $notifier->svnlook;
2058 $notifier = $notifier->svnlook($svnlook);
2059  
2060 Gets or sets the value of the C<svnlook> attribute.
2061  
2062 =head3 sendmail
2063  
2064 my $sendmail = $notifier->sendmail;
2065 $notifier = $notifier->sendmail($sendmail);
2066  
2067 Gets or sets the value of the C<sendmail> attribute.
2068  
2069 =head3 set_sender
2070  
2071 my $set_sender = $notifier->set_sender;
2072 $notifier = $notifier->set_sender($set_sender);
2073  
2074 Gets or sets the value of the C<set_sender> attribute.
2075  
2076 =head3 smtp
2077  
2078 my $smtp = $notifier->smtp;
2079 $notifier = $notifier->smtp($smtp);
2080  
2081 Gets or sets the value of the C<smtp> attribute.
2082  
2083 =head3 encoding
2084  
2085 my $encoding = $notifier->encoding;
2086 $notifier = $notifier->encoding($encoding);
2087  
2088 Gets or sets the value of the C<encoding> attribute. C<charset> is an alias
2089 preserved for backward compatibility.
2090  
2091 =head3 svn_encoding
2092  
2093 my $svn_encoding = $notifier->svn_encoding;
2094 $notifier = $notifier->svn_encoding($svn_encoding);
2095  
2096 Gets or sets the value of the C<svn_encoding> attribute.
2097  
2098 =head3 diff_encoding
2099  
2100 my $diff_encoding = $notifier->diff_encoding;
2101 $notifier = $notifier->diff_encoding($diff_encoding);
2102  
2103 Gets or sets the value of the C<diff_encoding> attribute.
2104  
2105 =head3 language
2106  
2107 my $language = $notifier->language;
2108 $notifier = $notifier->language($language);
2109  
2110 Gets or sets the value of the C<language> attribute.
2111  
2112 =head3 env_lang
2113  
2114 my $env_lang = $notifier->env_lang;
2115 $notifier = $notifier->env_lang($env_lang);
2116  
2117 Gets or sets the value of the C<env_lang> attribute, which is set to C<<
2118 $notify->language . '.' . $notify->encoding >> when C<language> is set, and
2119 otherwise is C<undef>. This attribute is used to set the C<$LANG> environment
2120 variable, if it is not already set by the environment, before executing
2121 C<sendmail>.
2122  
2123 =head3 svn_env_lang
2124  
2125 my $svn_env_lang = $notifier->svn_env_lang;
2126 $notifier = $notifier->svn_env_lang($svn_env_lang);
2127  
2128 Gets or sets the value of the C<svn_env_lang> attribute, which is set to C<<
2129 $notify->language . '.' . $notify->svn_encoding >> when C<language> is set,
2130 and otherwise is C<undef>. This attribute is used to set the C<$LANG>
2131 environment variable, if it is not already set by the environment, before
2132 executing C<svnlook>. It is not used for C<svnlook diff>, however, as the diff
2133 itself will be emitted in raw octets except for headers such as "Modified",
2134 which need to be in English so that subclasses can parse them. Thus, C<$LANG>
2135 is always set to "C" for the execution of C<svnlook diff>.
2136  
2137 =head3 with_diff
2138  
2139 my $with_diff = $notifier->with_diff;
2140 $notifier = $notifier->with_diff($with_diff);
2141  
2142 Gets or sets the value of the C<with_diff> attribute.
2143  
2144 =head3 attach_diff
2145  
2146 my $attach_diff = $notifier->attach_diff;
2147 $notifier = $notifier->attach_diff($attach_diff);
2148  
2149 Gets or sets the value of the C<attach_diff> attribute.
2150  
2151 =head3 diff_switches
2152  
2153 my $diff_switches = $notifier->diff_switches;
2154 $notifier = $notifier->diff_switches($diff_switches);
2155  
2156 Gets or sets the value of the C<diff_switches> attribute.
2157  
2158 =head3 reply_to
2159  
2160 my $reply_to = $notifier->reply_to;
2161 $notifier = $notifier->reply_to($reply_to);
2162  
2163 Gets or sets the value of the C<reply_to> attribute.
2164  
2165 =head3 add_headers
2166  
2167 my $add_headers = $notifier->add_headers;
2168 $notifier = $notifier->add_headers({
2169 'X-Accept' => [qw(This That)],
2170 'X-Reject' => 'Me!',
2171 });
2172  
2173 Gets or sets the value of the C<add_headers> attribute, which is a hash
2174 reference of the headers to be added to the email message. If one header needs
2175 to appear multiple times, simply pass the corresponding hash value as an array
2176 reference of each value for the header. Not to be confused with the C<header>
2177 accessor, which gets and sets text to be included at the beginning of the body
2178 of the email message.
2179  
2180 =head3 subject_prefix
2181  
2182 my $subject_prefix = $notifier->subject_prefix;
2183 $notifier = $notifier->subject_prefix($subject_prefix);
2184  
2185 Gets or sets the value of the C<subject_prefix> attribute.
2186  
2187 =head3 subject_cx
2188  
2189 my $subject_cx = $notifier->subject_cx;
2190 $notifier = $notifier->subject_cx($subject_cx);
2191  
2192 Gets or sets the value of the C<subject_cx> attribute.
2193  
2194 =head3 strip_cx_regex
2195  
2196 my $strip_cx_regex = $notifier->strip_cx_regex;
2197 $notifier = $notifier->strip_cx_regex($strip_cx_regex);
2198 my @strip_cx_regexs = $notifier->strip_cx_regex;
2199 $notifier = $notifier->strip_cx_regex(@strip_cx_regexs);
2200  
2201 Gets or sets the list of values stored in the C<strip_cx_regex> attribute. In
2202 a scalar context, it returns only the first value in the list; in list
2203 context, it of course returns the entire list. Pass in one or more values to
2204 set all of the values for the C<strip_cx_regex> attribute.
2205  
2206 =head3 max_sub_length
2207  
2208 my $max_sub_length = $notifier->max_sub_length;
2209 $notifier = $notifier->max_sub_length($max_sub_length);
2210  
2211 Gets or sets the value of the C<max_sub_length> attribute.
2212  
2213 =head3 max_diff_length
2214  
2215 my $max_diff_length = $notifier->max_diff_length;
2216 $notifier = $notifier->max_diff_length($max_diff_length);
2217  
2218 Gets or set the value of the C<max_diff_length> attribute.
2219  
2220 =head3 author_url
2221  
2222 my $author_url = $notifier->author_url;
2223 $notifier = $notifier->author_url($author_url);
2224  
2225 Gets or sets the value of the C<author_url> attribute.
2226  
2227 =head3 revision_url
2228  
2229 my $revision_url = $notifier->revision_url;
2230 $notifier = $notifier->revision_url($revision_url);
2231  
2232 Gets or sets the value of the C<revision_url> attribute.
2233  
2234 =head3 svnweb_url
2235  
2236 Deprecated. Pleas use C<revision_url()>, instead.
2237  
2238 =head3 viewcvs_url
2239  
2240 Deprecated. Pleas use C<revision_url()>, instead.
2241  
2242 =head3 verbose
2243  
2244 my $verbose = $notifier->verbose;
2245 $notifier = $notifier->verbose($verbose);
2246  
2247 Gets or sets the value of the C<verbose> attribute.
2248  
2249 =head3 boundary
2250  
2251 my $boundary = $notifier->boundary;
2252 $notifier = $notifier->boundary($boundary);
2253  
2254 Gets or sets the value of the C<boundary> attribute. This string is normally
2255 set by a call to C<output_headers()>, but may be set ahead of time.
2256  
2257 =head3 user
2258  
2259 my $user = $notifier->user;
2260 $notifier = $notifier->user($user);
2261  
2262 Gets or sets the value of the C<user> attribute, which is set to the value
2263 pulled in from F<svnlook> by the call to C<prepare_contents()>.
2264  
2265 =head3 date
2266  
2267 my $date = $notifier->date;
2268 $notifier = $notifier->date($date);
2269  
2270 Gets or sets the value of the C<date> attribute, which is set to the value
2271 pulled in from F<svnlook> by the call to C<prepare_contents()>.
2272  
2273 =head3 message
2274  
2275 my $message = $notifier->message;
2276 $notifier = $notifier->message($message);
2277  
2278 Gets or sets the value of the C<message> attribute, which is set to an array
2279 reference of strings by the call to C<prepare_contents()>.
2280  
2281 =head3 message_size
2282  
2283 my $message_size = $notifier->message_size;
2284 $notifier = $notifier->message_size($message_size);
2285  
2286 Gets or sets the value of the C<message_size> attribute, which is set to the
2287 value pulled in from F<svnlook> by the call to C<prepare_contents()>.
2288  
2289 =head3 subject
2290  
2291 my $subject = $notifier->subject;
2292 $notifier = $notifier->subject($subject);
2293  
2294 Gets or sets the value of the C<subject> attribute, which is normally set
2295 by a call to C<prepare_subject()>, but may be set explicitly.
2296  
2297 =head3 files
2298  
2299 my $files = $notifier->files;
2300 $notifier = $notifier->files($files);
2301  
2302 Gets or sets the value of the C<files> attribute, which is set to a hash
2303 reference of change type mapped to arrays of strings by the call to
2304 C<prepare_files()>.
2305  
2306 =head3 header
2307  
2308 my $header = $notifier->header;
2309 $notifier = $notifier->header($header);
2310  
2311 Gets or set the value of the C<header> attribute. Not to be confused with the
2312 C<add_headers> attribute, which manages headers to be inserted into the
2313 notification email message headers.
2314  
2315 =head3 footer
2316  
2317 my $footer = $notifier->footer;
2318 $notifier = $notifier->footer($footer);
2319  
2320 Gets or set the value of the C<footer> attribute.
2321  
2322 =cut
2323  
2324 ##############################################################################
2325 # This method forks off a process to execute an external program and any
2326 # associated arguments and returns a file handle that can be read from to
2327 # fetch the output of the external program, or written to. Pass "-|" as the
2328 # sole argument to read from another process (such as svnlook), and pass "|-"
2329 # to write to another process (such as sendmail).
2330 ##############################################################################
2331  
2332 9133 ▶sub _pipe {
Subroutine _pipe: called CC=6 SCAR=18.4
2333 9133 my ($self, $encode, $mode) = (shift, shift, shift);
2334 $self->_dbpnt( q{Piping execution of "} . join(q{" "}, @_) . q{"})
2335 9133 ▶ if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 5 9128 9133
2336 # Safer version of backtick (see perlipc(1)).
2337 9133 local *PIPE;
2338 9133 if (WIN32) {
2339 my $cmd = $mode eq '-|'
2340 ? q{"} . join(q{" "}, @_) . q{"|}
2341 : q{|"} . join(q{" "}, @_) . q{"};
2342 open PIPE, $cmd or die "Cannot fork: $!\n";
2343 binmode PIPE, ":encoding($encode)" if PERL58 && $encode;
2344 return *PIPE;
2345 }
2346  
2347 9133 my $pid = open PIPE, $mode;
2348 9133 ▶ die "Cannot fork: $!\n" unless defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 9133 9133
2349  
2350 9133 ▶ if ($pid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid) { } 8848 285 9133
2351 # Parent process. Set the encoding layer and return the file handle.
2352 8848 ▶ binmode PIPE, ":encoding($encode)" if PERL58 && $encode;
Branch: 1 branch
BranchTrueFalseTotal
if $encode 8848 0 8848
2353 8848 return *PIPE;
2354 } else {
2355 # Child process. Execute the commands.
2356 285 ▶ exec @_ or die "Cannot exec $_[0]: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
exec @_ or die "Cannot exec $_[0]: $!\n" 0 0 0
2357 # Not reached.
2358 }
2359 }
2360  
2361 ##############################################################################
2362 # This method passes its arguments to _pipe(), but then fetches each line
2363 # off output from the returned file handle, safely strips out and replaces any
2364 # newlines and carriage returns, and returns an array reference of those
2365 # lines.
2366 ##############################################################################
2367  
2368 2793 ▶sub _read_pipe {
Subroutine _read_pipe: called CC=2 SCAR=7.0
2369 2793 my $self = shift;
2370 2793 my $fh = $self->_pipe( $self->{svn_encoding}, '-|', @_ );
2371 2709 local $/; my @lines = split /(?:\r\n|\r|\n)/, <$fh>;
2372 2709 ▶ close $fh or warn "Child process exited: $?\n";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or warn "Child process exited: $?\n" 2709 0 2709
2373 2709 return \@lines;
2374 }
2375  
2376 ##############################################################################
2377 # This method is used for debugging output in various verbose modes.
2378 ##############################################################################
2379  
2380 0 ▶sub _dbpnt { print ref(shift), ': ', join(' ', @_), "\n"; }
Subroutine _dbpnt: not called CC=1 SCAR=6.9
2381  
2382 ##############################################################################
2383 # This function is used to exit the program with an error if a parameter is
2384 # missing.
2385 ##############################################################################
2386  
2387 3 ▶sub _usage {
Subroutine _usage: called CC=2 SCAR=11.6
2388 3 my ($msg) = @_;
2389  
2390 # Just die if the API is used.
2391 3 ▶ die $msg if $0 !~ /\bsvnnotify(?:[.]bat)?$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $0 =~ /\bsvnnotify(?:[.]bat)?$/ 3 0 3
2392  
2393 # Otherwise, tell 'em how to use it.
2394 0 $msg =~ s/_/-/g;
2395 0 $msg =~ s/(\s+")/$1--/g;
2396 0 $msg =~ s/\bparameter\b/option/g;
2397 0 require Pod::Usage;
2398 0 Pod::Usage::pod2usage(
2399 '-message' => $msg,
2400 '-verbose' => 99,
2401 '-sections' => '(?i:(Usage|Options))',
2402 '-exitval' => 1,
2403 );
2404 }
2405  
2406 package SVN::Notify::SMTP;
2407  
2408 293 $SVN::Notify::SMTP::VERSION = '2.87';
2409  
2410 4 ▶sub get_handle {
Subroutine get_handle: called CC=7 SCAR=19.5
2411 4 my ($class, $notifier) = @_;
2412  
2413 # Load Net::SMTP::TLS.
2414 4 require Net::SMTP::TLS;
2415 4 require Sys::Hostname;
2416 my $smtp = Net::SMTP::TLS->new(
2417 $notifier->{smtp},
2418 Hello => Sys::Hostname::hostname(),
2419 ( $notifier->{smtp_port} ? ( Port => $notifier->{smtp_port} ) : () ),
2420 ( $notifier->{smtp_tls} ? () : (NoTLS => 1) ),
2421 ( $notifier->{smtp_user} ? ( User => $notifier->{smtp_user} ) : () ),
2422 ( $notifier->{smtp_pass} ? ( Password => $notifier->{smtp_pass} ) : () ),
2423 4 ▶ ( $notifier->{verbose} ? ( Debug => 1 ) : () )
Branch: 6 branches
BranchTrueFalseTotal
my $smtp = "Net::SMTP::TLS"->new($notifier->{"smtp"}, "Hello", Sys::Hostname::hostname(), $notifier->{"smtp_port"} ? ("Port", $notifier->{"smtp_port"}) : (), $notifier->{"smtp_tls"} ? () : ("NoTLS", 1), $notifier->{"smtp_user"} ? ("User", $notifier->{"smtp_user"}) : (), $notifier->{"smtp_pass"} ? ("Password", $notifier->{"smtp_pass"}) : (), $notifier->{"verbose"} ? ("Debug", 1) : ()) or die "Unable to create SMTP object: $!" 4 0 4
$notifier->{'smtp_port'} ? : 1 3 4
$notifier->{'smtp_tls'} ? : 0 4 4
$notifier->{'smtp_user'} ? : 1 3 4
$notifier->{'smtp_pass'} ? : 1 3 4
$notifier->{'verbose'} ? : 1 3 4
2424 ) or die "Unable to create SMTP object: $!";
2425  
2426 4 $smtp->mail($notifier->{from});
2427 4 $smtp->to(map { split /\s*,\s*/ } @{ $notifier->{to} });
2428 4 $smtp->data;
2429 4 tie local(*SMTP), $class, $smtp, $notifier;
2430 # Perl 5.6 requires the escape.
2431 4 return SVN::Notify::PERL58 ? *SMTP : \*SMTP;
2432 }
2433  
2434 4 ▶sub TIEHANDLE {
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
2435 4 my ($class, $smtp, $notifier) = @_;
2436 4 bless { smtp => $smtp, notifier => $notifier }, $class;
2437 }
2438  
2439 44 ▶sub PRINT {
Subroutine PRINT: called CC=1 SCAR=0.0
2440 44 my $self = shift;
2441 44 if (SVN::Notify::PERL58) {
2442 44 my $encode = $self->{notifier}->encoding;
2443 return $self->{smtp}->datasend( map {
2444 44 Encode::encode( $encode, $_ )
2445 } @_ )
2446 }
2447 0 return $self->{smtp}->datasend(@_);
2448 }
2449  
2450 4 ▶sub PRINTF {
Subroutine PRINTF: called CC=1 SCAR=0.0
2451 4 my $self = shift;
2452 4 $self->PRINT( sprintf(shift, @_) );
2453 }
2454  
2455 4 ▶sub CLOSE {
Subroutine CLOSE: called CC=1 SCAR=0.0
2456 4 my $self = shift;
2457 4 $self->{smtp}->dataend;
2458 4 $self->{smtp}->quit;
2459 }
2460  
2461 293 1;
2462 __END__
« Notify/HTML/ColorDiff.pm ↑ Summary Notify/HTML.pm »