lib/PurpleWiki/View/debug.pm untested

filter: Statementstmt 0.0% 0 / 80 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 41 Podpod 0.0% 0 / 36 totaltotal 0.0% 0 / 175 CC 6 SCAR 16.5
CC
6
Cov
0%
recurse
30.0
_heading
6.0
new
2.0
CRAP 5.2
1 # PurpleWiki::View::debug.pm
2 #
3 # $Id: debug.pm 444 2004-08-05 08:14:37Z eekim $
4 #
5 # Copyright (c) Blue Oxen Associates 2002-2004. All rights reserved.
6 #
7 # This file is part of PurpleWiki. PurpleWiki is derived from:
8 #
9 # UseModWiki v0.92 (c) Clifford A. Adams 2000-2001
10 # AtisWiki v0.3 (c) Markus Denker 1998
11 # CVWiki CVS-patches (c) Peter Merel 1997
12 # The Original WikiWikiWeb (c) Ward Cunningham
13 #
14 # PurpleWiki is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the
26 # Free Software Foundation, Inc.
27 # 59 Temple Place, Suite 330
28 # Boston, MA 02111-1307 USA
29  
30 package PurpleWiki::View::debug;
31 use 5.005;
32 use strict;
33 use warnings;
34 use Carp;
35 use PurpleWiki::View::Driver;
36  
37 ############### Package Globals ###############
38  
39 our $VERSION;
40 $VERSION = sprintf("%d", q$Id: debug.pm 444 2004-08-05 08:14:37Z eekim $ =~ /\s(\d+)\s/);
41  
42 our @ISA = qw(PurpleWiki::View::Driver);
43  
44  
45 ############### Overloaded Methods ###############
46  
47 sub new {
48 my $proto = shift;
49 my $class = ref($proto) || $proto;
50 my $self = $class->SUPER::new(@_);
51  
52 # Object State
53 $self->{outputString} = "";
54 $self->{indentLevel} = -1;
55  
56 bless($self, $class);
57 return $self;
58 }
59  
60 sub view {
61 my ($self, $wikiTree) = @_;
62 $self->SUPER::view($wikiTree);
63  
64 my $title = $wikiTree->title || '';
65  
66 $self->{outputString} = 'title:' . $title . "\n" .
67 $self->{outputString};
68 return $self->{outputString};
69 }
70  
71 sub recurse {
72 my ($self, $nodeRef) = @_;
73  
74 # recurse() should never be called on an undefined node.
75 if (not defined $nodeRef) {
76 carp "Warning: tried to recurse on an undefined node\n";
77 return;
78 }
79  
80 if ($nodeRef->isa('PurpleWiki::StructuralNode')) {
81 $self->traverse($nodeRef->content) if defined $nodeRef->content;
82 }
83  
84 if (defined $nodeRef->children) {
85 $self->{indentLevel}++;
86 $self->traverse($nodeRef->children);
87 $self->{indentLevel}--;
88 }
89 }
90  
91 #sub Main {
92 # my ($self, $nodeRef) = @_;
93 # if ($nodeRef->type =~ /^(section|indent|ul|ol|dl)$/) {
94 # $self->{indentLevel}++;
95 # }
96 #}
97  
98 #sub Post {
99 # my ($self, $nodeRef) = @_;
100 # if ($nodeRef->type =~ /^(section|indent|ul|ol|dl)$/) {
101 # $self->{indentLevel}--;
102 # }
103 #}
104  
105 sub sectionPre { shift->_headingWithNewline(@_) }
106 sub indentPre { shift->_headingWithNewline(@_) }
107 sub ulPre { shift->_headingWithNewline(@_) }
108 sub olPre { shift->_headingWithNewline(@_) }
109 sub dlPre { shift->_headingWithNewline(@_) }
110  
111 sub hPre { shift->_heading(@_) }
112 sub pPre { shift->_heading(@_) }
113 sub liPre { shift->_heading(@_) }
114 sub ddPre { shift->_heading(@_) }
115 sub dtPre { shift->_heading(@_) }
116 sub prePre { shift->_heading(@_) }
117 sub sketchPre { shift->_heading(@_) }
118  
119 sub bPre { &_showType(@_) }
120 sub iPre { &_showType(@_) }
121 sub ttPre { &_showType(@_) }
122 sub nowikiPre { &_showType(@_) }
123 sub transclusionPre { &_showType(@_) }
124 sub linkPre { &_showType(@_) }
125 sub urlPre { &_showType(@_) }
126 sub wikiwordPre { &_showType(@_) }
127 sub freelinkPre { &_showType(@_) }
128 sub imagePre { &_showType(@_) }
129  
130 sub textMain { shift->{outputString} .= shift->content . "\n" }
131 sub nowikiMain { shift->{outputString} .= shift->content . "\n" }
132 sub transclusionMain { shift->{outputString} .= shift->content . "\n" }
133 sub linkMain { shift->{outputString} .= shift->content . "\n" }
134 sub urlMain { shift->{outputString} .= shift->content . "\n" }
135 sub wikiwordMain { shift->{outputString} .= shift->content . "\n" }
136 sub freelinkMain { shift->{outputString} .= shift->content . "\n" }
137 sub imageMain { shift->{outputString} .= shift->content . "\n" }
138  
139  
140 ############### Private Methods ###############
141  
142 sub _showType {
143 my ($self, $nodeRef) = @_;
144 $self->{outputString} .= uc($nodeRef->type) . ':';
145 }
146  
147 sub _heading {
148 my ($self, $nodeRef) = @_;
149 $self->{outputString} .= ' 'x(2 * $self->{indentLevel});
150 $self->{outputString} .= $nodeRef->type.":";
151 $self->{outputString} .= $nodeRef->id.':' if ($nodeRef->id);
152 }
153  
154 sub _headingWithNewline {
155 my ($self, $nodeRef) = @_;
156 $self->{outputString} .= ' 'x(2 * $self->{indentLevel});
157 $self->{outputString} .= $nodeRef->type.":\n";
158 }
159 1;
160 __END__