line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::AccessorMaker::Private; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
## |
4
|
|
|
|
|
|
|
## Class::AccessorMaker::Private by Hartog 'Sinister' de Mik |
5
|
|
|
|
|
|
|
## |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
15542
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
125
|
|
8
|
3
|
|
|
3
|
|
16
|
no strict 'refs'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
120
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "1.0"; |
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
12
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1570
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# lexical for data-hiding |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my %obj_ = (); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import { |
19
|
3
|
|
|
3
|
|
28
|
my ($class, $subs, $xtra) = @_; |
20
|
3
|
|
33
|
|
|
21
|
my $pkg = ref(caller) || caller; |
21
|
3
|
|
100
|
|
|
15
|
$xtra ||=""; |
22
|
|
|
|
|
|
|
|
23
|
3
|
50
|
|
|
|
10
|
croak "Can't make methods out of an empty hash-ref\n" if !defined $subs; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
## define a constructor |
26
|
3
|
100
|
|
|
|
11
|
if ( $xtra ne "no_new" ) { |
27
|
|
|
|
|
|
|
# we have a green light for 'new()' creation |
28
|
2
|
100
|
|
|
|
10
|
if ( $xtra ne "new_init" ) { |
|
|
50
|
|
|
|
|
|
29
|
1
|
|
|
|
|
5
|
*{"${pkg}::new"} = sub { |
30
|
0
|
|
0
|
0
|
|
0
|
my $class = ref($_[0]) || $_[0]; shift; |
|
0
|
|
|
|
|
0
|
|
31
|
0
|
|
|
|
|
0
|
my $self = bless({}, $class); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
while ( @_ ) { |
34
|
0
|
|
|
|
|
0
|
my ($sub, $value) = (shift, shift); |
35
|
0
|
|
|
|
|
0
|
$self->$sub($value); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
0
|
return $self; |
39
|
1
|
|
|
|
|
3
|
}; |
40
|
|
|
|
|
|
|
} elsif ( $xtra eq "new_init" ) { |
41
|
1
|
|
|
|
|
6
|
*{"${pkg}::new"} = sub { |
42
|
1
|
|
33
|
1
|
|
7
|
my $class = ref($_[0]) || $_[0]; shift; |
|
1
|
|
|
|
|
2
|
|
43
|
1
|
|
|
|
|
4
|
my $self = bless({}, $class); |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
5
|
while ( @_ ) { |
46
|
0
|
|
|
|
|
0
|
my ($sub, $value) = (shift, shift); |
47
|
0
|
|
|
|
|
0
|
$self->$sub($value); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
4
|
$self->init(); |
51
|
1
|
|
|
|
|
5
|
return $self; |
52
|
1
|
|
|
|
|
3
|
}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
3
|
|
|
|
|
9
|
foreach my $sub ( keys %$subs ) { |
58
|
|
|
|
|
|
|
# construct the method if it is not defined yet. |
59
|
6
|
50
|
|
|
|
8
|
next if ( defined &{"${pkg}::$sub"} ); |
|
6
|
|
|
|
|
34
|
|
60
|
|
|
|
|
|
|
|
61
|
6
|
|
|
|
|
33
|
*{"${pkg}::$sub"} = sub { |
62
|
4
|
|
|
4
|
|
12
|
my ( $self, $value ) = @_; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# fill with default at first run |
65
|
4
|
100
|
|
|
|
26
|
$obj_{$self}->{$sub} = $subs->{$sub} if !exists $obj_{$self}->{$sub}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# more then just self, something has to be set. |
68
|
4
|
100
|
|
|
|
10
|
if ($#_ > 0) { |
69
|
1
|
50
|
33
|
|
|
6
|
warn "The value supplied to '$sub()' is not of propper type" |
70
|
|
|
|
|
|
|
if (ref($subs->{$sub}) and !ref($value)); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# set the value and return the object. |
73
|
1
|
|
|
|
|
3
|
$obj_{$self}->{$sub} = $value; |
74
|
1
|
|
|
|
|
3
|
return $self; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# return the value; |
78
|
3
|
|
|
|
|
591
|
return $obj_{$self}->{$sub}; |
79
|
|
|
|
|
|
|
|
80
|
6
|
50
|
|
|
|
20
|
} or warn "Method: $sub not implemented\n"; |
81
|
|
|
|
|
|
|
} |
82
|
3
|
|
|
|
|
110
|
return 1; # import succeeded |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |