File Coverage

blib/lib/Kwiki/EscapeURI.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::EscapeURI;
2 1     1   34820 use strict;
  1         2  
  1         36  
3 1     1   5 use warnings;
  1         1  
  1         28  
4 1     1   331 use Kwiki::Plugin -Base;
  0            
  0            
5             use mixin 'Kwiki::Installer';
6              
7             use URI::Escape qw(uri_escape_utf8);
8              
9             our $VERSION = '0.02';
10              
11             const class_id => 'escape_uri';
12             const class_title => "uri escape to raw UTF8 links";
13              
14             sub init {
15             super;
16             my $formatter = $self->hub->load_class('formatter');
17             $formatter->table->{forced} = 'Kwiki::EscapeURI::ForcedLink';
18             }
19              
20             sub register {
21             my $registry = shift;
22             $registry->add(preload => 'escape_uri');
23             $registry->add(hook => 'page:kwiki_link', pre => 'uri_hook');
24             }
25              
26             sub uri_hook {
27             my $hook = pop;
28             $hook->code(undef);
29             my ($label) = @_;
30             my $page_uri = uri_escape_utf8($self->uri);
31             $label = $self->title
32             unless defined $label;
33             my $class = $self->active
34             ? '' : ' class="empty"';
35             qq($label);
36             }
37              
38             package Kwiki::EscapeURI::ForcedLink;
39             use base 'Kwiki::Formatter::ForcedLink';
40              
41             use URI::Escape qw(uri_escape_utf8);
42              
43             sub html {
44             $self->matched =~ $self->pattern_start;
45             my $target = $1;
46             my $page_uri = uri_escape_utf8($target);
47             my $class = $self->hub->pages->new_from_name($target)->exists
48             ? '' : ' class="empty"';
49             my $text = $self->escape_html($target);
50             return qq($text);
51             }
52              
53             package Kwiki::EscapeURI;
54             __DATA__