line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Stream::HashBase; |
2
|
109
|
|
|
109
|
|
1038
|
use strict; |
|
109
|
|
|
|
|
173
|
|
|
109
|
|
|
|
|
2664
|
|
3
|
109
|
|
|
109
|
|
509
|
use warnings; |
|
109
|
|
|
|
|
174
|
|
|
109
|
|
|
|
|
2950
|
|
4
|
|
|
|
|
|
|
|
5
|
109
|
|
|
109
|
|
488
|
use Carp qw/confess croak/; |
|
109
|
|
|
|
|
189
|
|
|
109
|
|
|
|
|
5529
|
|
6
|
109
|
|
|
109
|
|
524
|
use Scalar::Util qw/blessed reftype/; |
|
109
|
|
|
|
|
213
|
|
|
109
|
|
|
|
|
25662
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$Carp::Internal{(__PACKAGE__)}++; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my (%META); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import { |
13
|
4066
|
|
|
4066
|
|
13236
|
my ($class, %args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
4066
|
|
66
|
|
|
17996
|
my $into = $args{into} || caller; |
16
|
4066
|
|
100
|
|
|
14540
|
my $meta = $META{$into} = $args{accessors} || []; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Use the comment to change the filename slightly so that Devel::Cover does |
19
|
|
|
|
|
|
|
# not try to cover the contents of the string eval. |
20
|
4066
|
|
|
|
|
6347
|
my $file = __FILE__; |
21
|
4066
|
|
|
|
|
82346
|
$file =~ s/(\.*)$/.eval$1/; |
22
|
4066
|
|
|
|
|
11361
|
my $eval = "# line 1 \"$file\"\npackage $into;\n"; |
23
|
|
|
|
|
|
|
|
24
|
4066
|
100
|
|
|
|
11787
|
if(my $base = $args{base}) { |
25
|
2565
|
|
66
|
|
|
7704
|
my $bmeta = $META{$base} || croak "Base class '$base' is not a HashBase class"; |
26
|
|
|
|
|
|
|
|
27
|
2563
|
|
|
|
|
18484
|
$eval .= "sub " . uc($_) . "() { '$_' };\n" for @$bmeta; |
28
|
|
|
|
|
|
|
|
29
|
109
|
|
|
109
|
|
570
|
no strict 'refs'; |
|
109
|
|
|
|
|
242
|
|
|
109
|
|
|
|
|
18891
|
|
30
|
2563
|
50
|
|
|
|
32247
|
push @{"$into\::ISA"} => $base |
|
2563
|
|
|
|
|
31145
|
|
31
|
|
|
|
|
|
|
unless $into->isa($base); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
{ |
35
|
4064
|
|
|
|
|
8977
|
$eval .= join '' => map { |
36
|
4064
|
|
|
|
|
8002
|
my $const = uc($_); |
|
14390
|
|
|
|
|
21116
|
|
37
|
|
|
|
|
|
|
<<" EOT" |
38
|
|
|
|
|
|
|
sub $const() { '$_' } |
39
|
|
|
|
|
|
|
sub $_ { \$_[0]->{'$_'} } |
40
|
|
|
|
|
|
|
sub set_$_ { \$_[0]->{'$_'} = \$_[1] } |
41
|
|
|
|
|
|
|
sub clear_$_ { delete \$_[0]->{'$_'} } |
42
|
|
|
|
|
|
|
EOT |
43
|
14390
|
|
|
|
|
68270
|
} @$meta; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
4064
|
50
|
|
|
|
1625752
|
eval "${eval}1;" || die $@; |
47
|
|
|
|
|
|
|
|
48
|
4064
|
100
|
|
|
|
85308
|
return if $args{no_new}; |
49
|
|
|
|
|
|
|
|
50
|
109
|
|
|
109
|
|
555
|
no strict 'refs'; |
|
109
|
|
|
|
|
169
|
|
|
109
|
|
|
|
|
34972
|
|
51
|
3969
|
|
|
|
|
7161
|
*{"$into\::new"} = \&_new; |
|
3969
|
|
|
|
|
1332328
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _new { |
55
|
16897
|
|
|
16897
|
|
54697
|
my ($class, %params) = @_; |
56
|
16897
|
|
|
|
|
31909
|
my $self = bless \%params, $class; |
57
|
16897
|
100
|
|
|
|
102937
|
$self->init if $self->can('init'); |
58
|
16860
|
|
|
|
|
57328
|
$self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub gen_accessor { |
62
|
50
|
|
|
50
|
1
|
617
|
my $class = shift; |
63
|
50
|
|
|
|
|
90
|
my ($field) = @_; |
64
|
|
|
|
|
|
|
sub { |
65
|
168
|
|
|
168
|
|
470
|
my $self = shift; |
66
|
168
|
100
|
|
|
|
486
|
($self->{$field}) = @_ if @_; |
67
|
168
|
|
|
|
|
754
|
$self->{$field}; |
68
|
50
|
|
|
|
|
251
|
}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub gen_getter { |
72
|
7
|
|
|
7
|
1
|
16
|
my $class = shift; |
73
|
7
|
|
|
|
|
13
|
my ($field) = @_; |
74
|
7
|
|
|
9
|
|
48
|
sub { $_[0]->{$field} }; |
|
9
|
|
|
|
|
38
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub gen_setter { |
78
|
7
|
|
|
7
|
0
|
15
|
my $class = shift; |
79
|
7
|
|
|
|
|
13
|
my ($field) = @_; |
80
|
7
|
|
|
8
|
|
37
|
sub { $_[0]->{$field} = $_[1] }; |
|
8
|
|
|
|
|
38
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |