| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Class::XSAccessor::Array; | 
| 2 | 11 |  |  | 11 |  | 106181 | use 5.008; | 
|  | 11 |  |  |  |  | 44 |  | 
|  | 11 |  |  |  |  | 555 |  | 
| 3 | 11 |  |  | 11 |  | 64 | use strict; | 
|  | 11 |  |  |  |  | 19 |  | 
|  | 11 |  |  |  |  | 416 |  | 
| 4 | 11 |  |  | 11 |  | 62 | use warnings; | 
|  | 11 |  |  |  |  | 19 |  | 
|  | 11 |  |  |  |  | 551 |  | 
| 5 | 11 |  |  | 11 |  | 70 | use Carp qw/croak/; | 
|  | 11 |  |  |  |  | 24 |  | 
|  | 11 |  |  |  |  | 932 |  | 
| 6 | 11 |  |  | 11 |  | 17415 | use Class::XSAccessor; | 
|  | 11 |  |  |  |  | 25 |  | 
|  | 11 |  |  |  |  | 65 |  | 
| 7 | 11 |  |  | 11 |  | 76 | use Class::XSAccessor::Heavy; | 
|  | 11 |  |  |  |  | 16 |  | 
|  | 11 |  |  |  |  | 8397 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | our $VERSION = '1.19'; | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | sub import { | 
| 12 | 24 |  |  | 24 |  | 42499 | my $own_class = shift; | 
| 13 | 24 |  |  |  |  | 75 | my ($caller_pkg) = caller(); | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | # Support both { getters => ... } and plain getters => ... | 
| 16 | 24 | 100 |  |  |  | 122 | my %opts = ref($_[0]) eq 'HASH' ? %{$_[0]} : @_; | 
|  | 5 |  |  |  |  | 21 |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 24 | 100 |  |  |  | 92 | $caller_pkg = $opts{class} if defined $opts{class}; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 24 |  | 100 |  |  | 96 | my $read_subs      = $opts{getters} || {}; | 
| 21 | 24 |  | 100 |  |  | 107 | my $set_subs       = $opts{setters} || {}; | 
| 22 | 24 |  | 100 |  |  | 94 | my $acc_subs       = $opts{accessors} || {}; | 
| 23 | 24 |  | 100 |  |  | 118 | my $lvacc_subs     = $opts{lvalue_accessors} || {}; | 
| 24 | 24 |  | 100 |  |  | 209 | my $pred_subs      = $opts{predicates} || {}; | 
| 25 | 24 |  | 50 |  |  | 147 | my $construct_subs = $opts{constructors} || [defined($opts{constructor}) ? $opts{constructor} : ()]; | 
| 26 | 24 |  | 100 |  |  | 107 | my $true_subs      = $opts{true} || []; | 
| 27 | 24 |  | 100 |  |  | 123 | my $false_subs     = $opts{false} || []; | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 24 |  |  |  |  | 161 | foreach my $subtype ( ["getter", $read_subs], | 
| 31 |  |  |  |  |  |  | ["setter", $set_subs], | 
| 32 |  |  |  |  |  |  | ["accessor", $acc_subs], | 
| 33 |  |  |  |  |  |  | ["lvalue_accessor", $lvacc_subs], | 
| 34 |  |  |  |  |  |  | ["pred_subs", $pred_subs] ) | 
| 35 |  |  |  |  |  |  | { | 
| 36 | 116 |  |  |  |  | 168 | my $subs = $subtype->[1]; | 
| 37 | 116 |  |  |  |  | 327 | foreach my $subname (keys %$subs) { | 
| 38 | 43 |  |  |  |  | 65 | my $array_index = $subs->{$subname}; | 
| 39 | 43 |  |  |  |  | 119 | _generate_method($caller_pkg, $subname, $array_index, \%opts, $subtype->[0]); | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 23 |  |  |  |  | 116 | foreach my $subtype ( ["constructor", $construct_subs], | 
| 44 |  |  |  |  |  |  | ["true", $true_subs], | 
| 45 |  |  |  |  |  |  | ["false", $false_subs] ) | 
| 46 |  |  |  |  |  |  | { | 
| 47 | 69 |  |  |  |  | 72 | foreach my $subname (@{$subtype->[1]}) { | 
|  | 69 |  |  |  |  | 5663 |  | 
| 48 | 11 |  |  |  |  | 44 | _generate_method($caller_pkg, $subname, "", \%opts, $subtype->[0]); | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | sub _generate_method { | 
| 54 | 54 |  |  | 54 |  | 108 | my ($caller_pkg, $subname, $array_index, $opts, $type) = @_; | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 54 | 50 |  |  |  | 122 | croak("Cannot use undef as a array index for generating an XS $type accessor. (Sub: $subname)") | 
| 57 |  |  |  |  |  |  | if not defined $array_index; | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 54 | 50 |  |  |  | 216 | $subname = "${caller_pkg}::$subname" if $subname !~ /::/; | 
| 60 |  |  |  |  |  |  |  | 
| 61 | 54 | 100 |  |  |  | 265 | Class::XSAccessor::Heavy::check_sub_existence($subname) if not $opts->{replace}; | 
| 62 | 11 |  |  | 11 |  | 66 | no warnings 'redefine'; # don't warn about an explicitly requested redefine | 
|  | 11 |  |  |  |  | 23 |  | 
|  | 11 |  |  |  |  | 2248 |  | 
| 63 |  |  |  |  |  |  |  | 
| 64 | 53 | 100 |  |  |  | 124 | if ($type eq 'getter') { | 
| 65 | 20 |  |  |  |  | 430 | newxs_getter($subname, $array_index); | 
| 66 |  |  |  |  |  |  | } | 
| 67 | 53 | 100 |  |  |  | 277 | if ($type eq 'lvalue_accessor') { | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
| 68 | 1 |  |  |  |  | 45 | newxs_lvalue_accessor($subname, $array_index); | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  | elsif ($type eq 'setter') { | 
| 71 | 11 |  | 100 |  |  | 180 | newxs_setter($subname, $array_index, $opts->{chained}||0); | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  | elsif ($type eq 'predicate') { | 
| 74 | 0 |  |  |  |  | 0 | newxs_predicate($subname, $array_index); | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  | elsif ($type eq 'constructor') { | 
| 77 | 3 |  |  |  |  | 28 | newxs_constructor($subname); | 
| 78 |  |  |  |  |  |  | } | 
| 79 |  |  |  |  |  |  | elsif ($type eq 'true') { | 
| 80 | 4 |  |  |  |  | 46 | Class::XSAccessor::newxs_boolean($subname, 1); | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  | elsif ($type eq 'false') { | 
| 83 | 4 |  |  |  |  | 65 | Class::XSAccessor::newxs_boolean($subname, 0); | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  | else { | 
| 86 | 30 |  | 100 |  |  | 518 | newxs_accessor($subname, $array_index, $opts->{chained}||0); | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  | } | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | 1; | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | __END__ |