line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Utils; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
62448
|
use base qw(Exporter); |
|
6
|
|
|
|
|
30
|
|
|
6
|
|
|
|
|
730
|
|
4
|
6
|
|
|
6
|
|
35
|
use strict; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
154
|
|
5
|
6
|
|
|
6
|
|
42
|
use warnings; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
210
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
2532
|
use Error::Pure qw(err); |
|
6
|
|
|
|
|
59154
|
|
|
6
|
|
|
|
|
109
|
|
8
|
6
|
|
|
6
|
|
3304
|
use List::MoreUtils qw(any); |
|
6
|
|
|
|
|
77773
|
|
|
6
|
|
|
|
|
30
|
|
9
|
6
|
|
|
6
|
|
5275
|
use Readonly; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
2571
|
|
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.12; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Set parameters to user values. |
19
|
|
|
|
|
|
|
sub set_params { |
20
|
2
|
|
|
2
|
1
|
683
|
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
|
|
|
|
6
|
if (! exists $self->{$key}) { |
26
|
1
|
|
|
|
|
9
|
err "Unknown parameter '$key'."; |
27
|
|
|
|
|
|
|
} |
28
|
1
|
|
|
|
|
4
|
$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
|
3296
|
my ($self, @params) = @_; |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
7
|
while (@params) { |
39
|
4
|
|
|
|
|
9
|
my $key = shift @params; |
40
|
4
|
|
|
|
|
5
|
my $val = shift @params; |
41
|
4
|
100
|
|
|
|
13
|
if ($key =~ m/^_/ms) { |
42
|
1
|
|
|
|
|
3
|
next; |
43
|
|
|
|
|
|
|
} |
44
|
3
|
100
|
|
|
|
8
|
if (! exists $self->{$key}) { |
45
|
1
|
|
|
|
|
8
|
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
|
1239
|
my ($self, @params) = @_; |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
3
|
my @other_params; |
58
|
2
|
|
|
|
|
6
|
while (@params) { |
59
|
3
|
|
|
|
|
6
|
my $key = shift @params; |
60
|
3
|
|
|
|
|
5
|
my $val = shift @params; |
61
|
3
|
100
|
|
|
|
7
|
if (! exists $self->{$key}) { |
62
|
1
|
|
|
|
|
4
|
push @other_params, $key, $val; |
63
|
|
|
|
|
|
|
} else { |
64
|
2
|
|
|
|
|
6
|
$self->{$key} = $val; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
2
|
|
|
|
|
6
|
return @other_params; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Split params to object and others. |
72
|
|
|
|
|
|
|
sub split_params { |
73
|
2
|
|
|
2
|
1
|
1286
|
my ($object_keys_ar, @params) = @_; |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
5
|
my @object_params; |
76
|
|
|
|
|
|
|
my @other_params; |
77
|
2
|
|
|
|
|
5
|
while (@params) { |
78
|
3
|
|
|
|
|
5
|
my $key = shift @params; |
79
|
3
|
|
|
|
|
4
|
my $val = shift @params; |
80
|
3
|
100
|
|
2
|
|
9
|
if (any { $_ eq $key } @{$object_keys_ar}) { |
|
2
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
14
|
|
81
|
1
|
|
|
|
|
5
|
push @object_params, $key, $val; |
82
|
|
|
|
|
|
|
} else { |
83
|
2
|
|
|
|
|
9
|
push @other_params, $key, $val; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
2
|
|
|
|
|
8
|
return (\@object_params, \@other_params); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |