blib/lib/LibWeb/Core.pm

filter: Statementstmt 80.7% 42 / 52 Branchbran 53.8% 14 / 26 Conditioncond 44.4% 4 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 1 totaltotal 65.3% 66 / 101 CC 17 SCAR 27.1
CC
17
Cov
69%
_make_portable
26.1
new
7.6
BEGIN
1.0
CRAP 15.0
« blib/lib/LibWeb/Database.pm ↑ Summary blib/lib/LibWeb/Digest.pm »
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 ▶use SelfLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 4 ▶use vars qw($VERSION @ISA %RC $OS);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 ##require Config
32  
33 #-###############################
34 # Use custom library.
35 4 require LibWeb::Class;
36 ##require LibWeb::HTML::Error;
37 ##require LibWeb::Crypt;
38 ##require Mail::Sendmail;
39  
40 #-###############################
41 # Version.
42 4 $VERSION = '0.02';
43  
44 #-###############################
45 # Inheritance.
46 4 @ISA = qw(LibWeb::Class);
47  
48 #-###############################
49 # Methods.
50 4 ▶sub new {
Subroutine new: called CC=7 SCAR=20.2
Pod undocumented
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 my ($class, $self, %rc);
63 4 $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 ▶ if (%RC) {
Branch: 1 branch
BranchTrueFalseTotal
if (%LibWeb::Core::RC) { } 1 3 4
70 1 %rc = %RC;
71 1 ▶ bless(\%rc, ref($class) || $class);
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
72 } else {
73 3 eval { $self = do "$_[0]"; };
74 3 ▶ croak "Couldn't read rc: $@\n" if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
75 3 ▶ $self->{HHTML} = $_[1] || eval { require LibWeb::HTML::Error; LibWeb::HTML::Error->new(); };
Condition66%2/3
$_[1] || eval { do { require LibWeb::HTML::Error; 'LibWeb::HTML::Error'->new } }
l!l&&r!l&&!r
120
MC/DC0%0/2
$_[1] || eval { do { require LibWeb::HTML::Error; 'LibWeb::HTML::Error'->new } }
$_[1] eval { do { require LibWeb::HTML::Error; 'LibWeb::HTML::Error'->new } }
Truth table66%2/3
A || B
A= $_[1]B= eval { do { require LibWeb::HTML::Error; 'LibWeb::HTML::Error'->new } }
ABresult
1X1
011
000
76 3 ▶ croak "LibWeb::Core::new(): No HTML Error object detected!" unless $self->{HHTML};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"HHTML"} 0 3 3
77 3 _make_portable($self);
78 3 %RC = %{ $self };
79 3 ▶ bless($self, ref($class) || $class);
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
030
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
80 }
81 }
82  
83 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
84  
85 3 ▶sub _make_portable {
Subroutine _make_portable: called CC=11 SCAR=32.6
86 #
87 # Some portability tricks stolen from CGI.pm 2.66.
88 #
89 3 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 ▶ unless ($OS) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($LibWeb::Core::OS) 3 0 3
94 3 ▶ unless ($OS = $^O) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($LibWeb::Core::OS = $^O) 0 3 3
95 0 require Config;
96 0 $OS = $Config::Config{'osname'};
97 }
98 }
99 3 ▶ if ($OS=~/Win/i) {
Branch: 6 branches
BranchTrueFalseTotal
if ($LibWeb::Core::OS =~ /Win/i) { } 0 3 3
elsif ($LibWeb::Core::OS =~ /vms/i) { } 0 3 3
elsif ($LibWeb::Core::OS =~ /bsdos/i) { } 0 3 3
elsif ($LibWeb::Core::OS =~ /dos/i) { } 0 3 3
elsif ($LibWeb::Core::OS =~ /^MacOS$/i) { } 0 3 3
elsif ($LibWeb::Core::OS =~ /os2/i) { } 0 3 3
100 0 $OS = 'WINDOWS';
101 } elsif ($OS=~/vms/i) {
102 0 $OS = 'VMS';
103 } elsif ($OS=~/bsdos/i) {
104 0 $OS = 'UNIX';
105 } elsif ($OS=~/dos/i) {
106 0 $OS = 'DOS';
107 } elsif ($OS=~/^MacOS$/i) {
108 0 $OS = 'MACINTOSH';
109 } elsif ($OS=~/os2/i) {
110 0 $OS = 'OS2';
111 } else {
112 3 $OS = 'UNIX';
113 }
114 3 $self->{OS} = $OS;
115 # The path separator is a slash, backslash or semicolon, depending
116 # on the platform.
117 $self->{PATH_SEP} = {
118 UNIX=>'/', OS2=>'\\', WINDOWS=>'\\', DOS=>'\\',
119 MACINTOSH=>':', VMS=>'/'
120 3 }->{$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 my $EBCDIC = "\t" ne "\011";
127 3 ▶ if ($OS eq 'VMS') {
Branch: 2 branches
BranchTrueFalseTotal
if ($LibWeb::Core::OS eq 'VMS') { } 0 3 3
elsif ($EBCDIC) { } 0 3 3
128 0 $self->{CRLF} = "\n";
129 } elsif ($EBCDIC) {
130 0 $self->{CRLF} = "\r\n";
131 } else {
132 3 $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 4 1;
147 __DATA__
« blib/lib/LibWeb/Database.pm ↑ Summary blib/lib/LibWeb/Digest.pm »