lib/PurpleWiki/Database/Text.pm

filter: Statementstmt 16.6% 9 / 54 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 14.2% 2 / 14 Podpod 0.0% 0 / 11 totaltotal 12.7% 11 / 86 CC 4 SCAR 14.2
CC
4
Cov
15%
_init
12.0
new
6.0
getText
2.0
CRAP 4.1
« lib/PurpleWiki/Config.pm ↑ Summary lib/PurpleWiki/Database/Page.pm »
1 # PurpleWiki::Database::Text
2 # vi:sw=4:ts=4:ai:sm:et:tw=0
3 #
4 # $Id: Text.pm 366 2004-05-19 19:22:17Z eekim $
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::Text;
32  
33 # PurpleWiki Text Data Access
34  
35 # $Id: Text.pm 366 2004-05-19 19:22:17Z eekim $
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  
40 1 our $VERSION;
41 1 $VERSION = sprintf("%d", q$Id: Text.pm 366 2004-05-19 19:22:17Z eekim $ =~ /\s(\d+)\s/);
42  
43 # Creates a new Text. A text represents the actual
44 # use visible and editable text of a WikiPage. It
45 # can be created empty or by being passed a string.
46 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
47 0 my $proto = shift;
48 0 my %params = @_;
49 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
50 0 my $self = {};
51 0 $self->{data} = $params{data};
52 0 $self->{config} = PurpleWiki::Config->instance();
53 0 bless ($self, $class);
54  
55 0 $self->_init();
56 0 return $self;
57 }
58  
59 # Getters and setters.
60 # FIXME: redunant
61  
62 # Gets the text of this Text.
63 0 ▶sub getText {
Subroutine getText: not called CC=1 SCAR=6.9
Pod undocumented
64 0 my $self = shift;
65 0 return $self->{text};
66 }
67  
68 # Sets the text of this Text.
69 0 ▶sub setText {
Subroutine setText: not called CC=1 SCAR=6.9
Pod undocumented
70 0 my $self = shift;
71 0 my $text = shift;
72 0 $self->{text} = $text;
73 }
74  
75 # Gets whether this text was last edited as a minor
76 # edit.
77 0 ▶sub getMinor {
Subroutine getMinor: not called CC=1 SCAR=6.9
Pod undocumented
78 0 my $self = shift;
79 0 return $self->{minor};
80 }
81  
82 # Sets whether this text was last edited as a minor
83 # edit.
84 0 ▶sub setMinor {
Subroutine setMinor: not called CC=1 SCAR=6.9
Pod undocumented
85 0 my $self = shift;
86 0 my $minor = shift;
87 0 $self->{minor} = $minor;
88 }
89  
90 # Gets whether this text was last edited by a different
91 # author from the previous editor (or maybe the current
92 # viewer, not sure) FIXME: don't be dumb
93 0 ▶sub getNewAuthor {
Subroutine getNewAuthor: not called CC=1 SCAR=6.9
Pod undocumented
94 0 my $self = shift;
95 0 return $self->{newauthor};
96 }
97  
98 # Gets whether this text was last edited by a different
99 # author from the previous editor (or maybe the current
100 # viewer, not sure) FIXME: don't be dumb
101 0 ▶sub setNewAuthor {
Subroutine setNewAuthor: not called CC=1 SCAR=6.9
Pod undocumented
102 0 my $self = shift;
103 0 my $newAuthor = shift;
104 0 $self->{newauthor} = $newAuthor;
105 }
106  
107 # Gets the brief summary of the changes made to the Text.
108 0 ▶sub getSummary {
Subroutine getSummary: not called CC=1 SCAR=6.9
Pod undocumented
109 0 my $self = shift;
110 0 return $self->{summary};
111 }
112  
113 # Sets the brief summary of the changes made to the Text.
114 0 ▶sub setSummary {
Subroutine setSummary: not called CC=1 SCAR=6.9
Pod undocumented
115 0 my $self = shift;
116 0 my $summary = shift;
117 0 $self->{summary} = $summary;
118 }
119  
120 # FIXME: dupe of getMinor
121 # which is better?
122 0 ▶sub isMinor {
Subroutine isMinor: not called CC=1 SCAR=6.9
Pod undocumented
123 0 my $self = shift;
124 0 return $self->{minor};
125 }
126  
127 # Initializes the Text datastructure by pulling fields from
128 # the provided data. If no data is provided, sets up a new
129 # empty page.
130 0 ▶sub _init {
Subroutine _init: not called CC=3 SCAR=24.8
131 0 my $self = shift;
132  
133 0 ▶ if (defined($self->{data})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'data'}) { } 0 0 0
134 0 my $regexp = $self->{config}->FS3;
135 0 my %tempHash = split(/$regexp/, $self->{data}, -1);
136  
137 0 foreach my $key (keys(%tempHash)) {
138 0 $self->{$key} = $tempHash{$key};
139 }
140 } else {
141 0 $self->{text} = 'Describe the new page here.' . "\n";
142 0 $self->{minor} = 0; # Default as major edit
143 0 $self->{newauthor} = 1; # Default as new author
144 0 $self->{summary} = '';
145 }
146 }
147  
148 # Serializes the Text to string so it can be saved.
149 0 ▶sub serialize {
Subroutine serialize: not called CC=1 SCAR=6.9
Pod undocumented
150 0 my $self = shift;
151  
152 0 my $data = join($self->{config}->FS3, map {$_ . $self->{config}->FS3 .
153 0 $self->{$_}} ('text', 'minor', 'newauthor', 'summary'));
154  
155 0 return $data;
156  
157 }
158  
159 1 1;
« lib/PurpleWiki/Config.pm ↑ Summary lib/PurpleWiki/Database/Page.pm »