1package Text::Trac::LinkResolver::Attachment;
2
3use strict;
4use warnings;
5use base qw( Text::Trac::LinkResolver );
6
7our $VERSION = '0.24';
8
9sub init {
10	my $self = shift;
11}
12
13sub format_link {
14	my ( $self, $match, $target, $label ) = @_;
15	return $match if $self->_is_disabled;
16
17	my $c = $self->{context};
18	$label ||= $match;
19
20	my ( $type, $name, $file ) = ( $match =~ m/attachment:([^:]+):([^:]+):([^:\]\s]+)/ );
21	my $url = $c->{trac_attachment_url} || $c->trac_url . 'attachment/';
22	$url .= "$type/$name/$file";
23
24	return sprintf '<a %s href="%s">%s</a>', ( $c->{class} ? q{class="attachment"} : '' ), $url, $label;
25}
26
271;
28