line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenInteract2::ParamContainer; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: ParamContainer.pm,v 1.2 2005/02/13 20:19:10 lachoy Exp $ |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
38
|
|
6
|
1
|
|
|
1
|
|
542
|
use OpenInteract2::Exception qw( oi_error ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$OpenInteract2::ParamContainer::VERSION = sprintf( "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/ ); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub get_skip_params { return () } |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub param { |
13
|
|
|
|
|
|
|
my ( $self, $key, $value ) = @_; |
14
|
|
|
|
|
|
|
$self->{params} ||= {}; |
15
|
|
|
|
|
|
|
return \%{ $self->{params} } unless ( $key ); |
16
|
|
|
|
|
|
|
if ( defined $value ) { |
17
|
|
|
|
|
|
|
$self->{params}{ $key } = $value; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
if ( ref $self->{params}{ $key } eq 'ARRAY' ) { |
20
|
|
|
|
|
|
|
return ( wantarray ) |
21
|
|
|
|
|
|
|
? @{ $self->{params}{ $key } } |
22
|
|
|
|
|
|
|
: $self->{params}{ $key }; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
return ( wantarray ) |
25
|
|
|
|
|
|
|
? ( $self->{params}{ $key } ) |
26
|
|
|
|
|
|
|
: $self->{params}{ $key }; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub param_add { |
30
|
|
|
|
|
|
|
my ( $self, $key, @values ) = @_; |
31
|
|
|
|
|
|
|
return undef unless ( $key ); |
32
|
|
|
|
|
|
|
$self->{params} ||= {}; |
33
|
|
|
|
|
|
|
my $num_values = scalar @values; |
34
|
|
|
|
|
|
|
return $self->{params}{ $key } unless ( scalar @values ); |
35
|
|
|
|
|
|
|
if ( my $existing = $self->{params}{ $key } ) { |
36
|
|
|
|
|
|
|
my $typeof = ref( $existing ); |
37
|
|
|
|
|
|
|
if ( $typeof eq 'ARRAY' ) { |
38
|
|
|
|
|
|
|
push @{ $self->{params}{ $key } }, @values; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
elsif ( ! $typeof ) { |
41
|
|
|
|
|
|
|
$self->{params}{ $key } = [ $existing, @values ]; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
|
|
|
|
|
|
oi_error "Cannot add $num_values values to parameter '$key' ", |
45
|
|
|
|
|
|
|
"since the parameter is defined as a '$typeof' to ", |
46
|
|
|
|
|
|
|
"which I cannot reliably add values."; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
|
|
|
|
|
|
if ( $num_values == 1 ) { |
51
|
|
|
|
|
|
|
$self->{params}{ $key } = $values[0]; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
|
|
|
|
|
|
$self->{params}{ $key } = [ @values ]; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
return $self->param( $key ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub param_clear { |
61
|
|
|
|
|
|
|
my ( $self, $key ) = @_; |
62
|
|
|
|
|
|
|
$self->{params} ||= {}; |
63
|
|
|
|
|
|
|
return delete $self->{params}{ $key }; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub param_assign { |
67
|
|
|
|
|
|
|
my ( $self, $params ) = @_; |
68
|
|
|
|
|
|
|
return unless ( ref $params eq 'HASH' ); |
69
|
|
|
|
|
|
|
my %skip_params = $self->get_skip_params(); |
70
|
|
|
|
|
|
|
while ( my ( $key, $value ) = each %{ $params } ) { |
71
|
|
|
|
|
|
|
next if ( $skip_params{ $key } ); |
72
|
|
|
|
|
|
|
next unless ( defined $value ); |
73
|
|
|
|
|
|
|
$self->param( $key, $value ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
return $self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |