lib/PurpleWiki/Apache1Handler.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 58 CC 1 SCAR 6.9
CC
1
Cov
0%
handler
2.0
readFile
2.0
BEGIN
2.0
CRAP 2.0
1 # PurpleWiki::Apache1Handler.pm
2 # vi:ai:sw=4:ts=4:et:sm
3 #
4 # $Id: Apache1Handler.pm 465 2004-08-09 02:00:02Z 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::Apache1Handler;
32  
33 use strict;
34 use IO::File;
35 use PurpleWiki::Config;
36 use PurpleWiki::Parser::WikiText;
37 use Apache;
38 use Apache::Constants;
39 use Apache::URI;
40  
41 our $VERSION;
42 $VERSION = sprintf("%d", q$Id: Apache1Handler.pm 465 2004-08-09 02:00:02Z cdent $ =~ /\s(\d+)\s/);
43  
44 sub handler {
45 my $r = shift;
46  
47 $r->send_http_header("text/html");
48  
49 my $file = $r->filename();
50 my $url = Apache::URI->parse($r)->unparse();
51  
52 my $content = readFile($file);
53 my $CONFIG = $ENV{WIKIDB};
54 my $purpleConfig = new PurpleWiki::Config($CONFIG);
55 my $wikiParser = new PurpleWiki::Parser::WikiText();
56 my $wiki = $wikiParser->parse($content,
57 wikiword => 1,
58 url => $url,
59 );
60  
61 # select and load a template driver
62 my $templateDriver = $purpleConfig->TemplateDriver();
63 my $templateClass = "PurpleWiki::Template::$templateDriver";
64 eval "require $templateClass";
65 my $wikiTemplate = $templateClass->new;
66 $wikiTemplate->vars( body => $wiki->view('wikihtml',
67 wikiword => 1,
68 url => $url),
69 title => $wiki->title,
70 date => $wiki->date );
71 $r->print($wikiTemplate->process('handler'));
72  
73 return OK;
74  
75 }
76  
77 sub readFile {
78 my $file = shift;
79  
80 my $fh = new IO::File();
81 $fh->open($file) || die "unable to open $file: $!";
82 return join('', $fh->getlines);
83 }
84  
85  
86  
87 1;
88  
89 __END__