line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Param::Base; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
1939
|
use strict; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
256
|
|
4
|
7
|
|
|
7
|
|
97
|
use warnings; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
197
|
|
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
40
|
use Carp qw[]; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
387
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
BEGIN { |
9
|
|
|
|
|
|
|
|
10
|
7
|
|
|
7
|
|
130
|
my @abstract = qw[ new get set names remove ]; |
11
|
|
|
|
|
|
|
|
12
|
7
|
|
|
|
|
29
|
foreach my $abstract ( @abstract ) { |
13
|
|
|
|
|
|
|
|
14
|
7
|
|
|
7
|
|
37
|
no strict 'refs'; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
809
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
*$abstract = sub { |
17
|
6
|
50
|
|
6
|
|
14977
|
my $class = ref $_[0] ? ref shift : shift; |
18
|
6
|
|
|
|
|
1086
|
Carp::croak qq/Abstract method '$abstract' must be implemented in '$class'./; |
19
|
35
|
|
|
|
|
6400
|
}; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub add { |
24
|
12
|
|
|
12
|
1
|
34
|
my ( $self, $name, @add ) = @_; |
25
|
|
|
|
|
|
|
|
26
|
12
|
100
|
|
|
|
48
|
unless ( $self->has($name) ) { |
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
|
|
11
|
my $value; |
29
|
|
|
|
|
|
|
|
30
|
6
|
100
|
|
|
|
33
|
if ( @add == 1 ) { |
31
|
4
|
100
|
|
|
|
24
|
$value = ref $add[0] eq 'ARRAY' ? [ $add[0] ] : $add[0]; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
2
|
|
|
|
|
11
|
$value = \@add; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
6
|
|
|
|
|
32
|
return $self->set( $name => $value ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
6
|
|
|
|
|
27
|
my $value = $self->get($name); |
41
|
|
|
|
|
|
|
|
42
|
6
|
50
|
|
|
|
43
|
unless ( ref $value eq 'ARRAY' ) { |
43
|
0
|
|
|
|
|
0
|
$value = [ $value ]; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
6
|
|
|
|
|
10
|
push @{ $value }, @add; |
|
6
|
|
|
|
|
19
|
|
47
|
|
|
|
|
|
|
|
48
|
6
|
|
|
|
|
26
|
return $self->set( $name => $value ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub has { |
52
|
23
|
|
|
23
|
1
|
42
|
my ( $self, $name ) = @_; |
53
|
|
|
|
|
|
|
|
54
|
23
|
|
|
|
|
73
|
foreach ( $self->names ) { |
55
|
57
|
100
|
|
|
|
1379
|
return 1 if $_ eq $name; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
6
|
|
|
|
|
45
|
return 0; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub clear { |
62
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
6
|
foreach ( $self->names ) { |
65
|
2
|
|
|
|
|
15
|
$self->remove($_); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
10
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub count { |
72
|
2
|
|
|
2
|
1
|
8
|
return scalar shift->names; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub param { |
76
|
65
|
|
|
65
|
1
|
146
|
my ( $self, $name, @values ) = @_; |
77
|
|
|
|
|
|
|
|
78
|
65
|
100
|
|
|
|
211
|
if ( @_ == 1 ) { |
79
|
4
|
|
|
|
|
156
|
return $self->names; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
61
|
100
|
|
|
|
154
|
unless ( defined $name ) { |
83
|
4
|
100
|
|
|
|
31
|
return wantarray ? () : undef; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
57
|
100
|
|
|
|
145
|
if ( @_ == 2 ) { |
87
|
|
|
|
|
|
|
|
88
|
46
|
100
|
|
|
|
148
|
unless ( $self->has($name) ) { |
89
|
4
|
100
|
|
|
|
72
|
return wantarray ? () : undef; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
42
|
|
|
|
|
948
|
my $value = $self->get($name); |
93
|
|
|
|
|
|
|
|
94
|
42
|
100
|
|
|
|
161
|
if ( ref $value eq 'ARRAY' ) { |
95
|
24
|
100
|
|
|
|
78
|
return wantarray ? @{ $value } : $value->[0]; |
|
21
|
|
|
|
|
103
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else { |
98
|
18
|
100
|
|
|
|
103
|
return wantarray ? ( $value ) : $value; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
11
|
100
|
100
|
|
|
70
|
if ( @values == 1 && ! defined $values[0] ) { |
103
|
4
|
|
|
|
|
18
|
return $self->remove($name); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
7
|
100
|
|
|
|
51
|
return $self->set( $name => @values > 1 ? \@values : $values[0] ); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub scan { |
110
|
6
|
|
|
6
|
1
|
13
|
my ( $self, $callback ) = @_; |
111
|
|
|
|
|
|
|
|
112
|
6
|
|
|
|
|
33
|
foreach ( $self->names ) { |
113
|
20
|
|
|
|
|
64
|
&$callback( $_, $self->param($_) ); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
6
|
|
|
|
|
18
|
return 1; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub as_hash { |
120
|
6
|
|
|
6
|
1
|
18
|
my $self = shift; |
121
|
6
|
|
|
|
|
16
|
my %hash = (); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$self->scan( sub { |
124
|
20
|
100
|
|
20
|
|
91
|
$hash{ shift() } = @_ > 2 ? \@_ : $_[1]; |
125
|
6
|
|
|
|
|
58
|
}); |
126
|
|
|
|
|
|
|
|
127
|
6
|
100
|
|
|
|
74
|
return wantarray ? %hash : \%hash; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |