line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Utils; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
63232
|
use base qw(Exporter); |
|
6
|
|
|
|
|
29
|
|
|
6
|
|
|
|
|
615
|
|
4
|
6
|
|
|
6
|
|
32
|
use strict; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
150
|
|
5
|
6
|
|
|
6
|
|
32
|
use warnings; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
179
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
2206
|
use Error::Pure qw(err); |
|
6
|
|
|
|
|
55347
|
|
|
6
|
|
|
|
|
137
|
|
8
|
6
|
|
|
6
|
|
3317
|
use List::MoreUtils qw(any); |
|
6
|
|
|
|
|
71085
|
|
|
6
|
|
|
|
|
36
|
|
9
|
6
|
|
|
6
|
|
4813
|
use Readonly; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
2391
|
|
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.11; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Set parameters to user values. |
19
|
|
|
|
|
|
|
sub set_params { |
20
|
2
|
|
|
2
|
1
|
720
|
my ($self, @params) = @_; |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
6
|
while (@params) { |
23
|
2
|
|
|
|
|
4
|
my $key = shift @params; |
24
|
2
|
|
|
|
|
3
|
my $val = shift @params; |
25
|
2
|
100
|
|
|
|
5
|
if (! exists $self->{$key}) { |
26
|
1
|
|
|
|
|
9
|
err "Unknown parameter '$key'."; |
27
|
|
|
|
|
|
|
} |
28
|
1
|
|
|
|
|
3
|
$self->{$key} = $val; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
2
|
return; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Set parameters to user values - public variables. |
35
|
|
|
|
|
|
|
sub set_params_pub { |
36
|
3
|
|
|
3
|
1
|
4500
|
my ($self, @params) = @_; |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
8
|
while (@params) { |
39
|
4
|
|
|
|
|
5
|
my $key = shift @params; |
40
|
4
|
|
|
|
|
5
|
my $val = shift @params; |
41
|
4
|
100
|
|
|
|
12
|
if ($key =~ m/^_/ms) { |
42
|
1
|
|
|
|
|
4
|
next; |
43
|
|
|
|
|
|
|
} |
44
|
3
|
100
|
|
|
|
6
|
if (! exists $self->{$key}) { |
45
|
1
|
|
|
|
|
7
|
err "Unknown parameter '$key'."; |
46
|
|
|
|
|
|
|
} |
47
|
2
|
|
|
|
|
5
|
$self->{$key} = $val; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
4
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Set params for object and other returns. |
54
|
|
|
|
|
|
|
sub set_split_params { |
55
|
2
|
|
|
2
|
1
|
1170
|
my ($self, @params) = @_; |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
4
|
my @other_params; |
58
|
2
|
|
|
|
|
5
|
while (@params) { |
59
|
3
|
|
|
|
|
4
|
my $key = shift @params; |
60
|
3
|
|
|
|
|
5
|
my $val = shift @params; |
61
|
3
|
100
|
|
|
|
7
|
if (! exists $self->{$key}) { |
62
|
1
|
|
|
|
|
3
|
push @other_params, $key, $val; |
63
|
|
|
|
|
|
|
} else { |
64
|
2
|
|
|
|
|
5
|
$self->{$key} = $val; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
2
|
|
|
|
|
5
|
return @other_params; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Split params to object and others. |
72
|
|
|
|
|
|
|
sub split_params { |
73
|
2
|
|
|
2
|
1
|
968
|
my ($object_keys_ar, @params) = @_; |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
4
|
my @object_params; |
76
|
|
|
|
|
|
|
my @other_params; |
77
|
2
|
|
|
|
|
4
|
while (@params) { |
78
|
3
|
|
|
|
|
5
|
my $key = shift @params; |
79
|
3
|
|
|
|
|
4
|
my $val = shift @params; |
80
|
3
|
100
|
|
2
|
|
8
|
if (any { $_ eq $key } @{$object_keys_ar}) { |
|
2
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
10
|
|
81
|
1
|
|
|
|
|
3
|
push @object_params, $key, $val; |
82
|
|
|
|
|
|
|
} else { |
83
|
2
|
|
|
|
|
9
|
push @other_params, $key, $val; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
2
|
|
|
|
|
6
|
return (\@object_params, \@other_params); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |