Toolkit/Formatter/WikiLinkFormatterParent.pm

filter: Statementstmt 62.1% 23 / 37 Branchbran 25.0% 2 / 8 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 71.4% 5 / 7 Podpod 66.6% 2 / 3 totaltotal 56.9% 33 / 58 CC 6 SCAR 16.3
CC
6
Cov
55%
rename_links
12.0
new
6.0
__ANON__
3.0
CRAP 5.1
« Toolkit/Plugin.pm ↑ Summary Toolkit/Search/Base.pm »
1 package Wiki::Toolkit::Formatter::WikiLinkFormatterParent;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use vars qw( $VERSION @_links_found );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 $VERSION = '0.01';
7  
8 3 ▶use Text::WikiFormat as => 'wikiformat';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 Wiki::Toolkit::Formatter::WikiLinkFormatterParent - The parent of Wiki::Toolkit formatters that work with Wiki Links.
13  
14 =head1 DESCRIPTION
15  
16 A provider of common formatter methods for L<Wiki::Toolkit> formatters that
17 deal with Wiki Links.
18  
19 =cut
20  
21 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
22 0 my ($class, @args) = @_;
23 0 my $self = {};
24 0 bless $self, $class;
25 0 ▶ $self->_init(@args) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_init(@args) or return undef 0 0 0
26 0 return $self;
27 }
28  
29 =head1 METHODS
30  
31 =head2 C<rename_links>
32  
33 $formatter->rename_links( $from, $to, $content );
34  
35 Renames all the links to a certain page in the supplied content.
36 (Obviously this is dependent on object properties such as
37 C<extended_links> and C<implicit_links>.)
38  
39 =cut
40  
41 0 ▶sub rename_links {
Subroutine rename_links: not called CC=3 SCAR=24.8
Pod documented
42 0 my ($self, $from, $to, $content) = @_;
43  
44 # If we support extended (square bracket) links, update those
45 0 ▶ if($self->{_extended_links}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_extended_links"}) 0 0 0
46 0 $content =~ s/\[$from\]/\[$to\]/g;
47 0 $content =~ s/\[$from(\s*|.*?)\]/\[$to$1\]/g;
48 }
49  
50 # If we support implicit (camelcase) links, update those
51 0 ▶ if($self->{_implicit_links}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_implicit_links"}) 0 0 0
52 0 $content =~ s/\b$from\b/$to/g;
53 0 $content =~ s/^$from\b/$to/gm;
54 0 $content =~ s/\b$from$/$to/gm;
55 }
56  
57 0 return $content;
58 }
59  
60 =head2 C<find_internal_links>
61  
62 my @links_to = $formatter->find_internal_links( $content );
63  
64 Returns a list of all nodes that the supplied content links to.
65 (Obviously this is dependent on object properties such as
66 C<extended_links> and C<implict_links>.)
67  
68 =cut
69  
70 3 ▶sub find_internal_links {
Subroutine find_internal_links: called CC=1 SCAR=0.0
Pod documented
71 3 my ($self, $raw) = @_;
72  
73 3 @_links_found = ();
74  
75 my $foo = wikiformat($raw,
76 4 ▶ { link => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
77 4 my ($link, $opts) = @_;
78 4 ▶ $opts ||= {};
Condition50%1/2
$opts ||= {}
l!l
40
MC/DC0%0/1
$opts ||= {}
$opts
Truth table50%1/2
A
A= $opts
Aresult
11
00
79 4 my $title;
80 ($link, $title) = split(/\|/, $link, 2)
81 4 ▶ if $opts->{extended};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"extended"} 3 1 4
82 4 push @Wiki::Toolkit::Formatter::WikiLinkFormatterParent::_links_found,
83 $link;
84 4 return ""; # don't care about output
85 }
86 },
87 {
88 extended => $self->{_extended_links},
89 prefix => $self->{_node_prefix},
90 implicit_links => $self->{_implicit_links}
91 }
92 3 );
93  
94 3 my @links = @_links_found;
95 3 @_links_found = ();
96 3 return @links;
97 }
98  
99 =head1 SEE ALSO
100  
101 L<Wiki::Toolkit::Formatter::Default>
102  
103 =head1 AUTHOR
104  
105 Kake Pugh (kake@earth.li).
106  
107 =head1 COPYRIGHT
108  
109 Copyright (C) 2002-2003 Kake Pugh. All Rights Reserved.
110 Copyright (C) 2006-2009 the Wiki::Toolkit team. All Rights Reserved.
111  
112 This module is free software; you can redistribute it and/or modify it
113 under the same terms as Perl itself.
114  
115 =cut
116  
117 3 1;
« Toolkit/Plugin.pm ↑ Summary Toolkit/Search/Base.pm »