| 1 | #============================================================================== | ||||||||||||||||||||||||||||
| 2 | # LibWeb::Class -- A base class for libweb modules. | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package LibWeb::Class; | ||||||||||||||||||||||||||||
| 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: Class.pm,v 1.4 2000/07/18 06:33:30 ckyc Exp $ | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #-############################# | ||||||||||||||||||||||||||||
| 26 | # Use standard library. | ||||||||||||||||||||||||||||
| 27 | 6 | require 5.004; | |||||||||||||||||||||||||||
| 28 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 6 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 6 | $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | #-############################# | ||||||||||||||||||||||||||||
| 34 | # Methods. | ||||||||||||||||||||||||||||
| 35 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 37 | 1 | ▶ | bless( {}, ref($class) || $class ); | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub DESTROY {} | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 7 | ▶ | sub rearrange { | ||||||||||||||||||||||||||
|
Subroutine
rearrange: called CC=10 SCAR=24.3
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | # | ||||||||||||||||||||||||||||
| 44 | # Stolen from CGI.pm and modified. | ||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||
| 46 | # Smart rearrangement of parameters to allow named parameter | ||||||||||||||||||||||||||||
| 47 | # calling. We do the rearrangement if: | ||||||||||||||||||||||||||||
| 48 | # 1. The first parameter begins with a - | ||||||||||||||||||||||||||||
| 49 | # | ||||||||||||||||||||||||||||
| 50 | 7 | my($self,$order,@param) = @_; | |||||||||||||||||||||||||||
| 51 | 7 | ▶ | return () unless @param; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | ▶ | if (ref($param[0]) eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | @param = %{$param[0]}; | |||||||||||||||||||||||||||
| 55 | } else { | ||||||||||||||||||||||||||||
| 56 | return @param | ||||||||||||||||||||||||||||
| 57 | 2 | ▶ | unless (defined($param[0]) && substr($param[0],0,1) eq '-'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $param[0] and substr($param[0], 0, 1) eq "-"
MC/DC0%0/2
defined $param[0] and substr($param[0], 0, 1) eq "-"
defined $param[0]
substr($param[0], 0, 1) eq "-"
Truth table33%1/3
A and B
A= defined $param[0]B= substr($param[0], 0, 1) eq "-"
| |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # map parameters into positional indices | ||||||||||||||||||||||||||||
| 61 | 2 | my ($i,%pos); | |||||||||||||||||||||||||||
| 62 | 2 | $i = 0; | |||||||||||||||||||||||||||
| 63 | 2 | foreach (@$order) { | |||||||||||||||||||||||||||
| 64 | 13 | ▶ | foreach (ref($_) eq 'ARRAY' ? @$_ : $_) { $pos{$_} = $i; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 13 | $i++; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 2 | my (@result); #leave out %leftover. | |||||||||||||||||||||||||||
| 69 | 2 | $#result = $#$order; #preextend | |||||||||||||||||||||||||||
| 70 | 2 | ▶ | while (@param) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 5 | my $key = uc(shift(@param)); #uc(shift(@param)); | |||||||||||||||||||||||||||
| 72 | 5 | $key =~ s/^\-//; | |||||||||||||||||||||||||||
| 73 | 5 | ▶ | $result[$pos{$key}] = shift(@param) if (exists $pos{$key}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | #} else { | ||||||||||||||||||||||||||||
| 75 | # $leftover{$key} = shift(@param); | ||||||||||||||||||||||||||||
| 76 | #} | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | #push (@result,$self->make_attributes(\%leftover)) if %leftover; | ||||||||||||||||||||||||||||
| 80 | 2 | return @result; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 6 | 1; | |||||||||||||||||||||||||||
| 84 | __DATA__ | ||||||||||||||||||||||||||||