HTML::TrackerLink - Autogenerates links to Bug/Tracker systems
# Create a linker for only #12345 for a single tracker system my $linker = HTML::TrackerLink->new( 'http://host/path?id=%n' ); # Create a linker for a single named ( 'Bug #12345' ) system $linker = HTML::TrackerLink->new( 'bug', 'http://host/path?id=%n' ); # Create a linker for multiple named systems $linker = HTML::TrackerLink->new( 'bug' => 'http://host1/path?id=%n', 'tracker' => 'http://host2/path?id=%n', ); # For the multiple linker, make it default to an arbitrary system $linker->default( 'http://host/path?id=%n' ); # For the multiple linker, make it default to one of the keywords $linker->default_keyword( 'bug' ); # Process a string, and add links my $string = 'Fix for bug 1234, described in client request CT #1234'; $string = $linker->process( $string );
HTML::TrackerLink is a package for automatically generating links to one or more external systems from references found in ordinary text, such as CVS commit messages. It tries to do this as intelligently and as flexibly as possible.
Most tracking systems ( bugs, client requests etc, henceforth known as a 'Tracker' ) use a numeric ID number as a key for the tracker item. Web interfaces to these systems will generally contain a URL like the following.
Mozilla Bugzilla 100,000th Bug Example URL http://bugzilla.mozilla.org/show_bug.cgi?id=100000
HTML::TrackerLink takes as arguments a generic form of this URL, created by replacing the number of the tracker item, with the symbol '%n'. For the previous example.
HTML::TrackerLink URL for Mozilla Bugzilla http://bugzilla.mozilla.org/show_bug.cgi?id=%n
When HTML::TrackerLink find a valid reference while processing, it will replace the %n with the id it finds, and replace the reference in the source string with a resulting link.
Any tracker URL arguments passed to HTML::TrackerLink will be checked to make sure that they actually contain the %n placeholder.
HTML::TrackerLink does two types of searches in the source text, a 'default' search, and 'keyword' searches.
A default search will look only for a number with a preceding hash, like '#12345'. Note that the default search will NOT match with naked numbers, such as '12345'.
A keyword search is a little more flexible. For a 'bug' keyword search, the following would all be valid, and matched against.
bug 12345 # Simplest form Bug 12345 # Case insensitive BuG 12345 # Case insensitive and allows multiple spaces bug #12345 # Normal hashed number form Bug #12345 # Again, case insensitive
The keyword search would NOT match with the following
bug12345 # Must be seperated by whitespace bug#12345 # Even in this case bigbug 12345 # 'bug' must be a seperate word
All of these searches are performed condurrently, meaning that given both a default search, and a
'bug' keyword search, the following would match the way you would expect it to.
Client issue #435 ( Bug #1532 ) fixed
'Bug #1532' would link to your bug tracking system, and the
'#435' would link to your client feedback tracking system, which is the default.
The keyword can be up to 32 characters long, containing only word characters, and cannot start with a number. Irrelevant of the case passed, the keywords are stored internally in lowercase. As such, you cannot have two seperate keyword searchs for
new constructor takes a variety of arguments and returns a new HTML::TrackerLink processing object.
new are accepted in one of the following formats.
A empty HTML::LinkTracker object is created without any trackers set
If a single argument is passed, the argument is assume be the tracker URL for a the default search.
If two arguments are passed, they are assumed to be a single keyword search. In the case where the HTML::TrackerLink object is created with only one keyword, the default search will ALSO be set to the same tracker, so that in systems with only one possible place to link to, people that forget the keyword will still get their references linked to.
It also catches a cases where there is a message like
'This resolves Bug #12, #13, #14 and #15'.
If more than two arguments are passed, they are assumed to be a set of keyword searches. In this case, the default search will NOT be set, as we cannot be sure which case the default should go to.
To assign the default in this case, you should use the
In all cases, the
new method will returns a new HTML::TrackerLink object on success, or
undef if an error has occured. ( Invalid keyword/URL formats etc ).
Returns a list containing all current defined keywords
If passed a single argument, returns the current URL for the keyword, or
undef if the keyword does not exist.
If passed two arguments, it will add a new keyword search, or replace an existing one, returning true on success, or
undef if the keyword or tracker URL are invalid.
If passed, explicitly sets the tracker URL to be used for the default search.
Returns the default search URL
undef if attempting to set an invalid tracker_url
Sets the default search to be the same as an already existing keyword search.
Returns true on success.
undef if the keyword does not exist.
process methods takes a string as argument, and applies the searches to it.
Returns the processed string on success.
undef on error.
When an error occurs, the
errstr method allows you to get access to the error message.
errstr can be called as either a static or object method.
i.e. The following are equivalent
# Calling errstr as a static method my $linker = HTML::TrackerLink->new( 'badurl' ); die HTML::TrackerLink->errstr; # Calling errstr as an object method my $linker = HTML::TrackerLink->new( 'badurl' ); die $linker->errstr;
Although the code for this module was extracted from a known working application, this package itself has only basic tests. Please report any bugs encountered.
Bugs should be reported via the CPAN bug tracker at
For other issues, or commercial enhancement or support, contact the author.
Adam Kennedy <firstname.lastname@example.org>
Copyright 2002 - 2008 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.