line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Utils; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
77434
|
use base qw(Exporter); |
|
6
|
|
|
|
|
40
|
|
|
6
|
|
|
|
|
903
|
|
4
|
6
|
|
|
6
|
|
42
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
168
|
|
5
|
6
|
|
|
6
|
|
30
|
use warnings; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
230
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
3011
|
use Error::Pure qw(err); |
|
6
|
|
|
|
|
72159
|
|
|
6
|
|
|
|
|
162
|
|
8
|
6
|
|
|
6
|
|
445
|
use List::Util qw(any); |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
814
|
|
9
|
6
|
|
|
6
|
|
39
|
use Readonly; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
3074
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Constants. |
12
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(set_params set_params_pub set_split_params |
13
|
|
|
|
|
|
|
split_params); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Version. |
16
|
|
|
|
|
|
|
our $VERSION = 0.14; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Set parameters to user values. |
19
|
|
|
|
|
|
|
sub set_params { |
20
|
2
|
|
|
2
|
1
|
938
|
my ($self, @params) = @_; |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
8
|
while (@params) { |
23
|
2
|
|
|
|
|
5
|
my $key = shift @params; |
24
|
2
|
|
|
|
|
3
|
my $val = shift @params; |
25
|
2
|
100
|
|
|
|
8
|
if (! exists $self->{$key}) { |
26
|
1
|
|
|
|
|
10
|
err "Unknown parameter '$key'."; |
27
|
|
|
|
|
|
|
} |
28
|
1
|
|
|
|
|
3
|
$self->{$key} = $val; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
3
|
return; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Set parameters to user values - public variables. |
35
|
|
|
|
|
|
|
sub set_params_pub { |
36
|
3
|
|
|
3
|
1
|
3465
|
my ($self, @params) = @_; |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
10
|
while (@params) { |
39
|
4
|
|
|
|
|
9
|
my $key = shift @params; |
40
|
4
|
|
|
|
|
11
|
my $val = shift @params; |
41
|
4
|
100
|
|
|
|
17
|
if ($key =~ m/^_/ms) { |
42
|
1
|
|
|
|
|
4
|
next; |
43
|
|
|
|
|
|
|
} |
44
|
3
|
100
|
|
|
|
9
|
if (! exists $self->{$key}) { |
45
|
1
|
|
|
|
|
10
|
err "Unknown parameter '$key'."; |
46
|
|
|
|
|
|
|
} |
47
|
2
|
|
|
|
|
7
|
$self->{$key} = $val; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
5
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Set params for object and other returns. |
54
|
|
|
|
|
|
|
sub set_split_params { |
55
|
2
|
|
|
2
|
1
|
1490
|
my ($self, @params) = @_; |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
4
|
my @other_params; |
58
|
2
|
|
|
|
|
8
|
while (@params) { |
59
|
3
|
|
|
|
|
7
|
my $key = shift @params; |
60
|
3
|
|
|
|
|
4
|
my $val = shift @params; |
61
|
3
|
100
|
|
|
|
12
|
if (! exists $self->{$key}) { |
62
|
1
|
|
|
|
|
8
|
push @other_params, $key, $val; |
63
|
|
|
|
|
|
|
} else { |
64
|
2
|
|
|
|
|
6
|
$self->{$key} = $val; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
2
|
|
|
|
|
7
|
return @other_params; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Split params to object and others. |
72
|
|
|
|
|
|
|
sub split_params { |
73
|
2
|
|
|
2
|
1
|
1409
|
my ($object_keys_ar, @params) = @_; |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
3
|
my @object_params; |
76
|
|
|
|
|
|
|
my @other_params; |
77
|
2
|
|
|
|
|
7
|
while (@params) { |
78
|
3
|
|
|
|
|
7
|
my $key = shift @params; |
79
|
3
|
|
|
|
|
5
|
my $val = shift @params; |
80
|
3
|
100
|
|
2
|
|
12
|
if (any { $_ eq $key } @{$object_keys_ar}) { |
|
2
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
16
|
|
81
|
1
|
|
|
|
|
5
|
push @object_params, $key, $val; |
82
|
|
|
|
|
|
|
} else { |
83
|
2
|
|
|
|
|
11
|
push @other_params, $key, $val; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
2
|
|
|
|
|
9
|
return (\@object_params, \@other_params); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |