line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Method::Auto; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
27543
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "1.00"; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
933
|
use attributes 'get'; |
|
1
|
|
|
|
|
1587
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub my_croak($$) { |
11
|
2
|
|
|
2
|
0
|
4
|
my ($package, $method) = @_; |
12
|
2
|
|
|
|
|
13
|
require Carp; |
13
|
2
|
|
|
|
|
279
|
Carp::croak "Undefined subroutine &${package}::$method called"; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub import { |
17
|
3
|
|
|
3
|
|
3396
|
shift; |
18
|
3
|
|
|
|
|
5
|
my $target = caller; |
19
|
3
|
|
|
|
|
6
|
my ($regexp, $check_attributes, @methods); |
20
|
3
|
|
|
|
|
7
|
for (@_) { |
21
|
3
|
100
|
|
|
|
10
|
if (ref($_) eq 'Regexp') { |
|
|
100
|
|
|
|
|
|
22
|
1
|
|
|
|
|
3
|
$regexp = $_; |
23
|
|
|
|
|
|
|
} elsif ($_ eq '-attributes') { |
24
|
1
|
|
|
|
|
20
|
$check_attributes = 1; |
25
|
|
|
|
|
|
|
} else { |
26
|
1
|
|
|
|
|
4
|
push(@methods, $_); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
3
|
100
|
|
|
|
6
|
if (@methods) { # install for every method in @_ |
30
|
1
|
|
|
|
|
2
|
for my $method(@methods) { |
31
|
|
|
|
|
|
|
my $autosub = sub { |
32
|
1
|
|
|
1
|
|
240
|
my $package = caller; |
33
|
1
|
|
|
|
|
5
|
unshift(@_, $package); |
34
|
1
|
|
|
|
|
3
|
my @isa; |
35
|
|
|
|
|
|
|
{ |
36
|
1
|
|
|
1
|
|
248
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
103
|
|
|
1
|
|
|
|
|
2
|
|
37
|
1
|
|
|
|
|
2
|
@isa = @{$package.'::ISA'}; |
|
1
|
|
|
|
|
7
|
|
38
|
|
|
|
|
|
|
} |
39
|
1
|
|
|
|
|
3
|
for (@isa) { |
40
|
1
|
|
|
|
|
12
|
my $sub = $_->can($method); |
41
|
1
|
50
|
|
|
|
5
|
goto &{$sub} if defined $sub; |
|
1
|
|
|
|
|
33
|
|
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
0
|
my_croak($package, $method); |
44
|
1
|
|
|
|
|
5
|
}; |
45
|
|
|
|
|
|
|
{ |
46
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
226
|
|
|
1
|
|
|
|
|
2
|
|
47
|
1
|
50
|
|
|
|
1
|
*{"${target}::$method"} = $autosub unless defined *{"${target}::$method"}{'CODE'}; |
|
1
|
|
|
|
|
95
|
|
|
1
|
|
|
|
|
9
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} else { # install globally; |
51
|
|
|
|
|
|
|
my $autoload = sub { |
52
|
3
|
|
|
3
|
|
2708
|
my $method = our $AUTOLOAD; |
53
|
3
|
|
|
|
|
15
|
$method =~ s/.*:://; |
54
|
3
|
|
|
|
|
9
|
my $package = caller; |
55
|
3
|
50
|
|
|
|
10
|
if ($regexp) { |
56
|
3
|
100
|
|
|
|
23
|
my_croak($package, $method) unless ($method =~ $regexp); |
57
|
|
|
|
|
|
|
} |
58
|
1
|
|
|
|
|
3
|
unshift(@_, $package); |
59
|
1
|
|
|
|
|
13
|
my $sub = $package->can($method); |
60
|
1
|
50
|
|
|
|
4
|
my_croak($package, $method) unless defined $sub; |
61
|
1
|
50
|
|
|
|
4
|
if ($check_attributes) { |
62
|
1
|
|
|
|
|
2
|
my %attr; |
63
|
1
|
|
|
|
|
7
|
@attr{get($sub)} = undef; |
64
|
1
|
50
|
|
|
|
68
|
my_croak($package, $method) unless exists $attr{'method'}; |
65
|
|
|
|
|
|
|
} |
66
|
1
|
|
|
|
|
2
|
goto &{$sub}; |
|
1
|
|
|
|
|
5
|
|
67
|
2
|
|
|
|
|
9
|
}; |
68
|
|
|
|
|
|
|
{ |
69
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
99
|
|
|
2
|
|
|
|
|
3
|
|
70
|
2
|
50
|
|
|
|
3
|
if (defined *{"${target}::AUTOLOAD"}{'CODE'}) { |
|
2
|
|
|
|
|
11
|
|
71
|
0
|
|
|
|
|
0
|
require Carp; |
72
|
0
|
|
|
|
|
0
|
Carp::croak "There already seems to be a routine named AUTOLOAD in $target"; |
73
|
|
|
|
|
|
|
} else { |
74
|
2
|
|
|
|
|
2
|
*{"${target}::AUTOLOAD"} = $autoload; |
|
2
|
|
|
|
|
2284
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
__END__ |