File Coverage

blib/lib/Text/Trac/LinkResolver/Attachment.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 4 50.0
condition 3 6 50.0
subroutine 5 5 100.0
pod 0 2 0.0
total 28 35 80.0


line stmt bran cond sub pod time code
1             package Text::Trac::LinkResolver::Attachment;
2              
3 8     8   54 use strict;
  8         17  
  8         221  
4 8     8   36 use warnings;
  8         17  
  8         205  
5 8     8   39 use base qw( Text::Trac::LinkResolver );
  8         16  
  8         40  
6              
7             our $VERSION = '0.22';
8              
9             sub init {
10 1607     1607 0 2931 my $self = shift;
11             }
12              
13             sub format_link {
14 5     5 0 20 my ( $self, $match, $target, $label ) = @_;
15 5 50       34 return $match if $self->_is_disabled;
16              
17 5         28 my $c = $self->{context};
18 5   33     18 $label ||= $match;
19              
20 5         35 my ( $type, $name, $file ) = ( $match =~ m/attachment:([^:]+):([^:]+):([^:\]\s]+)/ );
21 5   66     114 my $url = $c->{trac_attachment_url} || $c->trac_url . 'attachment/';
22 5         46 $url .= "$type/$name/$file";
23              
24 5 50       104 return sprintf '%s', ( $c->{class} ? q{class="attachment"} : '' ), $url, $label;
25             }
26              
27             1;