.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "SVN::Notify::Filter 3pm" .TH SVN::Notify::Filter 3pm "2018-07-03" "perl v5.26.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "Name" .IX Header "Name" SVN::Notify::Filter \- Create output filters for SVN::Notify .SH "Synopsis" .IX Header "Synopsis" .Vb 2 \& package SVN::Notify::Filter::Textile; \& use Text::Textile (); \& \& sub log_message { \& my ($notifier, $lines) = @_; \& return $lines unless $notify\->content_type eq \*(Aqtext/html\*(Aq; \& return [ Text::Textile\->new\->process( join $/, @$lines ) ]; \& } .Ve .SH "Description" .IX Header "Description" This document covers the output filtering capabilities of SVN::Notify. Output filters are simply subroutines that modify content before SVN::Notify outputs it. The idea is to provide a simple interface for anyone to use to change the format of the messages that SVN::Notify creates. Filters are loaded by the \f(CW\*(C`filter\*(C'\fR parameter to \f(CW\*(C`new()\*(C'\fR or by the \f(CW\*(C`\-\-filter\*(C'\fR option to the \f(CW\*(C`svnnotify\*(C'\fR command-line program. .SS "A Quick Example" .IX Subsection "A Quick Example" The most common use for an output filter is to modify the format of log commit messages. Say that your developers write their commit messages in Markdown format, and you'd like it to be reformatted as \s-1HTML\s0 in the messages sent by SVN::Notify::HTML. To do so, just create a Perl module and put it somewhere in the Perl path. Something like this: .PP .Vb 3 \& package SVN::Notify::Filter::Markdown; \& use strict; \& use Text::Markdown (); \& \& sub log_message { \& my ($notifier, $lines) = @_; \& return $lines unless $notify\->content_type eq \*(Aqtext/html\*(Aq; \& return [ Text::Markdown\->new\->markdown( join $/, @$lines ) ]; \& } .Ve .PP Put this code in a file named \fISVN/Notify/Filter/Markdown.pm\fR somewhere in your Perl's path. The way that SVN::Notify filters work is that you simply define a subroutine named for what you want to filter. The subroutine's first argument will always be the SVN::Notify object that's generating the notification message, and the second argument will always be the content to be filtered. .PP In this example, we wanted to filter the commit log message, so we just defined a subroutine named \f(CW\*(C`log_message()\*(C'\fR and, if the message will be \s-1HTML,\s0 passed the lines of the commit message to Text::Markdown to format, returning a new array reference. And that's all there is to writing SVN::Notify filters: Define a subroutine, process the second argument, and return a data structure in the same format as that argument (usually an array reference). .PP Now, to use this filter, just use the \f(CW\*(C`\-\-filter\*(C'\fR option: .PP .Vb 1 \& svnnotify \-p "$1" \-r "$2" \-\-handler HTML \-\-filter Markdown .Ve .PP SVN::Notify will assume that a filter option without \*(L"::\*(R" is in the SVN::Notify::Filter name space, and will load it accordingly. If you instead created your filter in some other name space, say \f(CW\*(C`My::Filter::Markdown\*(C'\fR, then you'd specify the full package name in the \f(CW\*(C`\-\-filter\*(C'\fR option: .PP .Vb 1 \& svnnotify \-p "$1" \-r "$2" \-\-handler HTML \-\-filter My::Filter::Markdown .Ve .PP And that's it! The filter modifies the contents of the log message before SVN::Notify::HTML spits it out. .SS "The Details" .IX Subsection "The Details" Writing SVN::Notify filters is easy. The name of each subroutine in a filter module determines what content it filters. The filter subroutines take two arguments: the SVN::Notify object that's creating the notification message, and the content to be filtered. They should return the filtered content in the same data structure as that in which it was passed. This makes it easy to change the output of SVN::Notify without the hassle of subclassing or sending patches to the maintainer. .PP The names of the filter subroutines and the types of their content arguments and return values are as follows, in the order in which they execute: .PP .Vb 10 \& Sub Name | Second Argument \& \-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& pre_prepare | undef \& recipients | Array reference of email addresses. \& from | String with sender address. \& subject | String with the subject line. \& post_prepare | undef \& pre_execute | undef \& headers | Array reference of individual email headers lines. \& start_html | An array of lines starting an SVN::Notify::HTML document. \& css | An array of lines of CSS. Used only by SVN::Notify::HTML. \& start_body | Array reference of lines at the start of the message body. \& metadata | Array reference of lines of the metadata part of the message. \& log_message | Array reference of lines of log message. \& file_lists | Array reference of lines of file names. The first line will \& | be the type of change for the list, the next a simple line of \& | dashes, and each of the rest of the lines a file name. \& \& diff | A file handle reference to the diff. \& end_body | Array reference of lines at the end of the message body. \& post_execute | undef .Ve .PP Note that the data passed to the filters by SVN::Notify subclasses (SVN::Notify::HTML and SVN::Notify::HTML::ColorDiff) may be in a slightly different format than documented here. Consult the documentation for the relevant methods in those classes for details. .PP There are four special filter subroutines that are called at the beginning and at the end of the execution of the \f(CW\*(C`prepare()\*(C'\fR and \f(CW\*(C`execute()\*(C'\fR methods, named \f(CW\*(C`pre_prepare\*(C'\fR, \f(CW\*(C`post_prepare\*(C'\fR, \f(CW\*(C`pre_execute\*(C'\fR, and \f(CW\*(C`post_execute\*(C'\fR. No data is passed to them and their return values are ignored, but they are included to enable callbacks at the points at which they execute. If, for example, you wanted to set the value of the \f(CW\*(C`to\*(C'\fR attribute before SVN::Notify checks to make sure that there are recipients to whom to send an email, you'd want to do so in a \f(CW\*(C`pre_prepare\*(C'\fR filter. .PP The package name of the filter module can be anything you like; just pass it via the \f(CW\*(C`filter\*(C'\fR parameter, e.g., \f(CW\*(C`filter => [ \*(AqMy::Filter\*(Aq ]\*(C'\fR (or \&\f(CW\*(C`\-\-filter My::Filter\*(C'\fR on the command-line). If, however, it's in the \&\f(CW\*(C`SVN::Notify::Filter\*(C'\fR name space, you can just pass the last bit as the filter name, for example \f(CW\*(C`filter => [ \*(AqNoSpam\*(Aq ]\*(C'\fR (or \f(CW\*(C`\-\-filter NoSpam\*(C'\fR on the command-line) for \f(CW\*(C`SVN::Notify::Filter::NoSpam\*(C'\fR. .PP The first argument to a filter subroutine is always the SVN::Notify object that's generating the message to be delivered. This is so that you can access its attributes for your own nefarious purposes in the filter, as in the first example below. .PP But more importantly \*(-- and more hackerously \*(-- you can add attributes to the SVN::Notify class from your filters. Just call \f(CW\*(C`SVN::Notify\->register_attributes\*(C'\fR to do so, as in the final example below. below. .SS "Examples" .IX Subsection "Examples" First, see the \*(L"Synopsis\*(R" for an example that converts Textile-formatted log messages to \s-1HTML,\s0 and \*(L"A Quick Example\*(R" for a filter that converts a Markdown-formatted log message to \s-1HTML.\s0 If you format your log messages for Trac, just use the included SVN::Notify::Filter::Trac filter. There is also SVN::Notify::Filter::Markdown on \s-1CPAN,\s0 and maybe other filters as well. .PP But if you can't find anything that does what you want, here are some examples to get you started writing your own filters: .IP "\(bu" 4 Map committers to senders .Sp Map committer user names to email addresses using a lookup table. The \*(L"from\*(R" filter gets and returns a string representing the sender. Note how this example makes use of the SVN::Notify object to get the username of the committer: .Sp .Vb 10 \& package SVN::Notify::Filter::FromTable; \& my %committers = ( \& \*(Aqhomer\*(Aq => \*(Aqhomer@simpson.com\*(Aq, \& \*(Aqbart\*(Aq => \*(Aqbart@gmail.com\*(Aq, \& \*(Aqmarge\*(Aq => \*(Aqmarge@urbanmamas.com\*(Aq, \& ); \& sub from { \& my ($notifier, $from) = @_; \& return $committers{ $notifier\->user } || $from; \& } .Ve .IP "\(bu" 4 Add a recipient .Sp Easily done from the command-line using \f(CW\*(C`\-\-to\*(C'\fR, but hey, why not just filter it? .Sp .Vb 6 \& package SVN::Notify::Filter::Cc; \& sub recipients { \& my ($notifier, $recip) = @_; \& push @$recip, \*(Aqboss@example.com\*(Aq; \& return $recip; \& } .Ve .IP "\(bu" 4 Clean up the subject .Sp Need to keep the subject line clean? Just modify the string and return it: .Sp .Vb 7 \& package SVN::Notify::Filter::FromTable; \& my $nasties = qr/\eb(?:golly|shucks|darn)\eb/i; \& sub subject { \& my ($notifier, $subject) = @_; \& $subject =~ s/$nasties/[elided]/g; \& return $subject; \& } .Ve .IP "\(bu" 4 Add an extra header .Sp This emulates \f(CW\*(C`add_header\*(C'\fR to demonstrate header filtering. Maybe you have a special header that tells your spam filtering service to skip filtering for certain messages (not a good idea, but what the hell?): .Sp .Vb 6 \& package SVN::Notify::Filter::NoSpam; \& sub headers { \& my ($notifier, $headers) = @_; \& push @$headers, \*(AqX\-NotSpam: true\*(Aq; \& return $headers; \& } .Ve .IP "\(bu" 4 Uppercase meta data labels .Sp Change the format of the commit meta data section of the message to uppercase all of the headers, so that \*(L"Revision: 111\*(R" becomes \*(L"\s-1REVISION: 111\*(R":\s0 .Sp Note that this example also makes use of the \f(CW\*(C`content_type()\*(C'\fR method of SVN::Notify to determine whether or not to actually do the filtering. This prevents it from being applied to \s-1HTML\s0 messages, where it likely wouldn't be able to do much. .Sp .Vb 7 \& package SVN::Notify::Filter::UpLabels; \& sub metadata { \& my ($notifier, $lines) = @_; \& return $lines unless $notify\->content_type eq \*(Aqtext/plain\*(Aq; \& s/([^:]+:)/uc $1/eg for @$lines; \& return $lines; \& } .Ve .IP "\(bu" 4 Wrap your log message .Sp Log message filtering will probably be quite common, generally to reformat it (see, for example, the included SVN::Notify::Filter::Trac filter, as well as SVN::Notify::Filter::Markdown on \s-1CPAN\s0). If the Markdown and Textile examples above are more than you need, here's a simple filter that reformats the log message so that paragraphs are wrapped. .Sp .Vb 6 \& package SVN::Notify::Filter::WrapMessage; \& use Text::Wrap (); \& sub log_message { \& my ($notifier, $lines) = @_; \& return [ Text::Wrap::wrap( \*(Aq\*(Aq, \*(Aq\*(Aq, @$lines ) ]; \& } .Ve .IP "\(bu" 4 Remove leading \*(L"trunk/\*(R" from file names .Sp Just to demonstrate how to filter file lists: .Sp .Vb 6 \& package SVN::Notify::Filter::StripTrunk; \& sub file_lists { \& my ($notifier, $lines) = @_; \& s{^(\es*)trunk/}{$1} for @$lines; \& return $lines; \& } .Ve .IP "\(bu" 4 Remove leading \*(L"trunk/\*(R" from file names in a diff .Sp This one is a little more complicated because diff filters need to return a file handle. SVN::Notify tries to be as efficient with resources as it can, so it reads each line of the diff from the file handle one-at-a-time, processing and outputting each in turn so as to avoid loading the entire diff into memory. To retain this pattern, the best approach is to tie the file handle to a class that does the filtering one line at a time. The requisite \f(CW\*(C`tie\*(C'\fR class needs only three methods: \f(CW\*(C`TIEHANDLE\*(C'\fR \f(CW\*(C`READLINE\*(C'\fR, and \f(CW\*(C`CLOSE\*(C'\fR. In this example, I've defined them in a different name space than the filter subroutine, so as to simplify SVN::Notify's loading of filters and to keep thing neatly packaged. Note that this filter is applied before SVN::Notify::HTML outputs its diff, so you can modify things before they get marked up by, say, SVN::Notify::HTML::ColorDiff. .Sp .Vb 5 \& package My::IO::TrunkStripper; \& sub TIEHANDLE { \& my ($class, $fh) = @_; \& bless { fh => $fh }, $class; \& } \& \& sub READLINE { \& my $fh = shift\->{fh}; \& defined( my $line = <$fh> ) or return; \& $line =~ s{^((?:\-{3}|[+]{3})\es+)trunk/}{$1}; \& return $line; \& } \& \& sub CLOSE { \& close shift\->{fh} or die $! ? "Error closing diff pipe: $!" \& : "Exit status $? from diff pipe"; \& } \& \& package SVN::Notify::Filter::StripTrunkDiff; \& use Symbol (); \& \& sub diff { \& my ($notifier, $fh) = @_; \& my $filter = Symbol::gensym; \& tie *{ $filter }, \*(AqMy::IO::TrunkStripper\*(Aq, $fh; \& return $filter; \& } .Ve .Sp However, if you don't mind loading the entire diff into memory (because you just \fIknow\fR that all of your commits are small [you know that's not true, right?]), you can simplify things by using a data structure and an existing \s-1IO\s0 module to do the same thing: .Sp .Vb 2 \& package SVN::Notify::Filter::StripTrunkDiff; \& use IO::ScalarArray; \& \& sub diff { \& my ($notifier, $fh) = @_; \& my @lines; \& while (<$fh>) { \& s{^((?:\-{3}|[+]{3})\es+)trunk/}{$1}; \& push @lines, $_; \& } \& return IO::ScalarArray\->new(\e@lines); \& } .Ve .Sp But do beware of this approach if you're likely to commit changes that would generate very larges diffs! .IP "\(bu" 4 Filter based on parameter .Sp You can also add attributes (and therefor command-line options) to SVN::Notify in your filter in order to alter its behavior. This is precisely what the included SVN::Notify::Filter::Trac module does: it adds a new attribute, \f(CW\*(C`trac_url()\*(C'\fR, so that it can create the proper Trac links in your commit messages. See the documentation for \&\fIregister_attributes()\fR for details on its arguments mapping attribute names to Getopt::Long rules. .Sp Note that this example also makes use of the \f(CW\*(C`content_type()\*(C'\fR method of SVN::Notify to determine whether or not to actually do the filtering. This prevents it from inadvertently converting the log file to \s-1HTML\s0 in plain text messages, such as those sent by default by SVN::Notify, or the plain text part sent by SVN::Notify::Alternative. .Sp .Vb 1 \& package SVN::Notify::Filter::Trac; \& \& SVN::Notify\->register_attributes( trac_url => \*(Aqtrac\-url=s\*(Aq ); \& \& sub log_message { \& my ($notify, $lines) = @_; \& return $lines unless $notify\->content_type eq \*(Aqtext/html\*(Aq; \& my $trac = Text::Trac\->new( trac_url => $notify\->trac_url ); \& return [ $trac\->parse( join $/, @{ $lines } ) ]; \& } .Ve .SH "Contributing Filters" .IX Header "Contributing Filters" I created the filtering feature of SVN::Notify in the hopes that all those folks who want new features for SVN::Notify will stop asking me for them and instead start writing them themselves. I should have thought to do it a long time ago, because, in truth, about half the features of SVN::Notify could have been implemented as filters (maybe more than half). .PP So by all means write your filters for SVN::Notify. If you've think you've got a really good one, or a filter that others will find useful, please \fBdo not send it to me.\fR A better option is to package it up and put it on the \s-1CPAN.\s0 Go ahead! Take an example from this document, if you want, put it in a module, write a few tests, and upload the distribution. Model your distribution on SVN::Notify::Filter::Markdown, which is already separately distributed on \s-1CPAN.\s0 Let's create a mini-ecosystem of SVN::Notify filters, all available via \s-1CPAN.\s0 That way, lots of people can take advantage of them, new \*(L"features\*(R" can be added on a regular basis, and I don't have to keep adding cruft to SVN::Notify itself! .SH "See Also" .IX Header "See Also" .IP "SVN::Notify" 4 .IX Item "SVN::Notify" The class that makes this stuff all work. .IP "SVN::Notify::HTML" 4 .IX Item "SVN::Notify::HTML" The SVN::Notify class that likely will be most often used when filtering messages. Check its documentation for variations on filter handling from SVN::Notify. .IP "SVN::Notify::Filter::Trac" 4 .IX Item "SVN::Notify::Filter::Trac" Filters log messages to convert them from Trac wiki format to \s-1HTML.\s0 Also demonstrates the ability to add attributes to SVN::Notify (and options to \&\fIsvnnotify\fR for added functionality of the filter. .IP "SVN::Notify::Filter::Markdown" 4 .IX Item "SVN::Notify::Filter::Markdown" A separate \s-1CPAN\s0 distribution that filters log messages to convert them from Markdown format to \s-1HTML.\s0 Check it out to get an idea how to create your own filter distributions on \s-1CPAN.\s0 .SH "Author" .IX Header "Author" David E. Wheeler .SH "Copyright and License" .IX Header "Copyright and License" Copyright (c) 2008\-2016 David E. Wheeler. Some Rights Reserved. .PP This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.