| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1152 | ▶ | if (ref($ref) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 144 | ▶ | $caller_pkg = $opts{class} if defined $opts{class}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # TODO: Refactor. Move more duplicated code to ::Heavy | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 144 | ▶ | my $read_subs = _make_hash($opts{getters} || {}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{'getters'} || {}
MC/DC0%0/1
$opts{'getters'} || {}
$opts{'getters'}
Truth table50%1/2
A
A= $opts{'getters'}
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 144 | ▶ | my $set_subs = _make_hash($opts{setters} || {}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{'setters'} || {}
MC/DC0%0/1
$opts{'setters'} || {}
$opts{'setters'}
Truth table50%1/2
A
A= $opts{'setters'}
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 144 | ▶ | my $acc_subs = _make_hash($opts{accessors} || {}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{'accessors'} || {}
MC/DC0%0/1
$opts{'accessors'} || {}
$opts{'accessors'}
Truth table50%1/2
A
A= $opts{'accessors'}
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 144 | ▶ | my $lvacc_subs = _make_hash($opts{lvalue_accessors} || {}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{'lvalue_accessors'} || {}
MC/DC0%0/1
$opts{'lvalue_accessors'} || {}
$opts{'lvalue_accessors'}
Truth table50%1/2
A
A= $opts{'lvalue_accessors'}
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 144 | ▶ | my $pred_subs = _make_hash($opts{predicates} || {}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{'predicates'} || {}
MC/DC0%0/1
$opts{'predicates'} || {}
$opts{'predicates'}
Truth table50%1/2
A
A= $opts{'predicates'}
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 144 | ▶ | my $ex_pred_subs = _make_hash($opts{exists_predicates} || {}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{'exists_predicates'} || {}
MC/DC0%0/1
$opts{'exists_predicates'} || {}
$opts{'exists_predicates'}
Truth table50%1/2
A
A= $opts{'exists_predicates'}
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 144 | ▶ | my $def_pred_subs = _make_hash($opts{defined_predicates} || {}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{'defined_predicates'} || {}
MC/DC0%0/1
$opts{'defined_predicates'} || {}
$opts{'defined_predicates'}
Truth table50%1/2
A
A= $opts{'defined_predicates'}
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 144 | ▶ | my $test_subs = _make_hash($opts{__tests__} || {}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{'__tests__'} || {}
MC/DC0%0/1
$opts{'__tests__'} || {}
$opts{'__tests__'}
Truth table50%1/2
A
A= $opts{'__tests__'}
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 144 | ▶ | my $construct_subs = $opts{constructors} || [defined($opts{constructor}) ? $opts{constructor} : ()]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$opts{'constructors'} || [defined $opts{'constructor'} ? $opts{'constructor'} : ()]
MC/DC0%0/1
$opts{'constructors'} || [defined $opts{'constructor'} ? $opts{'constructor'} : ()]
$opts{'constructors'}
Truth table50%1/2
A
A= $opts{'constructors'}
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 144 | ▶ | my $true_subs = $opts{true} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{'true'} || []
MC/DC0%0/1
$opts{'true'} || []
$opts{'true'}
Truth table50%1/2
A
A= $opts{'true'}
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 144 | ▶ | my $false_subs = $opts{false} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{'false'} || []
MC/DC0%0/1
$opts{'false'} || []
$opts{'false'}
Truth table50%1/2
A
A= $opts{'false'}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | if not defined $hashkey; | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 144 | ▶ | $subname = "${caller_pkg}::$subname" if $subname !~ /::/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 144 | ▶ | Class::XSAccessor::Heavy::check_sub_existence($subname) if not $opts->{replace}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$opts->{'chained'} || 0
$opts->{'chained'}
Truth table0%0/2
A
A= $opts->{'chained'}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$opts->{'chained'} || 0
$opts->{'chained'}
Truth table0%0/2
A
A= $opts->{'chained'}
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||||||||||||||||||||||||