line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Util::HashBase; |
2
|
57
|
|
|
57
|
|
180
|
use strict; |
|
57
|
|
|
|
|
61
|
|
|
57
|
|
|
|
|
1243
|
|
3
|
57
|
|
|
57
|
|
162
|
use warnings; |
|
57
|
|
|
|
|
56
|
|
|
57
|
|
|
|
|
2889
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000044'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Carp; |
8
|
|
|
|
|
|
|
$Carp::Internal{+__PACKAGE__} = 1; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my %ATTRS; |
11
|
|
|
|
|
|
|
my %META; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _get_inherited_attrs { |
14
|
57
|
|
|
57
|
|
180
|
no strict 'refs'; |
|
57
|
|
|
|
|
53
|
|
|
57
|
|
|
|
|
15664
|
|
15
|
970
|
|
|
970
|
|
1001
|
my @todo = map @{"$_\::ISA"}, @_; |
|
970
|
|
|
|
|
3703
|
|
16
|
970
|
|
|
|
|
840
|
my %seen; |
17
|
|
|
|
|
|
|
my @all; |
18
|
970
|
|
|
|
|
2113
|
while (my $pkg = shift @todo) { |
19
|
713
|
50
|
|
|
|
1540
|
next if $seen{$pkg}++; |
20
|
713
|
|
|
|
|
683
|
my $found = $META{$pkg}; |
21
|
713
|
50
|
|
|
|
3313
|
push @all => %$found if $found; |
22
|
|
|
|
|
|
|
|
23
|
713
|
|
|
|
|
715
|
my $isa = \@{"$pkg\::ISA"}; |
|
713
|
|
|
|
|
1221
|
|
24
|
713
|
100
|
|
|
|
2195
|
push @todo => @$isa if @$isa; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
970
|
|
|
|
|
11734
|
return \@all; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _make_subs { |
31
|
4837
|
|
|
4837
|
|
4365
|
my ($str) = @_; |
32
|
|
|
|
|
|
|
return $ATTRS{$str} ||= { |
33
|
0
|
|
|
0
|
|
0
|
uc($str) => sub() { $str }, |
34
|
2905
|
|
|
2905
|
|
10096
|
$str => sub { $_[0]->{$str} }, |
35
|
639
|
|
|
639
|
|
1186
|
"set_$str" => sub { $_[0]->{$str} = $_[1] }, |
36
|
4837
|
|
100
|
|
|
53362
|
}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub import { |
40
|
970
|
|
|
970
|
|
11107
|
my $class = shift; |
41
|
970
|
|
|
|
|
1329
|
my $into = caller; |
42
|
|
|
|
|
|
|
|
43
|
970
|
|
|
|
|
1388
|
my %attrs = map %{_make_subs($_)}, @_; |
|
4837
|
|
|
|
|
5223
|
|
44
|
|
|
|
|
|
|
|
45
|
970
|
|
|
|
|
4597
|
my @meta = map uc, @_; |
46
|
970
|
|
|
|
|
3262
|
@{$META{$into}}{@meta} = map $attrs{$_}, @meta; |
|
970
|
|
|
|
|
3244
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my %subs = ( |
49
|
|
|
|
|
|
|
%attrs, |
50
|
970
|
100
|
|
|
|
2415
|
@{_get_inherited_attrs($into)}, |
|
970
|
|
|
|
|
1314
|
|
51
|
|
|
|
|
|
|
$into->can('new') ? () : (new => \&_new) |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
57
|
|
|
57
|
|
204
|
no strict 'refs'; |
|
57
|
|
|
|
|
53
|
|
|
57
|
|
|
|
|
6125
|
|
55
|
970
|
|
|
|
|
4081
|
*{"$into\::$_"} = $subs{$_} for keys %subs; |
|
19371
|
|
|
|
|
337708
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _new { |
59
|
950
|
|
|
950
|
|
4734
|
my ($class, %params) = @_; |
60
|
950
|
|
|
|
|
1562
|
my $self = bless \%params, $class; |
61
|
950
|
100
|
|
|
|
4952
|
$self->init if $self->can('init'); |
62
|
940
|
|
|
|
|
5094
|
$self; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |