File Coverage

lib/Kwiki/CoolURI.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Kwiki::CoolURI;
2 1     1   28186 use strict;
  1         2  
  1         43  
3 1     1   6 use warnings;
  1         2  
  1         40  
4 1     1   2098 use Kwiki::Plugin -Base;
  0            
  0            
5             use mixin 'Kwiki::Installer';
6              
7             our $VERSION = '0.04';
8              
9             const class_id => 'cool_uri';
10             const class_title => "Cool URIs don't change";
11              
12             sub init {
13             super;
14             $self->hub->template->add_path('plugin/cool_uri/template/tt2');
15             my $formatter = $self->hub->load_class('formatter');
16             $formatter->table->{forced} = 'Kwiki::CoolURI::ForcedLink';
17             }
18              
19             sub register {
20             my $registry = shift;
21             $registry->add(preload => 'cool_uri');
22             $registry->add(hook => 'page:kwiki_link', pre => 'uri_hook');
23             }
24              
25             sub uri_hook {
26             my $hook = pop;
27             $hook->code(undef);
28             my ($label) = @_;
29             my $page_uri = $self->uri;
30             $label = $self->title
31             unless defined $label;
32             my $class = $self->active
33             ? '' : ' class="empty"';
34             qq($label);
35             }
36              
37             package Kwiki::CoolURI::ForcedLink;
38             use base 'Kwiki::Formatter::ForcedLink';
39              
40             sub html {
41             $self->matched =~ $self->pattern_start;
42             my $target = $1;
43             my $text = $self->escape_html($target);
44             my $class = $self->hub->pages->new_from_name($target)->exists
45             ? '' : ' class="empty"';
46             return qq($target);
47             }
48              
49             package Kwiki::CoolURI;
50             __DATA__