/usr/local/lib/perl5/site_perl/5.44.0/x86_64-linux/Class/XSAccessor.pm

filter: Statementstmt 80.0% 56 / 70 Branchbran 26.4% 9 / 34 Conditioncond 42.3% 11 / 26 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 56.2% 86 / 153 CC 35 SCAR 38.4
CC
35
Cov
58%
_generate_method
98.1
import
28.9
_make_hash
3.8
CRAP 46.3
« lib/Skilletor/Resolver.pm ↑ Summary lib/Skilletor/Apply.pm »
1 package Class::XSAccessor;
2 7 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use Class::XSAccessor::Heavy;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 our $VERSION = '1.19';
10  
11 7 XSLoader::load('Class::XSAccessor', $VERSION);
12  
13 1152 ▶sub _make_hash {
Subroutine _make_hash: called CC=3 SCAR=13.5
14 1152 my $ref = shift;
15  
16 1152 ▶ if (ref ($ref)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref) { } 1152 0 1152
17 1152 ▶ if (ref($ref) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref eq "ARRAY") 0 1152 1152
18 0 $ref = { map { $_ => $_ } @$ref }
19 }
20 } else {
21 0 $ref = { $ref, $ref };
22 }
23  
24 1152 return $ref;
25 }
26  
27 144 ▶sub import {
Subroutine import: called CC=19 SCAR=33.6
28 144 my $own_class = shift;
29 144 my ($caller_pkg) = caller();
30  
31 # Support both { getters => ... } and plain getters => ...
32 0 ▶ my %opts = ref($_[0]) eq 'HASH' ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 144 144
33  
34 144 ▶ $caller_pkg = $opts{class} if defined $opts{class};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"class"} 144 0 144
35  
36 # TODO: Refactor. Move more duplicated code to ::Heavy
37 144 ▶ my $read_subs = _make_hash($opts{getters} || {});
Condition50%1/2
$opts{'getters'} || {}
l!l
1440
MC/DC0%0/1
$opts{'getters'} || {}
$opts{'getters'}
Truth table50%1/2
A
A= $opts{'getters'}
Aresult
11
00
38 144 ▶ my $set_subs = _make_hash($opts{setters} || {});
Condition50%1/2
$opts{'setters'} || {}
l!l
0144
MC/DC0%0/1
$opts{'setters'} || {}
$opts{'setters'}
Truth table50%1/2
A
A= $opts{'setters'}
Aresult
11
00
39 144 ▶ my $acc_subs = _make_hash($opts{accessors} || {});
Condition50%1/2
$opts{'accessors'} || {}
l!l
0144
MC/DC0%0/1
$opts{'accessors'} || {}
$opts{'accessors'}
Truth table50%1/2
A
A= $opts{'accessors'}
Aresult
11
00
40 144 ▶ my $lvacc_subs = _make_hash($opts{lvalue_accessors} || {});
Condition50%1/2
$opts{'lvalue_accessors'} || {}
l!l
0144
MC/DC0%0/1
$opts{'lvalue_accessors'} || {}
$opts{'lvalue_accessors'}
Truth table50%1/2
A
A= $opts{'lvalue_accessors'}
Aresult
11
00
41 144 ▶ my $pred_subs = _make_hash($opts{predicates} || {});
Condition50%1/2
$opts{'predicates'} || {}
l!l
0144
MC/DC0%0/1
$opts{'predicates'} || {}
$opts{'predicates'}
Truth table50%1/2
A
A= $opts{'predicates'}
Aresult
11
00
42 144 ▶ my $ex_pred_subs = _make_hash($opts{exists_predicates} || {});
Condition50%1/2
$opts{'exists_predicates'} || {}
l!l
0144
MC/DC0%0/1
$opts{'exists_predicates'} || {}
$opts{'exists_predicates'}
Truth table50%1/2
A
A= $opts{'exists_predicates'}
Aresult
11
00
43 144 ▶ my $def_pred_subs = _make_hash($opts{defined_predicates} || {});
Condition50%1/2
$opts{'defined_predicates'} || {}
l!l
0144
MC/DC0%0/1
$opts{'defined_predicates'} || {}
$opts{'defined_predicates'}
Truth table50%1/2
A
A= $opts{'defined_predicates'}
Aresult
11
00
44 144 ▶ my $test_subs = _make_hash($opts{__tests__} || {});
Condition50%1/2
$opts{'__tests__'} || {}
l!l
0144
MC/DC0%0/1
$opts{'__tests__'} || {}
$opts{'__tests__'}
Truth table50%1/2
A
A= $opts{'__tests__'}
Aresult
11
00
45 144 ▶ my $construct_subs = $opts{constructors} || [defined($opts{constructor}) ? $opts{constructor} : ()];
Branch: 1 branch
BranchTrueFalseTotal
defined $opts{'constructor'} ? : 0 144 144
Condition50%1/2
$opts{'constructors'} || [defined $opts{'constructor'} ? $opts{'constructor'} : ()]
l!l
0144
MC/DC0%0/1
$opts{'constructors'} || [defined $opts{'constructor'} ? $opts{'constructor'} : ()]
$opts{'constructors'}
Truth table50%1/2
A
A= $opts{'constructors'}
Aresult
11
00
46 144 ▶ my $true_subs = $opts{true} || [];
Condition50%1/2
$opts{'true'} || []
l!l
0144
MC/DC0%0/1
$opts{'true'} || []
$opts{'true'}
Truth table50%1/2
A
A= $opts{'true'}
Aresult
11
00
47 144 ▶ my $false_subs = $opts{false} || [];
Condition50%1/2
$opts{'false'} || []
l!l
0144
MC/DC0%0/1
$opts{'false'} || []
$opts{'false'}
Truth table50%1/2
A
A= $opts{'false'}
Aresult
11
00
48  
49 144 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 1152 my $subs = $subtype->[1];
59 1152 foreach my $subname (keys %$subs) {
60 144 my $hashkey = $subs->{$subname};
61 144 _generate_method($caller_pkg, $subname, $hashkey, \%opts, $subtype->[0]);
62 }
63 }
64  
65 144 foreach my $subtype ( ["constructor", $construct_subs],
66 ["true", $true_subs],
67 ["false", $false_subs] )
68 {
69 432 foreach my $subname (@{$subtype->[1]}) {
70 0 _generate_method($caller_pkg, $subname, "", \%opts, $subtype->[0]);
71 }
72 }
73 }
74  
75 144 ▶sub _generate_method {
Subroutine _generate_method: called CC=15 SCAR=45.9
76 144 my ($caller_pkg, $subname, $hashkey, $opts, $type) = @_;
77  
78 144 ▶ croak("Cannot use undef as a hash key for generating an XS $type accessor. (Sub: $subname)")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hashkey 0 144 144
79 if not defined $hashkey;
80  
81 144 ▶ $subname = "${caller_pkg}::$subname" if $subname !~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless $subname =~ /::/ 144 0 144
82  
83 144 ▶ Class::XSAccessor::Heavy::check_sub_existence($subname) if not $opts->{replace};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"replace"} 0 144 144
84 7 ▶ no warnings 'redefine'; # don't warn about an explicitly requested redefine
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 144 ▶ if ($type eq 'getter') {
Branch: 9 branches
BranchTrueFalseTotal
if ($type eq 'getter') { } 144 0 144
elsif ($type eq 'lvalue_accessor') { } 0 0 0
elsif ($type eq 'setter') { } 0 0 0
elsif ($type eq 'def_predicate') { } 0 0 0
elsif ($type eq 'ex_predicate') { } 0 0 0
elsif ($type eq 'constructor') { } 0 0 0
elsif ($type eq 'true') { } 0 0 0
elsif ($type eq 'false') { } 0 0 0
elsif ($type eq 'test') { } 0 0 0
87 144 newxs_getter($subname, $hashkey);
88 }
89 elsif ($type eq 'lvalue_accessor') {
90 0 newxs_lvalue_accessor($subname, $hashkey);
91 }
92 elsif ($type eq 'setter') {
93 0 ▶ newxs_setter($subname, $hashkey, $opts->{chained}||0);
Condition0%0/2
$opts->{'chained'} || 0
l!l
00
MC/DC0%0/1
$opts->{'chained'} || 0
$opts->{'chained'}
Truth table0%0/2
A
A= $opts->{'chained'}
Aresult
11
00
94 }
95 elsif ($type eq 'def_predicate') {
96 0 newxs_defined_predicate($subname, $hashkey);
97 }
98 elsif ($type eq 'ex_predicate') {
99 0 newxs_exists_predicate($subname, $hashkey);
100 }
101 elsif ($type eq 'constructor') {
102 0 newxs_constructor($subname);
103 }
104 elsif ($type eq 'true') {
105 0 newxs_boolean($subname, 1);
106 }
107 elsif ($type eq 'false') {
108 0 newxs_boolean($subname, 0);
109 }
110 elsif ($type eq 'test') {
111 0 newxs_test($subname, $hashkey);
112 }
113 else {
114 0 ▶ newxs_accessor($subname, $hashkey, $opts->{chained}||0);
Condition0%0/2
$opts->{'chained'} || 0
l!l
00
MC/DC0%0/1
$opts->{'chained'} || 0
$opts->{'chained'}
Truth table0%0/2
A
A= $opts->{'chained'}
Aresult
11
00
115 }
116 }
117  
118 7 1;
119  
120 __END__
« lib/Skilletor/Resolver.pm ↑ Summary lib/Skilletor/Apply.pm »