File Coverage

blib/lib/LibWeb/Class.pm
Criterion Covered Total %
statement 25 28 89.2
branch 6 10 60.0
condition 2 6 33.3
subroutine 4 5 80.0
pod 1 2 50.0
total 38 51 74.5


line stmt bran cond sub pod time code
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             require 5.004;
28 6     6   1350 use strict;
  6         12  
  6         1628  
29 6     6   43 use vars qw($VERSION);
  6         14  
  6         2588  
30              
31             $VERSION = '0.02';
32              
33             #-#############################
34             # Methods.
35             sub new {
36 1     1 0 2 my $class = shift;
37 1   33     9 bless( {}, ref($class) || $class );
38             }
39              
40 0     0   0 sub DESTROY {}
41              
42             sub rearrange {
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 8     8 1 5237 my($self,$order,@param) = @_;
51 8 100       42 return () unless @param;
52              
53 2 50       6 if (ref($param[0]) eq 'HASH') {
54 0         0 @param = %{$param[0]};
  0         0  
55             } else {
56             return @param
57 2 50 33     143 unless (defined($param[0]) && substr($param[0],0,1) eq '-');
58             }
59              
60             # map parameters into positional indices
61 2         3 my ($i,%pos);
62 2         5 $i = 0;
63 2         6 foreach (@$order) {
64 13 50       27 foreach (ref($_) eq 'ARRAY' ? @$_ : $_) { $pos{$_} = $i; }
  13         115  
65 13         20 $i++;
66             }
67              
68 2         4 my (@result); #leave out %leftover.
69 2         10 $#result = $#$order; #preextend
70 2         8 while (@param) {
71 5         10 my $key = uc(shift(@param)); #uc(shift(@param));
72 5         19 $key =~ s/^\-//;
73 5 50       24 $result[$pos{$key}] = shift(@param) if (exists $pos{$key});
74             #} else {
75             # $leftover{$key} = shift(@param);
76             #}
77             }
78              
79             #push (@result,$self->make_attributes(\%leftover)) if %leftover;
80 2         16 return @result;
81             }
82              
83             1;
84             __DATA__