Wiki.pm

filter: Statementstmt 94.8% 73 / 77 Branchbran 88.8% 16 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 85.7% 6 / 7 totaltotal 93.9% 109 / 116 CC 11 SCAR 7.8
CC
11
Cov
94%
_init
4.0
_pull_nodes
3.0
clear
2.3
CRAP 2.2
« Wiki/Node/Line.pm ↑ Summary Wiki/Node/Item.pm »
1 #############################################################################
2 # (c) by Tels 2004.
3 #
4 #############################################################################
5  
6 package Convert::Wiki;
7  
8 2 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use vars qw/$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 $VERSION = '0.05';
15  
16 2 ▶use Convert::Wiki::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 #############################################################################
19  
20 sub new
21 12 ▶ {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
22 12 my $class = shift;
23  
24 12 my $self = bless {}, $class;
25  
26 12 my $args = $_[0];
27 12 ▶ $args = { @_ } if ref($args) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args ne "HASH" 12 0 12
28  
29 12 $self->clear();
30 12 $self->_init($args);
31 }
32  
33 sub _init
34 12 ▶ {
Subroutine _init: called CC=4 SCAR=13.9
35 12 my ($self,$args) = @_;
36  
37 12 $self->{interlink} = []; # default none
38 12 foreach my $k (keys %$args)
39 {
40 16 ▶ if ($k !~ /^(interlink|debug)\z/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($k =~ /^(interlink|debug)\z/) 1 15 16
41 {
42 1 $self->error ("Unknown option '$k'");
43 }
44 16 $self->{$k} = $args->{$k};
45 }
46
47 12 ▶ if (ref($self->{interlink}) ne 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"interlink"} ne "ARRAY") 1 11 12
48 {
49 1 $self->error ("Option 'interlink' needs a list of phrases");
50 }
51  
52 12 $self->{nodes} = undef;
53 12 $self;
54 }
55  
56 sub nodes
57 2 ▶ {
Subroutine nodes: called CC=2 SCAR=6.9
Pod documented
58 2 my $self = shift;
59  
60 2 my $node = $self->{nodes};
61  
62 2 my $nodes = 0;
63 2 ▶ while (defined $node)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node) 4 2 6
64 {
65 4 $nodes++;
66 4 $node = $node->{next};
67 }
68  
69 2 $nodes;
70 }
71  
72 sub clear
73 19 ▶ {
Subroutine clear: called CC=2 SCAR=8.3
Pod documented
74 19 my $self = shift;
75
76 19 $self->{error} = '';
77  
78 19 my $node = $self->{nodes};
79 # break circular references (this should not be necc., but play safe)
80 19 ▶ while (defined $node)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node) 0 19 19
81 {
82 0 $node->{prev} = undef;
83 0 my $next = $node->{next};
84 0 $node->{next} = undef;
85 0 $node = $next;
86 }
87 19 $self->{nodes} = undef;
88 19 $self;
89 }
90  
91 sub from_txt
92 7 ▶ {
Subroutine from_txt: called CC=1 SCAR=0.0
Pod documented
93 7 my ($self,$txt) = @_;
94  
95 7 require Convert::Wiki::Txt;
96  
97 7 $self->_from_txt($txt);
98  
99 7 $self->_pull_nodes();
100 }
101  
102 sub _pull_nodes
103 7 ▶ {
Subroutine _pull_nodes: called CC=3 SCAR=11.0
104 # ask each node whether it should be removed (based on context)
105 7 my $self = shift;
106  
107 7 my $node = $self->{nodes};
108 7 ▶ while (defined $node)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node) 45 7 52
109 {
110 45 ▶ if ($node->_remove_me())
Branch: 1 branch
BranchTrueFalseTotal
if ($node->_remove_me) { } 1 44 45
111 {
112 1 $node->{prev}->{next} = $node->{next};
113 1 $node->{next}->{prev} = $node->{prev};
114 1 my $next = $node->{next};
115 1 $node->{prev} = undef;
116 1 $node->{next} = undef;
117 1 $node = $next;
118 }
119 else
120 {
121 44 $node = $node->{next};
122 }
123 }
124 7 $self;
125 }
126  
127 sub as_wiki
128 6 ▶ {
Subroutine as_wiki: called CC=2 SCAR=6.9
Pod undocumented
129 6 my $self = shift;
130  
131 6 my $wiki = '';
132 6 my $node = $self->{nodes};
133 6 ▶ while (defined $node)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node) 40 6 46
134 {
135 40 $wiki .= $node->as_wiki($self);
136 40 $node = $node->{next};
137 }
138 6 $wiki;
139 }
140  
141 sub error
142 8 ▶ {
Subroutine error: called CC=2 SCAR=6.9
Pod documented
143 8 my $self = shift;
144  
145 8 ▶ $self->{error} = $_[0] if defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 4 4 8
146 8 $self->{error};
147 }
148  
149 sub debug
150 1 ▶ {
Subroutine debug: called CC=1 SCAR=0.0
Pod documented
151 1 my $self = shift;
152  
153 1 $self->{debug};
154 }
155  
156 2 1;
157 __END__
« Wiki/Node/Line.pm ↑ Summary Wiki/Node/Item.pm »