line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Util::HashBase; |
2
|
57
|
|
|
57
|
|
174
|
use strict; |
|
57
|
|
|
|
|
59
|
|
|
57
|
|
|
|
|
1244
|
|
3
|
57
|
|
|
57
|
|
162
|
use warnings; |
|
57
|
|
|
|
|
54
|
|
|
57
|
|
|
|
|
3350
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000043'; |
6
|
|
|
|
|
|
|
$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval) |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Carp; |
9
|
|
|
|
|
|
|
$Carp::Internal{+__PACKAGE__} = 1; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %ATTRS; |
12
|
|
|
|
|
|
|
my %META; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _get_inherited_attrs { |
15
|
57
|
|
|
57
|
|
196
|
no strict 'refs'; |
|
57
|
|
|
|
|
53
|
|
|
57
|
|
|
|
|
16635
|
|
16
|
970
|
|
|
970
|
|
1096
|
my @todo = map @{"$_\::ISA"}, @_; |
|
970
|
|
|
|
|
3744
|
|
17
|
970
|
|
|
|
|
892
|
my %seen; |
18
|
|
|
|
|
|
|
my @all; |
19
|
970
|
|
|
|
|
2133
|
while (my $pkg = shift @todo) { |
20
|
713
|
50
|
|
|
|
1501
|
next if $seen{$pkg}++; |
21
|
713
|
|
|
|
|
690
|
my $found = $META{$pkg}; |
22
|
713
|
50
|
|
|
|
3933
|
push @all => %$found if $found; |
23
|
|
|
|
|
|
|
|
24
|
713
|
|
|
|
|
722
|
my $isa = \@{"$pkg\::ISA"}; |
|
713
|
|
|
|
|
1285
|
|
25
|
713
|
100
|
|
|
|
2261
|
push @todo => @$isa if @$isa; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
970
|
|
|
|
|
12378
|
return \@all; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _make_subs { |
32
|
4837
|
|
|
4837
|
|
4035
|
my ($str) = @_; |
33
|
|
|
|
|
|
|
return $ATTRS{$str} ||= { |
34
|
0
|
|
|
0
|
|
0
|
uc($str) => sub() { $str }, |
35
|
2905
|
|
|
2905
|
|
10411
|
$str => sub { $_[0]->{$str} }, |
36
|
639
|
|
|
639
|
|
1264
|
"set_$str" => sub { $_[0]->{$str} = $_[1] }, |
37
|
4837
|
|
100
|
|
|
59901
|
}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub import { |
41
|
970
|
|
|
970
|
|
11420
|
my $class = shift; |
42
|
970
|
|
|
|
|
1230
|
my $into = caller; |
43
|
|
|
|
|
|
|
|
44
|
970
|
|
|
|
|
1325
|
my %attrs = map %{_make_subs($_)}, @_; |
|
4837
|
|
|
|
|
5102
|
|
45
|
|
|
|
|
|
|
|
46
|
970
|
|
|
|
|
4693
|
my @meta = map uc, @_; |
47
|
970
|
|
|
|
|
2607
|
@{$META{$into}}{@meta} = map $attrs{$_}, @meta; |
|
970
|
|
|
|
|
3295
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my %subs = ( |
50
|
|
|
|
|
|
|
%attrs, |
51
|
970
|
100
|
|
|
|
2341
|
@{_get_inherited_attrs($into)}, |
|
970
|
|
|
|
|
1291
|
|
52
|
|
|
|
|
|
|
$into->can('new') ? () : (new => \&_new) |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
57
|
|
|
57
|
|
233
|
no strict 'refs'; |
|
57
|
|
|
|
|
57
|
|
|
57
|
|
|
|
|
6066
|
|
56
|
970
|
|
|
|
|
4175
|
*{"$into\::$_"} = $subs{$_} for keys %subs; |
|
19371
|
|
|
|
|
341207
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _new { |
60
|
950
|
|
|
950
|
|
4974
|
my ($class, %params) = @_; |
61
|
950
|
|
|
|
|
1286
|
my $self = bless \%params, $class; |
62
|
950
|
100
|
|
|
|
5191
|
$self->init if $self->can('init'); |
63
|
940
|
|
|
|
|
5144
|
$self; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |