lib/PurpleWiki/Database/Section.pm

filter: Statementstmt 15.1% 12 / 79 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 15.0% 3 / 20 Podpod 0.0% 0 / 16 totaltotal 11.8% 15 / 127 CC 6 SCAR 14.0
CC
6
Cov
14%
_init
12.0
new
6.0
getText
6.0
CRAP 4.0
« lib/PurpleWiki/Database/Page.pm ↑ Summary lib/PurpleWiki/InlineNode.pm »
1 # PurpleWiki::Database::Section
2 # vi:sw=4:ts=4:ai:sm:et:tw=0
3 #
4 # $Id: Section.pm 473 2004-08-11 07:51:17Z cdent $
5 #
6 # Copyright (c) Blue Oxen Associates 2002-2003. All rights reserved.
7 #
8 # This file is part of PurpleWiki. PurpleWiki is derived from:
9 #
10 # UseModWiki v0.92 (c) Clifford A. Adams 2000-2001
11 # AtisWiki v0.3 (c) Markus Denker 1998
12 # CVWiki CVS-patches (c) Peter Merel 1997
13 # The Original WikiWikiWeb (c) Ward Cunningham
14 #
15 # PurpleWiki is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
19 #
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the
27 # Free Software Foundation, Inc.
28 # 59 Temple Place, Suite 330
29 # Boston, MA 02111-1307 USA
30  
31 package PurpleWiki::Database::Section;
32  
33 # PurpleWiki Section Data Access
34  
35 # $Id: Section.pm 473 2004-08-11 07:51:17Z cdent $
36  
37 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use PurpleWiki::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use PurpleWiki::Database::Text;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 1 our $VERSION;
42 1 $VERSION = sprintf("%d", q$Id: Section.pm 473 2004-08-11 07:51:17Z cdent $ =~ /\s(\d+)\s/);
43  
44 # Creates a new Section reference, may be a
45 # a new one or an existing one. Arguments
46 # are passed directly to _init() for use
47 # in filling data fields.
48 #
49 # Sections are used in both PageS and KeptRevisionS
50 # to represent a single version of a WikiPage. They
51 # contain metadata about the wiki page, and a pointer
52 # to the text itself.
53 #
54 # FIXME: argument passing is very crufty throughout this
55 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
56 0 my $proto = shift;
57 0 my %params = @_;
58 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
59 0 my $self = {};
60 0 bless ($self, $class);
61 0 $self->{config} = PurpleWiki::Config->instance();
62 0 $self->_init(@_);
63 0 return $self;
64 }
65  
66 # Creates a new Text from this Section
67 0 ▶sub getText {
Subroutine getText: not called CC=2 SCAR=17.9
Pod undocumented
68 0 my $self = shift;
69  
70 0 ▶ if (!ref($self->{data})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self->{"data"}) 0 0 0
71 0 $self->{data} = new PurpleWiki::Database::Text(data => $self->{data});
72
73 }
74 0 return $self->{data};
75 }
76  
77 # Gets the host that last editied this Section.
78 0 ▶sub getHost {
Subroutine getHost: not called CC=1 SCAR=6.9
Pod undocumented
79 0 my $self = shift;
80 0 return $self->{host};
81 }
82  
83 # Sets the host that last editied this Section.
84 0 ▶sub setHost {
Subroutine setHost: not called CC=1 SCAR=6.9
Pod undocumented
85 0 my $self = shift;
86 0 my $host = shift;
87 0 $self->{host} = $host;
88 }
89  
90 # Gets the IP that last editied this Section.
91 0 ▶sub getIP {
Subroutine getIP: not called CC=1 SCAR=6.9
Pod undocumented
92 0 my $self = shift;
93 0 return $self->{ip};
94 }
95  
96 # Gets the user ID that last editied this Section.
97 0 ▶sub getID {
Subroutine getID: not called CC=1 SCAR=6.9
Pod undocumented
98 0 my $self = shift;
99 0 return $self->{id};
100 }
101  
102 0 ▶sub setID {
Subroutine setID: not called CC=1 SCAR=6.9
Pod undocumented
103 0 my $self = shift;
104 0 $self->{id} = shift;
105 }
106  
107 # Gets the username that last edited this Section.
108 # FIXME: Discussion on UseModWiki points out that keeping
109 # both ID and username is problematic from a clean
110 # data standpoint.
111 0 ▶sub getUsername {
Subroutine getUsername: not called CC=1 SCAR=6.9
Pod undocumented
112 0 my $self = shift;
113 0 return $self->{username};
114 }
115  
116 0 ▶sub setUsername {
Subroutine setUsername: not called CC=1 SCAR=6.9
Pod undocumented
117 0 my $self = shift;
118 0 $self->{username} = shift;
119 }
120  
121 # Gets the revision of this section. If this Section
122 # is the current revision then the containing Page
123 # will have the same revision.
124 0 ▶sub getRevision {
Subroutine getRevision: not called CC=1 SCAR=6.9
Pod undocumented
125 0 my $self = shift;
126 0 return $self->{revision};
127 }
128  
129 # Sets the revision of this section.
130 0 ▶sub setRevision {
Subroutine setRevision: not called CC=1 SCAR=6.9
Pod undocumented
131 0 my $self = shift;
132 0 my $revision = shift;
133 0 $self->{revision} = $revision;
134 }
135  
136 # Gets the timestamp of the last edit.
137 0 ▶sub getTS {
Subroutine getTS: not called CC=1 SCAR=6.9
Pod undocumented
138 0 my $self = shift;
139 0 return $self->{ts};
140 }
141  
142 # Sets the timestamp of the last edit.
143 0 ▶sub setTS {
Subroutine setTS: not called CC=1 SCAR=6.9
Pod undocumented
144 0 my $self = shift;
145 0 my $ts = shift;
146 0 $self->{ts} = $ts;
147 }
148  
149 # Gets the timestamp of when this section
150 # was stored as a revision (became a KeptRevision)
151 0 ▶sub getKeepTS {
Subroutine getKeepTS: not called CC=1 SCAR=6.9
Pod undocumented
152 0 my $self = shift;
153 0 return $self->{keepts};
154 }
155  
156 # Sets the timestamp of when this section
157 # was stored as a revision (became a KeptRevision)
158 0 ▶sub setKeepTS {
Subroutine setKeepTS: not called CC=1 SCAR=6.9
Pod undocumented
159 0 my $self = shift;
160 0 my $time = shift;
161 0 $self->{keepts} = $time;
162 }
163  
164 # Initializes the Section datastructure by pulling fields from
165 # the page. Or creates a new one with default fields.
166 # FIXME: default fields should be constants.
167 0 ▶sub _init {
Subroutine _init: not called CC=3 SCAR=24.8
168 0 my $self = shift;
169 0 my %args = @_;
170  
171 # If we have data to push in
172 0 ▶ if (defined($args{data})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{'data'}) { } 0 0 0
173 0 my $regexp = $self->{config}->FS2;
174 0 my %tempHash = split(/$regexp/, $args{data}, -1);
175  
176 0 foreach my $key (keys(%tempHash)) {
177 0 $self->{$key} = $tempHash{$key};
178 }
179 0 $self->{data} = $self->getText();
180 } else {
181 0 $self->{name} = 'text_default';
182 0 $self->{version} = 1;
183 0 $self->{revision} = 0;
184 0 $self->{tscreate} = $args{now};
185 0 $self->{ts} = $args{now};
186 0 $self->{ip} = $ENV{REMOTE_ADDR};
187 0 $self->{host} = '';
188 0 $self->{id} = $args{userID};
189 0 $self->{username} = $args{username};
190 0 $self->{data} = new PurpleWiki::Database::Text();
191 }
192 }
193  
194 # Serializes the Section data to a string and calls
195 # serialize() on the contained Text object.
196 0 ▶sub serialize {
Subroutine serialize: not called CC=2 SCAR=17.9
Pod undocumented
197 0 my $self = shift;
198  
199 0 my $textData = $self->{data}->serialize();
200  
201 0 my $separator = $self->{config}->FS2;
202  
203 0 ▶ my $data = join($separator, map {$_ . $separator . ($self->{$_} || '')}
Condition0%0/2
$self->{$_} || ''
l!l
00
MC/DC0%0/1
$self->{$_} || ''
$self->{$_}
Truth table0%0/2
A
A= $self->{$_}
Aresult
11
00
204 ('name', 'version', 'id', 'username', 'ip', 'host',
205 'ts', 'tscreate', 'keepts', 'revision'));
206 0 $data .= $separator . 'data' . $separator . $textData;
207  
208 0 return $data;
209 }
210  
211 1 1;
« lib/PurpleWiki/Database/Page.pm ↑ Summary lib/PurpleWiki/InlineNode.pm »