line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################## |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Class::SelfMethods - a Module for supporting instance-defined methods |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Author: Toby Ovod-Everett |
6
|
|
|
|
|
|
|
# Last Change: Update POD to mention Class::Prototyped |
7
|
|
|
|
|
|
|
############################################################################## |
8
|
|
|
|
|
|
|
# Copyright 1999, 2003 Toby Ovod-Everett, 1999 Damian Conway. All rights reserved. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify it |
11
|
|
|
|
|
|
|
# under the same terms as Perl itself. |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# For comments, questions, bugs or general interest, feel free to |
14
|
|
|
|
|
|
|
# contact Toby Ovod-Everett at tovod-everett@alascom.att.com |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# Damian Conway, damian@cs.monash.edu.au, was responsible for the _SET |
17
|
|
|
|
|
|
|
# accessor code and the symbol table manipulation code. |
18
|
|
|
|
|
|
|
############################################################################## |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package Class::SelfMethods; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
822
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
23
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
107
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$VERSION = '1.08'; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
377
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub AUTOLOAD { |
30
|
8
|
|
|
8
|
|
116
|
(my $func = $AUTOLOAD) =~ s/^.*::(_?)//; |
31
|
8
|
100
|
|
|
|
26
|
unless ($1) { |
32
|
7
|
|
|
|
|
16
|
my $method = can($_[0], $func); |
33
|
7
|
100
|
|
|
|
28
|
goto &$method if $method; |
34
|
|
|
|
|
|
|
} |
35
|
2
|
|
|
|
|
225
|
croak sprintf 'Can\'t locate object method "%s" via package "%s"', $func, ref($_[0]); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub can { |
39
|
16
|
|
|
16
|
1
|
128
|
my($self, $func) = @_; |
40
|
|
|
|
|
|
|
|
41
|
16
|
100
|
|
|
|
53
|
if ($func =~ s/_SET$//) { |
42
|
3
|
|
|
|
|
14
|
my $method = UNIVERSAL::can($self, "${func}_SET"); |
43
|
3
|
50
|
|
|
|
8
|
unless ($method) { |
44
|
1
|
|
|
1
|
|
6
|
no strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
135
|
|
45
|
3
|
|
|
12
|
|
9
|
*{"${func}_SET"} = $method = sub { $_[0]->{$func} = $_[1] }; |
|
3
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
136
|
|
46
|
|
|
|
|
|
|
} |
47
|
3
|
|
|
|
|
7
|
return $method; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
13
|
100
|
|
|
|
31
|
if ($func =~ s/_CLEAR$//) { |
51
|
2
|
|
|
|
|
12
|
my $method = UNIVERSAL::can($self, "${func}_CLEAR"); |
52
|
2
|
50
|
|
|
|
6
|
unless ($method) { |
53
|
1
|
|
|
1
|
|
5
|
no strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
144
|
|
54
|
2
|
|
|
2
|
|
16
|
*{"${func}_CLEAR"} = $method = sub { delete $_[0]->{$func} }; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
39
|
|
55
|
|
|
|
|
|
|
} |
56
|
2
|
|
|
|
|
6
|
return $method; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
11
|
|
|
|
|
18
|
my $undercall = "_$func"; |
60
|
11
|
100
|
100
|
|
|
99
|
if (exists $self->{$func} or UNIVERSAL::can($self, $undercall)) { |
61
|
6
|
|
|
|
|
15
|
my $method = UNIVERSAL::can($self, $func); |
62
|
6
|
100
|
|
|
|
14
|
unless ($method) { |
63
|
1
|
|
|
1
|
|
5
|
no strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
356
|
|
64
|
3
|
|
|
|
|
21
|
*{$func} = $method = sub { |
65
|
24
|
100
|
|
24
|
|
118
|
if (exists $_[0]->{$func}) { |
66
|
16
|
100
|
|
|
|
37
|
if (ref ($_[0]->{$func}) eq 'CODE') { |
67
|
4
|
|
|
|
|
6
|
goto &{$_[0]->{$func}}; |
|
4
|
|
|
|
|
12
|
|
68
|
|
|
|
|
|
|
} else { |
69
|
12
|
|
|
|
|
143
|
return $_[0]->{$func}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} else { |
72
|
8
|
|
|
|
|
11
|
my $self = shift; |
73
|
8
|
|
|
|
|
20
|
return $self->$undercall(@_); |
74
|
|
|
|
|
|
|
} |
75
|
3
|
|
|
|
|
21
|
}; |
76
|
|
|
|
|
|
|
} |
77
|
6
|
|
|
|
|
14
|
return $method; |
78
|
|
|
|
|
|
|
} |
79
|
5
|
|
|
|
|
36
|
return; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub new { |
83
|
3
|
|
|
3
|
1
|
80
|
my $class = shift; |
84
|
3
|
|
|
|
|
9
|
my(%params) = @_; |
85
|
|
|
|
|
|
|
|
86
|
3
|
|
|
|
|
4
|
my %temp_params; |
87
|
3
|
|
|
|
|
8
|
foreach my $i (keys %params) { |
88
|
5
|
50
|
|
|
|
14
|
if ($i =~ /^_/) { |
89
|
0
|
|
|
|
|
0
|
$temp_params{$i} = $params{$i}; |
90
|
0
|
|
|
|
|
0
|
delete $params{$i}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
3
|
|
|
|
|
6
|
my $self = \%params; |
95
|
3
|
|
|
|
|
4
|
bless $self, $class; |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
7
|
foreach my $i (keys %temp_params) { |
98
|
0
|
|
|
|
|
0
|
$self->$i(@{$temp_params{$i}}); |
|
0
|
|
|
|
|
0
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
3
|
|
|
|
|
9
|
return $self; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |