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