| 1 | # PurpleWiki::Singleton.pm | ||||||||||||||||||||||||||||
| 2 | # vi:ai:sm:et:sw=4:ts=4 | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # $Id$ | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # Copyright (c) Matthew O'Connor 2004. 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::Singleton; | ||||||||||||||||||||||||||||
| 32 | 18 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 18 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 18 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | ######## Package Globals ######## | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 18 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 18 | $VERSION = "0.9.1"; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | ######## Public Class Methods ######## | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 0 | croak "PurpleWiki::Singleton can not be instantiated."; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | sub instance { | ||||||||||||||||||||||||||
|
Subroutine
instance: called CC=5 SCAR=19.8
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 50 | 2 | ▶ | croak "instance() is a class method." if ref $class or not $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $class or not $class
MC/DC0%0/2
ref $class or not $class
ref $class
not $class
Truth table33%1/3
A or not(B)
A= ref $classB= not $class
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 2 | ▶ | if ($ENV{MOD_PERL}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | require mod_perl; | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | ($mod_perl::VERSION >= 1.99) ? require Apache::compat : require Apache; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | return Apache->request->pnotes("purplewiki_singleton_$class"); | |||||||||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||||||||
| 57 | 18 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 58 | 2 | my $classGlobal = "$class\::_singletonObjectInstance"; | |||||||||||||||||||||||||||
| 59 | 2 | return $$classGlobal; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | ▶ | sub setInstance { | ||||||||||||||||||||||||||
|
Subroutine
setInstance: called CC=5 SCAR=19.8
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 2 | my ($class, $instance) = @_; | |||||||||||||||||||||||||||
| 65 | 2 | ▶ | croak "setInstance() is a class method." if ref $class or not $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $class or not $class
MC/DC0%0/2
ref $class or not $class
ref $class
not $class
Truth table33%1/3
A or not(B)
A= ref $classB= not $class
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 2 | ▶ | if ($ENV{MOD_PERL}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | require mod_perl; | |||||||||||||||||||||||||||
| 69 | 0 | ▶ | ($mod_perl::VERSION >= 1.99) ? require Apache::compat : require Apache; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | Apache->request->pnotes("purplewiki_singleton_$class" => $instance); | |||||||||||||||||||||||||||
| 71 | } else { | ||||||||||||||||||||||||||||
| 72 | 18 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 73 | 2 | my $classGlobal = "$class\::_singletonObjectInstance"; | |||||||||||||||||||||||||||
| 74 | 2 | $$classGlobal = $instance; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 18 | 1; | |||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||