| 1 | # PurpleWiki::Tree.pm | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # $Id: Tree.pm 385 2004-06-02 08:39:02Z matthew $ | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # Copyright (c) Blue Oxen Associates 2002-2003. 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::Tree; | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 17 | ▶ | use 5.005; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 17 | ▶ | use PurpleWiki::StructuralNode; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 17 | our $VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 17 | $VERSION = sprintf("%d", q$Id: Tree.pm 385 2004-06-02 08:39:02Z matthew $ =~ /\s(\d+)\s/); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | ### constructor | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | my (%options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | my $self; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | $self = {}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | ▶ | $self->{title} = $options{title} ? $options{title} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | ▶ | $self->{subtitle} = $options{subtitle} ? $options{subtitle} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | $self->{id} = $options{id} ? $options{id} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | ▶ | $self->{date} = $options{date} ? $options{date} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | ▶ | $self->{version} = $options{version} ? $options{version} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | $self->{authors} = &_validateAuthors($options{authors}) | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | ▶ | ? $options{authors} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | $self->{rootNode} = PurpleWiki::StructuralNode->new(type=>'document'); | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | bless($self, $this); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | ### accessors/mutators | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | sub root { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
root: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | return $this->{rootNode}; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | ▶ | sub title { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
title: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 4 | ▶ | $this->{title} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 4 | return $this->{title}; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | ▶ | sub subtitle { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subtitle: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 4 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 4 | ▶ | $this->{subtitle} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 4 | return $this->{subtitle}; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | ▶ | sub id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | ▶ | $this->{id} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | return $this->{id}; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | ▶ | sub date { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
date: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 4 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | ▶ | $this->{date} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 4 | return $this->{date}; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | ▶ | sub version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 4 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | ▶ | $this->{version} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | return $this->{version}; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 11 | ▶ | sub authors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
authors: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 11 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 11 | my $authors = shift; | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 11 | ▶ | if (&_validateAuthors($authors)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | $this->{authors} = $authors; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 11 | return $this->{authors}; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | ### methods | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub view { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
view: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my ($driver, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $driver = lc($driver); | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $viewer = "PurpleWiki::View::$driver"; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | eval "require $viewer"; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ($@) { # driver not found | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | # FIXME: Need better exception handling. | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | return "Error: Unable to load \"$driver\" view driver: $@\n"; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $driverObj = $viewer->new(%params); | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | return $driverObj->view($this); | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | ### private | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 13 | ▶ | sub _validateAuthors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validateAuthors: called CC=7 SCAR=20.6
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 13 | my $authors = shift; | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 13 | ▶ | if ($authors && ref($authors) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$authors and ref $authors eq "ARRAY"
MC/DC100%2/2
$authors and ref $authors eq "ARRAY"
$authors
ref $authors eq "ARRAY"
Truth table100%3/3
A and B
A= $authorsB= ref $authors eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | foreach my $author (@{$authors}) { | |||||||||||||||||||||||||||||||||||||||||
| 140 | 3 | ▶ | if ( (ref($author) ne 'ARRAY') || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $author ne "ARRAY" or scalar @{$author;} > 2 or scalar @{$author;} < 1
ref $author ne "ARRAY" or scalar @{$author;} > 2
MC/DC0%0/3
ref $author ne "ARRAY" or scalar @{$author;} > 2 or scalar @{$author;} < 1
ref $author ne "ARRAY"
scalar @{$author;} > 2
scalar @{$author;} < 1
Truth table25%1/4
A or B or C
A= ref $author ne "ARRAY"B= scalar @{$author;} > 2C= scalar @{$author;} < 1
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 3 | (scalar @{$author} > 2) || | |||||||||||||||||||||||||||||||||||||||||
| 142 | 3 | (scalar @{$author} < 1) ) { | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 11 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 154 | __END__ | ||||||||||||||||||||||||||||||||||||||||||