File Coverage

blib/lib/LibWeb/Core.pm
Criterion Covered Total %
statement 36 47 76.6
branch 14 26 53.8
condition 4 9 44.4
subroutine 6 7 85.7
pod 0 1 0.0
total 60 90 66.6


line stmt bran cond sub pod time code
1             #==============================================================================
2             # LibWeb::Core -- The core class for libweb modules.
3              
4             package LibWeb::Core;
5              
6             # Copyright (C) 2000 Colin Kong
7             #
8             # This program is free software; you can redistribute it and/or
9             # modify it under the terms of the GNU General Public License
10             # as published by the Free Software Foundation; either version 2
11             # of the License, or (at your option) any later version.
12             #
13             # This program is distributed in the hope that it will be useful,
14             # but WITHOUT ANY WARRANTY; without even the implied warranty of
15             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16             # GNU General Public License for more details.
17             #
18             # You should have received a copy of the GNU General Public License
19             # along with this program; if not, write to the Free Software
20             # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21             #=============================================================================
22              
23             # $Id: Core.pm,v 1.5 2000/07/18 06:33:30 ckyc Exp $
24              
25             #-###############################
26             # Use standard library.
27 4     4   15231 use SelfLoader;
  4         111264  
  4         296  
28 4     4   58 use Carp;
  4         9  
  4         226  
29 4     4   21 use strict;
  4         7  
  4         123  
30 4     4   23 use vars qw($VERSION @ISA %RC $OS);
  4         5  
  4         3929  
31             ##require Config
32              
33             #-###############################
34             # Use custom library.
35             require LibWeb::Class;
36             ##require LibWeb::HTML::Error;
37             ##require LibWeb::Crypt;
38             ##require Mail::Sendmail;
39              
40             #-###############################
41             # Version.
42             $VERSION = '0.02';
43              
44             #-###############################
45             # Inheritance.
46             @ISA = qw(LibWeb::Class);
47              
48             #-###############################
49             # Methods.
50             sub new {
51             #
52             # Params: $class [, $rc_file, $error_object]
53             #
54             # - $class is the class/package name of this package, be it a string
55             # or a reference.
56             # - $rc_file is the absolute path to the rc file for LibWeb.
57             # - $error_object is a reference to a perl object for printing out
58             # error/help message to users when error occurs.
59             #
60             # Usage: No, you don't use LibWeb::Core directly in client codes.
61             #
62 4     4 0 426 my ($class, $self, %rc);
63 4         9 $class = shift;
64              
65             # Read the rc file if haven't done so in this CGI session.
66             # Read rc and take care of portability issues only once for sake
67             # of performance! But the ``%rc = %RC'' is still an expensive way
68             # to do that. Any better approach?
69 4 100       20 if (%RC) {
70 1         52 %rc = %RC;
71 1   33     35 bless(\%rc, ref($class) || $class);
72             } else {
73 3         7 eval { $self = do "$_[0]"; };
  3         2296  
74 3 50       27 croak "Couldn't read rc: $@\n" if ($@);
75 3   66     19 $self->{HHTML} = $_[1] || eval { require LibWeb::HTML::Error; LibWeb::HTML::Error->new(); };
76 3 50       17 croak "LibWeb::Core::new(): No HTML Error object detected!" unless $self->{HHTML};
77 3         14 _make_portable($self);
78 3         4 %RC = %{ $self };
  3         100  
79 3   33     42 bless($self, ref($class) || $class);
80             }
81             }
82              
83 0     0   0 sub DESTROY {}
84              
85             sub _make_portable {
86             #
87             # Some portability tricks stolen from CGI.pm 2.66.
88             #
89 3     3   6 my $self = shift;
90             # FIGURE OUT THE OS WE'RE RUNNING UNDER
91             # Some systems support the $^O variable. If not
92             # available then require() the Config library
93 3 50       10 unless ($OS) {
94 3 50       15 unless ($OS = $^O) {
95 0         0 require Config;
96 0         0 $OS = $Config::Config{'osname'};
97             }
98             }
99 3 50       58 if ($OS=~/Win/i) {
    50          
    50          
    50          
    50          
    50          
100 0         0 $OS = 'WINDOWS';
101             } elsif ($OS=~/vms/i) {
102 0         0 $OS = 'VMS';
103             } elsif ($OS=~/bsdos/i) {
104 0         0 $OS = 'UNIX';
105             } elsif ($OS=~/dos/i) {
106 0         0 $OS = 'DOS';
107             } elsif ($OS=~/^MacOS$/i) {
108 0         0 $OS = 'MACINTOSH';
109             } elsif ($OS=~/os2/i) {
110 0         0 $OS = 'OS2';
111             } else {
112 3         7 $OS = 'UNIX';
113             }
114 3         32 $self->{OS} = $OS;
115             # The path separator is a slash, backslash or semicolon, depending
116             # on the platform.
117 3         30 $self->{PATH_SEP} = {
118             UNIX=>'/', OS2=>'\\', WINDOWS=>'\\', DOS=>'\\',
119             MACINTOSH=>':', VMS=>'/'
120             }->{$OS};
121             # Define the CRLF sequence. I can't use a simple "\r\n" because the meaning
122             # of "\n" is different on different OS's (sometimes it generates CRLF, sometimes
123             # LF and sometimes CR). The most popular VMS web server doesn't accept CRLF --
124             # instead it wants a LR. EBCDIC machines don't use ASCII, so \015\012 means
125             # something different. I find this all really annoying. -- Lincoln.
126 3         14 my $EBCDIC = "\t" ne "\011";
127 3 50       12 if ($OS eq 'VMS') {
    50          
128 0         0 $self->{CRLF} = "\n";
129             } elsif ($EBCDIC) {
130 0         0 $self->{CRLF} = "\r\n";
131             } else {
132 3         21 $self->{CRLF} = "\015\012";
133             }
134             }
135              
136              
137             # Selfloading methods declaration.
138             sub LibWeb::Core::_get_auth_info_from_cookie_for_admin ;
139             sub LibWeb::Core::_log_fatal ;
140             sub LibWeb::Core::alert_admin ;
141             sub LibWeb::Core::debug_print ;
142             sub LibWeb::Core::fatal ;
143             sub LibWeb::Core::sanitize ;
144             sub LibWeb::Core::send_cookie ;
145             sub LibWeb::Core::send_mail ;
146             1;
147             __DATA__