line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::ExtraAttributes; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# version |
4
|
|
|
|
|
|
|
$VERSION= '0.03'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# be as strict and verbose as possible |
7
|
2
|
|
|
2
|
|
1979
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
47
|
|
8
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
48
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# modules that we need |
11
|
2
|
|
|
2
|
|
820
|
use OOB qw( OOB_get OOB_set ); |
|
2
|
|
|
|
|
6644
|
|
|
2
|
|
|
|
|
10
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# additionals attributes per class |
14
|
|
|
|
|
|
|
my %attributes; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# satisfy -require- |
17
|
|
|
|
|
|
|
1; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
# Class Methods |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
# attributes |
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
# Return the extra attributes for the given class |
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
# IN: 1 Class::ExtraAttributes (ignored) |
29
|
|
|
|
|
|
|
# 2 class to return extra attributes of (optional) |
30
|
|
|
|
|
|
|
# OUT: 1 list (or list ref) with extra attributes |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub attributes { |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# fetch attributes |
35
|
1
|
50
|
33
|
1
|
0
|
235
|
my @attributes= keys %{ $attributes{ $_[1] || caller() } || {} }; |
|
1
|
|
|
|
|
9
|
|
36
|
|
|
|
|
|
|
|
37
|
1
|
50
|
|
|
|
4
|
return wantarray ? @attributes : \@attributes; |
38
|
|
|
|
|
|
|
} #attributes |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
41
|
|
|
|
|
|
|
# |
42
|
|
|
|
|
|
|
# Standard Perl features |
43
|
|
|
|
|
|
|
# |
44
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
45
|
|
|
|
|
|
|
# import |
46
|
|
|
|
|
|
|
# |
47
|
|
|
|
|
|
|
# Export any constants requested |
48
|
|
|
|
|
|
|
# |
49
|
|
|
|
|
|
|
# IN: 1 class (ignored) |
50
|
|
|
|
|
|
|
# 2..N attributes to be defined |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub import { |
53
|
3
|
|
|
3
|
|
471
|
my $class= shift; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# nothing to export |
56
|
3
|
100
|
|
|
|
16
|
return if !@_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# determine namespace to export to |
59
|
2
|
|
|
|
|
4
|
my $namespace= caller(); |
60
|
2
|
|
100
|
|
|
8
|
my $attributes= $attributes{$namespace} ||= {}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# create accessor / mutator for given attributes |
63
|
2
|
|
|
2
|
|
228
|
no strict 'refs'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
275
|
|
64
|
2
|
|
|
|
|
4
|
foreach my $method ( grep { !exists $attributes->{$_} } @_ ) { |
|
2
|
|
|
|
|
6
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# make sure we don't cloak anything |
67
|
2
|
100
|
|
|
|
17
|
die "Can already do '$method' on class $namespace" |
68
|
|
|
|
|
|
|
if $namespace->can($method); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# install accessor / mutator |
71
|
1
|
|
|
|
|
2
|
$attributes->{$method}= undef; |
72
|
1
|
|
|
|
|
3
|
*{ $namespace . '::' . $method }= sub { |
73
|
2
|
100
|
|
2
|
|
552
|
return @_ == 2 |
74
|
|
|
|
|
|
|
? OOB_set( $_[0], $method => $_[1], $namespace ) |
75
|
|
|
|
|
|
|
: OOB_get( $_[0], $method, $namespace ); |
76
|
1
|
|
|
|
|
4
|
}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
3
|
return; |
80
|
|
|
|
|
|
|
} #import |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |