line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::XSAccessor; |
2
|
23
|
|
|
23
|
|
168839
|
use 5.008; |
|
23
|
|
|
|
|
78
|
|
|
23
|
|
|
|
|
930
|
|
3
|
23
|
|
|
23
|
|
128
|
use strict; |
|
23
|
|
|
|
|
41
|
|
|
23
|
|
|
|
|
822
|
|
4
|
23
|
|
|
23
|
|
124
|
use warnings; |
|
23
|
|
|
|
|
53
|
|
|
23
|
|
|
|
|
835
|
|
5
|
23
|
|
|
23
|
|
121
|
use Carp qw/croak/; |
|
23
|
|
|
|
|
49
|
|
|
23
|
|
|
|
|
1613
|
|
6
|
23
|
|
|
23
|
|
17527
|
use Class::XSAccessor::Heavy; |
|
23
|
|
|
|
|
56
|
|
|
23
|
|
|
|
|
622
|
|
7
|
23
|
|
|
23
|
|
201
|
use XSLoader; |
|
23
|
|
|
|
|
36
|
|
|
23
|
|
|
|
|
15983
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.19'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
XSLoader::load('Class::XSAccessor', $VERSION); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _make_hash { |
14
|
400
|
|
|
400
|
|
487
|
my $ref = shift; |
15
|
|
|
|
|
|
|
|
16
|
400
|
100
|
|
|
|
742
|
if (ref ($ref)) { |
17
|
394
|
100
|
|
|
|
923
|
if (ref($ref) eq 'ARRAY') { |
18
|
8
|
|
|
|
|
21
|
$ref = { map { $_ => $_ } @$ref } |
|
15
|
|
|
|
|
56
|
|
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} else { |
21
|
6
|
|
|
|
|
54
|
$ref = { $ref, $ref }; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
400
|
|
|
|
|
788
|
return $ref; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub import { |
28
|
50
|
|
|
50
|
|
55003
|
my $own_class = shift; |
29
|
50
|
|
|
|
|
157
|
my ($caller_pkg) = caller(); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Support both { getters => ... } and plain getters => ... |
32
|
50
|
100
|
|
|
|
267
|
my %opts = ref($_[0]) eq 'HASH' ? %{$_[0]} : @_; |
|
8
|
|
|
|
|
33
|
|
33
|
|
|
|
|
|
|
|
34
|
50
|
100
|
|
|
|
216
|
$caller_pkg = $opts{class} if defined $opts{class}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# TODO: Refactor. Move more duplicated code to ::Heavy |
37
|
50
|
|
100
|
|
|
303
|
my $read_subs = _make_hash($opts{getters} || {}); |
38
|
50
|
|
100
|
|
|
300
|
my $set_subs = _make_hash($opts{setters} || {}); |
39
|
50
|
|
100
|
|
|
267
|
my $acc_subs = _make_hash($opts{accessors} || {}); |
40
|
50
|
|
100
|
|
|
395
|
my $lvacc_subs = _make_hash($opts{lvalue_accessors} || {}); |
41
|
50
|
|
100
|
|
|
312
|
my $pred_subs = _make_hash($opts{predicates} || {}); |
42
|
50
|
|
100
|
|
|
302
|
my $ex_pred_subs = _make_hash($opts{exists_predicates} || {}); |
43
|
50
|
|
100
|
|
|
333
|
my $def_pred_subs = _make_hash($opts{defined_predicates} || {}); |
44
|
50
|
|
100
|
|
|
448
|
my $test_subs = _make_hash($opts{__tests__} || {}); |
45
|
50
|
|
50
|
|
|
370
|
my $construct_subs = $opts{constructors} || [defined($opts{constructor}) ? $opts{constructor} : ()]; |
46
|
50
|
|
100
|
|
|
266
|
my $true_subs = $opts{true} || []; |
47
|
50
|
|
100
|
|
|
225
|
my $false_subs = $opts{false} || []; |
48
|
|
|
|
|
|
|
|
49
|
50
|
|
|
|
|
518
|
foreach my $subtype ( ["getter", $read_subs], |
50
|
|
|
|
|
|
|
["setter", $set_subs], |
51
|
|
|
|
|
|
|
["accessor", $acc_subs], |
52
|
|
|
|
|
|
|
["lvalue_accessor", $lvacc_subs], |
53
|
|
|
|
|
|
|
["test", $test_subs], |
54
|
|
|
|
|
|
|
["ex_predicate", $ex_pred_subs], |
55
|
|
|
|
|
|
|
["def_predicate", $def_pred_subs], |
56
|
|
|
|
|
|
|
["def_predicate", $pred_subs] ) |
57
|
|
|
|
|
|
|
{ |
58
|
393
|
|
|
|
|
606
|
my $subs = $subtype->[1]; |
59
|
393
|
|
|
|
|
1105
|
foreach my $subname (keys %$subs) { |
60
|
75
|
|
|
|
|
124
|
my $hashkey = $subs->{$subname}; |
61
|
75
|
|
|
|
|
335
|
_generate_method($caller_pkg, $subname, $hashkey, \%opts, $subtype->[0]); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
49
|
|
|
|
|
322
|
foreach my $subtype ( ["constructor", $construct_subs], |
66
|
|
|
|
|
|
|
["true", $true_subs], |
67
|
|
|
|
|
|
|
["false", $false_subs] ) |
68
|
|
|
|
|
|
|
{ |
69
|
147
|
|
|
|
|
207
|
foreach my $subname (@{$subtype->[1]}) { |
|
147
|
|
|
|
|
6361
|
|
70
|
11
|
|
|
|
|
39
|
_generate_method($caller_pkg, $subname, "", \%opts, $subtype->[0]); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _generate_method { |
76
|
86
|
|
|
86
|
|
147
|
my ($caller_pkg, $subname, $hashkey, $opts, $type) = @_; |
77
|
|
|
|
|
|
|
|
78
|
86
|
50
|
|
|
|
190
|
croak("Cannot use undef as a hash key for generating an XS $type accessor. (Sub: $subname)") |
79
|
|
|
|
|
|
|
if not defined $hashkey; |
80
|
|
|
|
|
|
|
|
81
|
86
|
100
|
|
|
|
291
|
$subname = "${caller_pkg}::$subname" if $subname !~ /::/; |
82
|
|
|
|
|
|
|
|
83
|
86
|
100
|
|
|
|
467
|
Class::XSAccessor::Heavy::check_sub_existence($subname) if not $opts->{replace}; |
84
|
23
|
|
|
23
|
|
139
|
no warnings 'redefine'; # don't warn about an explicitly requested redefine |
|
23
|
|
|
|
|
54
|
|
|
23
|
|
|
|
|
6927
|
|
85
|
|
|
|
|
|
|
|
86
|
85
|
100
|
|
|
|
406
|
if ($type eq 'getter') { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
87
|
30
|
|
|
|
|
436
|
newxs_getter($subname, $hashkey); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
elsif ($type eq 'lvalue_accessor') { |
90
|
1
|
|
|
|
|
36
|
newxs_lvalue_accessor($subname, $hashkey); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
elsif ($type eq 'setter') { |
93
|
17
|
|
100
|
|
|
287
|
newxs_setter($subname, $hashkey, $opts->{chained}||0); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
elsif ($type eq 'def_predicate') { |
96
|
9
|
|
|
|
|
93
|
newxs_defined_predicate($subname, $hashkey); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
elsif ($type eq 'ex_predicate') { |
99
|
2
|
|
|
|
|
14
|
newxs_exists_predicate($subname, $hashkey); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
elsif ($type eq 'constructor') { |
102
|
3
|
|
|
|
|
32
|
newxs_constructor($subname); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
elsif ($type eq 'true') { |
105
|
4
|
|
|
|
|
26
|
newxs_boolean($subname, 1); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
elsif ($type eq 'false') { |
108
|
4
|
|
|
|
|
56
|
newxs_boolean($subname, 0); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
elsif ($type eq 'test') { |
111
|
2
|
|
|
|
|
24
|
newxs_test($subname, $hashkey); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
else { |
114
|
13
|
|
100
|
|
|
236
|
newxs_accessor($subname, $hashkey, $opts->{chained}||0); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |