line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################# |
2
|
|
|
|
|
|
|
# (c) by Tels 2004. |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
############################################################################# |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Convert::Wiki; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
56775
|
use 5.006001; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
106
|
|
9
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
66
|
|
10
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
85
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
11
|
use vars qw/$VERSION/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
139
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = '0.05'; |
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
666
|
use Convert::Wiki::Node; |
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
1279
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
############################################################################# |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new |
21
|
|
|
|
|
|
|
{ |
22
|
12
|
|
|
12
|
1
|
6510
|
my $class = shift; |
23
|
|
|
|
|
|
|
|
24
|
12
|
|
|
|
|
199
|
my $self = bless {}, $class; |
25
|
|
|
|
|
|
|
|
26
|
12
|
|
|
|
|
24
|
my $args = $_[0]; |
27
|
12
|
50
|
|
|
|
231
|
$args = { @_ } if ref($args) ne 'HASH'; |
28
|
|
|
|
|
|
|
|
29
|
12
|
|
|
|
|
35
|
$self->clear(); |
30
|
12
|
|
|
|
|
31
|
$self->_init($args); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _init |
34
|
|
|
|
|
|
|
{ |
35
|
12
|
|
|
12
|
|
19
|
my ($self,$args) = @_; |
36
|
|
|
|
|
|
|
|
37
|
12
|
|
|
|
|
25
|
$self->{interlink} = []; # default none |
38
|
12
|
|
|
|
|
42
|
foreach my $k (keys %$args) |
39
|
|
|
|
|
|
|
{ |
40
|
16
|
100
|
|
|
|
931
|
if ($k !~ /^(interlink|debug)\z/) |
41
|
|
|
|
|
|
|
{ |
42
|
1
|
|
|
|
|
4
|
$self->error ("Unknown option '$k'"); |
43
|
|
|
|
|
|
|
} |
44
|
16
|
|
|
|
|
53
|
$self->{$k} = $args->{$k}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
12
|
100
|
|
|
|
210
|
if (ref($self->{interlink}) ne 'ARRAY') |
48
|
|
|
|
|
|
|
{ |
49
|
1
|
|
|
|
|
3
|
$self->error ("Option 'interlink' needs a list of phrases"); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
12
|
|
|
|
|
19
|
$self->{nodes} = undef; |
53
|
12
|
|
|
|
|
216
|
$self; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub nodes |
57
|
|
|
|
|
|
|
{ |
58
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
59
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
5
|
my $node = $self->{nodes}; |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
4
|
my $nodes = 0; |
63
|
2
|
|
|
|
|
27
|
while (defined $node) |
64
|
|
|
|
|
|
|
{ |
65
|
4
|
|
|
|
|
5
|
$nodes++; |
66
|
4
|
|
|
|
|
10
|
$node = $node->{next}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
582
|
$nodes; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub clear |
73
|
|
|
|
|
|
|
{ |
74
|
19
|
|
|
19
|
1
|
199
|
my $self = shift; |
75
|
|
|
|
|
|
|
|
76
|
19
|
|
|
|
|
60
|
$self->{error} = ''; |
77
|
|
|
|
|
|
|
|
78
|
19
|
|
|
|
|
200
|
my $node = $self->{nodes}; |
79
|
|
|
|
|
|
|
# break circular references (this should not be necc., but play safe) |
80
|
19
|
|
|
|
|
62
|
while (defined $node) |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
|
|
|
|
0
|
$node->{prev} = undef; |
83
|
0
|
|
|
|
|
0
|
my $next = $node->{next}; |
84
|
0
|
|
|
|
|
0
|
$node->{next} = undef; |
85
|
0
|
|
|
|
|
0
|
$node = $next; |
86
|
|
|
|
|
|
|
} |
87
|
19
|
|
|
|
|
38
|
$self->{nodes} = undef; |
88
|
19
|
|
|
|
|
195
|
$self; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub from_txt |
92
|
|
|
|
|
|
|
{ |
93
|
7
|
|
|
7
|
1
|
1817
|
my ($self,$txt) = @_; |
94
|
|
|
|
|
|
|
|
95
|
7
|
|
|
|
|
4179
|
require Convert::Wiki::Txt; |
96
|
|
|
|
|
|
|
|
97
|
7
|
|
|
|
|
204
|
$self->_from_txt($txt); |
98
|
|
|
|
|
|
|
|
99
|
7
|
|
|
|
|
23
|
$self->_pull_nodes(); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _pull_nodes |
103
|
|
|
|
|
|
|
{ |
104
|
|
|
|
|
|
|
# ask each node whether it should be removed (based on context) |
105
|
7
|
|
|
7
|
|
13
|
my $self = shift; |
106
|
|
|
|
|
|
|
|
107
|
7
|
|
|
|
|
13
|
my $node = $self->{nodes}; |
108
|
7
|
|
|
|
|
25
|
while (defined $node) |
109
|
|
|
|
|
|
|
{ |
110
|
45
|
100
|
|
|
|
139
|
if ($node->_remove_me()) |
111
|
|
|
|
|
|
|
{ |
112
|
1
|
|
|
|
|
2
|
$node->{prev}->{next} = $node->{next}; |
113
|
1
|
|
|
|
|
2
|
$node->{next}->{prev} = $node->{prev}; |
114
|
1
|
|
|
|
|
2
|
my $next = $node->{next}; |
115
|
1
|
|
|
|
|
3
|
$node->{prev} = undef; |
116
|
1
|
|
|
|
|
2
|
$node->{next} = undef; |
117
|
1
|
|
|
|
|
11
|
$node = $next; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
else |
120
|
|
|
|
|
|
|
{ |
121
|
44
|
|
|
|
|
111
|
$node = $node->{next}; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
7
|
|
|
|
|
34
|
$self; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub as_wiki |
128
|
|
|
|
|
|
|
{ |
129
|
6
|
|
|
6
|
0
|
109
|
my $self = shift; |
130
|
|
|
|
|
|
|
|
131
|
6
|
|
|
|
|
10
|
my $wiki = ''; |
132
|
6
|
|
|
|
|
13
|
my $node = $self->{nodes}; |
133
|
6
|
|
|
|
|
14
|
while (defined $node) |
134
|
|
|
|
|
|
|
{ |
135
|
40
|
|
|
|
|
132
|
$wiki .= $node->as_wiki($self); |
136
|
40
|
|
|
|
|
123
|
$node = $node->{next}; |
137
|
|
|
|
|
|
|
} |
138
|
6
|
|
|
|
|
33
|
$wiki; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub error |
142
|
|
|
|
|
|
|
{ |
143
|
8
|
|
|
8
|
1
|
595
|
my $self = shift; |
144
|
|
|
|
|
|
|
|
145
|
8
|
100
|
|
|
|
20
|
$self->{error} = $_[0] if defined $_[0]; |
146
|
8
|
|
|
|
|
32
|
$self->{error}; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub debug |
150
|
|
|
|
|
|
|
{ |
151
|
1
|
|
|
1
|
1
|
14
|
my $self = shift; |
152
|
|
|
|
|
|
|
|
153
|
1
|
|
|
|
|
4
|
$self->{debug}; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
1; |
157
|
|
|
|
|
|
|
__END__ |