line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::groups ; |
2
|
|
|
|
|
|
|
$VERSION = 2.41 ; |
3
|
5
|
|
|
5
|
|
63947
|
use 5.006_001 ; |
|
5
|
|
|
|
|
24
|
|
4
|
5
|
|
|
5
|
|
21
|
use strict ; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
107
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# This file uses the "Perlish" coding style |
7
|
|
|
|
|
|
|
# please read http://perl.4pro.net/perlish_coding_style.html |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
; use Class::props |
10
|
5
|
|
|
5
|
|
1506
|
; our @ISA = qw| Class::props | |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
23
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
; use Carp |
13
|
5
|
|
|
5
|
|
40
|
; $Carp::Internal{+__PACKAGE__}++ |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
958
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
; sub import |
16
|
14
|
|
|
14
|
|
2126
|
{ my $tool = shift |
17
|
14
|
|
|
|
|
43
|
; $tool->add_to(scalar caller, @_) |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
; sub add_to |
21
|
14
|
|
|
14
|
1
|
29
|
{ my ( $tool, $pkg, @args ) = @_ |
22
|
14
|
|
|
|
|
137
|
; foreach my $group ( @args ) |
23
|
11
|
50
|
|
|
|
33
|
{ $group = { name => $group } |
24
|
|
|
|
|
|
|
unless ref $group eq 'HASH' |
25
|
|
|
|
|
|
|
; $$group{name} = [ $$group{name} ] |
26
|
11
|
50
|
|
|
|
36
|
unless ref $$group{name} eq 'ARRAY' |
27
|
11
|
|
|
|
|
15
|
; foreach my $n ( @{$$group{name}} ) |
|
11
|
|
|
|
|
21
|
|
28
|
11
|
100
|
100
|
|
|
43
|
{ if ( not(defined $$group{no_strict}) |
29
|
|
|
|
|
|
|
&& not(defined $$group{props}) |
30
|
|
|
|
|
|
|
) |
31
|
1
|
|
|
|
|
1
|
{ $$group{no_strict} = 1 |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
; my @group_props |
34
|
11
|
|
|
|
|
16
|
; foreach my $prop ( @{$$group{props}} ) |
|
11
|
|
|
|
|
12
|
|
|
11
|
|
|
|
|
17
|
|
35
|
11
|
|
|
|
|
38
|
{ $prop = $tool->_init_prop_param( $prop ) |
36
|
11
|
|
|
|
|
14
|
; push @group_props, @{$$prop{name}} |
|
11
|
|
|
|
|
20
|
|
37
|
11
|
|
|
|
|
24
|
; $$prop{group} = $n |
38
|
11
|
|
|
|
|
30
|
; $tool->_add_prop($pkg, $prop ) |
39
|
|
|
|
|
|
|
} |
40
|
5
|
|
|
|
|
2999
|
; no strict 'refs' |
41
|
5
|
|
|
5
|
|
32
|
; my $init |
|
5
|
|
|
|
|
6
|
|
|
11
|
|
|
|
|
14
|
|
42
|
11
|
100
|
|
|
|
30
|
; if ( @group_props ) |
43
|
10
|
|
|
|
|
15
|
{ ${$tool.'::PROPS'}{$pkg}{$n} = \@group_props |
|
10
|
|
|
|
|
44
|
|
44
|
|
|
|
|
|
|
; $init = sub |
45
|
19
|
|
|
19
|
|
25
|
{ foreach my $p ( @{ ${$tool.'::PROPS'} |
|
19
|
|
|
|
|
81
|
|
46
|
|
|
|
|
|
|
{$_[1]} |
47
|
19
|
|
|
|
|
21
|
{$n} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
) |
50
|
35
|
|
|
|
|
144
|
{ my $dummy = $_[0]->$p |
51
|
|
|
|
|
|
|
} |
52
|
19
|
|
|
|
|
25
|
; foreach my $c ( @{$_[1].'::ISA'} ) |
|
19
|
|
|
|
|
69
|
|
53
|
9
|
|
|
|
|
27
|
{ $init->($_[0], $c) |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
10
|
|
|
|
|
31
|
} |
57
|
11
|
|
|
|
|
5333
|
; *{$pkg.'::'.$n} |
58
|
|
|
|
|
|
|
= sub |
59
|
0
|
|
|
|
|
0
|
{ &{$$group{pre_process}} if defined $$group{pre_process} |
60
|
40
|
50
|
|
40
|
|
202
|
; my $s = shift |
|
40
|
|
|
|
|
75
|
|
61
|
|
|
|
|
|
|
; my $hash |
62
|
15
|
|
66
|
|
|
95
|
= $tool =~ /^Class/ ? \%{(ref $s||$s).'::'.$n} # class |
63
|
12
|
|
|
|
|
39
|
: $tool =~ /^Package/ ? \%{$pkg.'::'.$n} # package |
64
|
40
|
100
|
100
|
|
|
166
|
: ( $$s{$n} ||= {} ) # object |
|
|
100
|
|
|
|
|
|
65
|
40
|
100
|
100
|
|
|
107
|
; if ( ( my $def = $$group{default} ) |
66
|
|
|
|
|
|
|
&& not keys %$hash |
67
|
|
|
|
|
|
|
) |
68
|
2
|
|
33
|
|
|
13
|
{ my $dprops |
69
|
|
|
|
|
|
|
= ref $def eq 'HASH' && $def |
70
|
|
|
|
|
|
|
|| (ref $def eq 'CODE' || not ref $def) && $s->$def() |
71
|
2
|
50
|
|
|
|
7
|
; ref $dprops eq 'HASH' or croak |
72
|
|
|
|
|
|
|
qq(Invalid "default" option for "$$group{name}[0]", died) |
73
|
2
|
|
|
|
|
31
|
; %$hash = %$dprops |
74
|
|
|
|
|
|
|
} |
75
|
40
|
100
|
|
|
|
88
|
; if ($init) |
76
|
10
|
|
66
|
|
|
40
|
{ $init->($s, ref($s)||$s) # init defaults |
77
|
10
|
|
|
|
|
56
|
; undef $init |
78
|
|
|
|
|
|
|
} |
79
|
40
|
|
|
|
|
46
|
; my $data |
80
|
40
|
100
|
|
|
|
108
|
; if ( @_ ) |
81
|
6
|
50
|
|
|
|
45
|
{ if ( ref $_[0] eq 'HASH' ) # set |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
82
|
0
|
|
|
|
|
0
|
{ $data = $_[0] |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
elsif ( @_ == 1 ) # get |
85
|
|
|
|
|
|
|
{ my @val |
86
|
2
|
100
|
|
|
|
3
|
; my @pro = ref $_[0] eq 'ARRAY' ? @{$_[0]} : $_[0] |
|
2
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
4
|
|
87
|
2
|
|
|
|
|
4
|
; foreach my $p ( @pro ) |
88
|
5
|
100
|
100
|
|
|
71
|
{ if ( my $m = $s->can($p) |
89
|
|
|
|
|
|
|
and grep /^$p$/, @group_props |
90
|
|
|
|
|
|
|
) |
91
|
2
|
|
|
|
|
6
|
{ push @val, $s->$m |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
else |
94
|
3
|
50
|
|
|
|
8
|
{ if ( $$group{no_strict} ) |
95
|
3
|
|
|
|
|
9
|
{ push @val, $$hash{$p} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else |
98
|
0
|
|
|
|
|
0
|
{ croak qq(No such property "$p", died) |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
2
|
100
|
|
|
|
11
|
; return wantarray ? @val : $val[0] |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
elsif ( not ( @_ % 2 ) ) # set |
105
|
4
|
|
|
|
|
60
|
{ $data = { @_ } |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
else |
108
|
0
|
|
|
|
|
0
|
{ croak qq(Odd number of arguments for "$n", died) |
109
|
|
|
|
|
|
|
} |
110
|
4
|
|
|
|
|
30
|
; while ( my ($p, $v) = each %$data ) # set |
111
|
7
|
100
|
66
|
|
|
141
|
{ if ( my $m = $s->can($p) |
112
|
|
|
|
|
|
|
and grep /^$p$/, @group_props |
113
|
|
|
|
|
|
|
) |
114
|
6
|
|
|
|
|
21
|
{ $s->$m($v) |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
else |
117
|
1
|
50
|
|
|
|
3
|
{ if ( $$group{no_strict} ) |
118
|
1
|
|
|
|
|
5
|
{ $$hash{$p} = $v |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
else |
121
|
0
|
|
|
|
|
0
|
{ croak qq(No such property "$p", died) |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
38
|
50
|
|
|
|
202
|
; wantarray ? %$hash : $hash # no argument |
127
|
|
|
|
|
|
|
} |
128
|
11
|
|
|
|
|
67
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1 ; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |