| 1 | package Object::HashBase; | ||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 6 | our $VERSION = '0.017'; | |||||||||||||||||||||||||||
| 6 | 6 | our $HB_VERSION = $VERSION; | |||||||||||||||||||||||||||
| 7 | # The next line is for inlining | ||||||||||||||||||||||||||||
| 8 | # <-- START --> | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 6 | require Carp; | |||||||||||||||||||||||||||
| 11 | { | ||||||||||||||||||||||||||||
| 12 | 6 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 6 | $Carp::Internal{+__PACKAGE__} = 1; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | BEGIN { | ||||||||||||||||||||||||||||
| 17 | { | ||||||||||||||||||||||||||||
| 18 | # Make sure none of these get messed up. | ||||||||||||||||||||||||||||
| 19 | 6 | ▶ | local ($SIG{__DIE__}, $@, $?, $!, $^E); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=4 SCAR=16.8
| |||||||||||||||||||||||||||||
| 20 | 6 | ▶ | if (eval { require Class::XSAccessor; Class::XSAccessor->VERSION(1.19); 1 }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | *CLASS_XS_ACCESSOR = sub() { 1 } | ||||||||||||||||||||||||||||
| 22 | 6 | } | |||||||||||||||||||||||||||
| 23 | else { | ||||||||||||||||||||||||||||
| 24 | *CLASS_XS_ACCESSOR = sub() { 0 } | ||||||||||||||||||||||||||||
| 25 | 0 | } | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # these are not strictly equivalent, but for out use we don't care | ||||||||||||||||||||||||||||
| 29 | # about order | ||||||||||||||||||||||||||||
| 30 | *_isa = ($] >= 5.010 && require mro) ? \&mro::get_linear_isa : sub { | ||||||||||||||||||||||||||||
| 31 | 6 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my @packages = ($_[0]); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 33 | 0 | my %seen; | |||||||||||||||||||||||||||
| 34 | 0 | for my $package (@packages) { | |||||||||||||||||||||||||||
| 35 | 0 | push @packages, grep !$seen{$_}++, @{"$package\::ISA"}; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 0 | return \@packages; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 6 | ▶ | } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$] >= "5.01" and require mro
MC/DC0%0/2
$] >= "5.01" and require mro
$] >= "5.01"
require mro
Truth table33%1/3
A and B
A= $] >= "5.01"B= require mro
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | sub _is_role { | ||||||||||||||||||||||||||||
| 42 | 49 | ▶ | my $pkg = shift; | ||||||||||||||||||||||||||
|
Subroutine
_is_role: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 43 | 49 | ▶ | return 0 unless $INC{'Role/Tiny.pm'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 19 | ▶ | return Role::Tiny->is_role($pkg) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 6 | my %SPEC = ( | |||||||||||||||||||||||||||
| 48 | '^' => {reader => 1, writer => 0, dep_writer => 1, read_only => 0, strip => 1}, | ||||||||||||||||||||||||||||
| 49 | '-' => {reader => 1, writer => 0, dep_writer => 0, read_only => 1, strip => 1}, | ||||||||||||||||||||||||||||
| 50 | '>' => {reader => 0, writer => 1, dep_writer => 0, read_only => 0, strip => 1}, | ||||||||||||||||||||||||||||
| 51 | '<' => {reader => 1, writer => 0, dep_writer => 0, read_only => 0, strip => 1}, | ||||||||||||||||||||||||||||
| 52 | '+' => {reader => 0, writer => 0, dep_writer => 0, read_only => 0, strip => 1}, | ||||||||||||||||||||||||||||
| 53 | '~' => {reader => 1, writer => 1, dep_writer => 0, read_only => 0, strip => 1, no_xs => 1}, | ||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 70 | ▶ | sub spec { \%SPEC } | ||||||||||||||||||||||||||
|
Subroutine
spec: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub import { | ||||||||||||||||||||||||||||
| 59 | 50 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | 50 | my $into = caller; | |||||||||||||||||||||||||||
| 61 | 50 | $class->do_import($into, @_); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | sub do_import { | ||||||||||||||||||||||||||||
| 65 | 50 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
do_import: called CC=41 SCAR=39.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | 50 | my $into = shift; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # Make sure we list the OLDEST version used to create this class. | ||||||||||||||||||||||||||||
| 69 | 50 | ▶ | my $ver = $Object::HashBase::HB_VERSION || $Object::HashBase::VERSION; | ||||||||||||||||||||||||||
|
Condition33%1/3
$Object::HashBase::HB_VERSION || $VERSION
MC/DC0%0/2
$Object::HashBase::HB_VERSION || $VERSION
$Object::HashBase::HB_VERSION
$VERSION
Truth table33%1/3
A || B
A= $Object::HashBase::HB_VERSIONB= $VERSION
| |||||||||||||||||||||||||||||
| 70 | 50 | ▶ | $Object::HashBase::VERSION{$into} = $ver if !$Object::HashBase::VERSION{$into} || $Object::HashBase::VERSION{$into} > $ver; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $Object::HashBase::VERSION{$into} or $Object::HashBase::VERSION{$into} > $ver
MC/DC0%0/2
not $Object::HashBase::VERSION{$into} or $Object::HashBase::VERSION{$into} > $ver
not $Object::HashBase::VERSION{$into}
$Object::HashBase::VERSION{$into} > $ver
Truth table33%1/3
not(A) or B
A= not $Object::HashBase::VERSION{$into}B= $Object::HashBase::VERSION{$into} > $ver
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 50 | my (@parents, @roles, @attrs); | |||||||||||||||||||||||||||
| 73 | 50 | for my $arg (@_) { | |||||||||||||||||||||||||||
| 74 | 85 | ▶ | if (defined($arg) && length($arg)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $arg and length $arg
MC/DC0%0/2
defined $arg and length $arg
defined $arg
length $arg
Truth table33%1/3
A and B
A= defined $argB= length $arg
| |||||||||||||||||||||||||||||
| 75 | 85 | my $p = substr($arg, 0, 1); | |||||||||||||||||||||||||||
| 76 | 85 | ▶ | if ($p eq '@') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 4 | push @parents, substr($arg, 1); | |||||||||||||||||||||||||||
| 78 | 4 | next; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 81 | ▶ | if ($p eq '&') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 11 | push @roles, substr($arg, 1); | |||||||||||||||||||||||||||
| 82 | 11 | next; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 70 | push @attrs, $arg; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 50 | for my $parent (@parents) { | |||||||||||||||||||||||||||
| 89 | 4 | my $pm = $parent; | |||||||||||||||||||||||||||
| 90 | 4 | $pm =~ s{::}{/}g; | |||||||||||||||||||||||||||
| 91 | 4 | $pm .= '.pm'; | |||||||||||||||||||||||||||
| 92 | 4 | ▶ | unless ($INC{$pm}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 1 | local ($@); | |||||||||||||||||||||||||||
| 94 | 1 | ▶ | unless (eval { require $pm; 1 }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 1 | Carp::croak("Could not load parent class '$parent': $@"); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 6 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 99 | 3 | ▶ | push @{"$into\::ISA"}, $parent unless grep { $_ eq $parent } @{"$into\::ISA"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 49 | my $isa = _isa($into); | |||||||||||||||||||||||||||
| 103 | 49 | ▶ | my $attr_list = $Object::HashBase::ATTR_LIST{$into} ||= []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$Object::HashBase::ATTR_LIST{$into} ||= []
MC/DC0%0/1
$Object::HashBase::ATTR_LIST{$into} ||= []
$Object::HashBase::ATTR_LIST{$into}
Truth table50%1/2
A
A= $Object::HashBase::ATTR_LIST{$into}
| |||||||||||||||||||||||||||||
| 104 | 49 | ▶ | my $attr_subs = $Object::HashBase::ATTR_SUBS{$into} ||= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$Object::HashBase::ATTR_SUBS{$into} ||= {}
MC/DC0%0/1
$Object::HashBase::ATTR_SUBS{$into} ||= {}
$Object::HashBase::ATTR_SUBS{$into}
Truth table50%1/2
A
A= $Object::HashBase::ATTR_SUBS{$into}
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 49 | my @pre_init; | |||||||||||||||||||||||||||
| 107 | my @post_init; | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 49 | ▶ | my $add_new = _is_role($into) ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 49 | ▶ | if ($add_new && (my $have_new = $into->can('new'))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$add_new and my $have_new = $into->can("new")
MC/DC100%2/2
$add_new and my $have_new = $into->can("new")
$add_new
my $have_new = $into->can("new")
Truth table100%3/3
A and B
A= $add_newB= my $have_new = $into->can("new")
| |||||||||||||||||||||||||||||
| 112 | 11 | ▶ | my $new_lookup = $Object::HashBase::NEW_LOOKUP //= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$Object::HashBase::NEW_LOOKUP //= {}
MC/DC0%0/1
$Object::HashBase::NEW_LOOKUP //= {}
$Object::HashBase::NEW_LOOKUP
Truth table50%1/2
A
A= $Object::HashBase::NEW_LOOKUP
| |||||||||||||||||||||||||||||
| 113 | 11 | ▶ | $add_new = 0 unless $new_lookup->{$have_new}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | my %subs = ( | ||||||||||||||||||||||||||||
| 117 | ($add_new ? ($class->_build_new($into, \@pre_init, \@post_init)) : ()), | ||||||||||||||||||||||||||||
| 118 | 49 | ▶ | (map %{$Object::HashBase::ATTR_SUBS{$_} || {}}, @{$isa}[1 .. $#$isa]), | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 119 | ($class->args_to_subs($attr_list, $attr_subs, \@attrs, $into)), | ||||||||||||||||||||||||||||
| 120 | ); | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 6 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 123 | 49 | ▶ | while (my ($k, $v) = each %subs) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 413 | ▶ | if (ref($v) eq 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 286 | *{"$into\::$k"} = $v; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | else { | ||||||||||||||||||||||||||||
| 128 | 127 | my ($sub, @args) = @$v; | |||||||||||||||||||||||||||
| 129 | 127 | $sub->(@args); | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 49 | ▶ | if (@roles) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 10 | ▶ | Carp::croak("Object::HashBase '&' role prefix requires Perl 5.010 or newer (this is $])") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | if $] < 5.010; | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 10 | ▶ | unless ($INC{'Role/Tiny.pm'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 0 | local ($@); | |||||||||||||||||||||||||||
| 139 | 0 | ▶ | unless (eval { require Role::Tiny; 1 }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 0 | Carp::croak("Object::HashBase '&' role prefix requires Role::Tiny but it could not be loaded: $@"); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 10 | ▶ | unless (Role::Tiny->can('is_role')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | Carp::croak("Object::HashBase '&' role prefix requires Role::Tiny 1.003000 or newer (is_role missing)"); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 10 | for my $role (@roles) { | |||||||||||||||||||||||||||
| 149 | 11 | my $pm = $role; | |||||||||||||||||||||||||||
| 150 | 11 | $pm =~ s{::}{/}g; | |||||||||||||||||||||||||||
| 151 | 11 | $pm .= '.pm'; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 11 | ▶ | unless ($INC{$pm}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 1 | local ($@); | |||||||||||||||||||||||||||
| 155 | 1 | ▶ | unless (eval { require $pm; 1 }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 1 | Carp::croak("Could not load role '$role': $@"); | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 10 | ▶ | Carp::croak("'$role' is not a Role::Tiny role") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | unless Role::Tiny->is_role($role); | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | Carp::croak("'$role' does not use Object::HashBase") | ||||||||||||||||||||||||||||
| 164 | 9 | ▶ | unless exists $Object::HashBase::VERSION{$role}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 8 | ▶ | my $role_subs = $Object::HashBase::ATTR_SUBS{$role} || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$Object::HashBase::ATTR_SUBS{$role} || {}
MC/DC0%0/1
$Object::HashBase::ATTR_SUBS{$role} || {}
$Object::HashBase::ATTR_SUBS{$role}
Truth table50%1/2
A
A= $Object::HashBase::ATTR_SUBS{$role}
| |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 6 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 169 | 8 | for my $const (keys %$role_subs) { | |||||||||||||||||||||||||||
| 170 | 8 | ▶ | next if defined &{"$into\::$const"}; # keep existing sub, no override, no warn | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 6 | *{"$into\::$const"} = $role_subs->{$const}; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 8 | ▶ | my $role_attr_list = $Object::HashBase::ATTR_LIST{$role} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$Object::HashBase::ATTR_LIST{$role} || []
MC/DC0%0/1
$Object::HashBase::ATTR_LIST{$role} || []
$Object::HashBase::ATTR_LIST{$role}
Truth table50%1/2
A
A= $Object::HashBase::ATTR_LIST{$role}
| |||||||||||||||||||||||||||||
| 175 | 8 | ▶ | push @{$Object::HashBase::ROLE_ATTRS{$into} ||= []}, @$role_attr_list; | ||||||||||||||||||||||||||
|
Condition100%2/2
$Object::HashBase::ROLE_ATTRS{$into} ||= []
MC/DC100%1/1
$Object::HashBase::ROLE_ATTRS{$into} ||= []
$Object::HashBase::ROLE_ATTRS{$into}
Truth table100%2/2
A
A= $Object::HashBase::ROLE_ATTRS{$into}
| |||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 7 | my $key = "Object::HashBase::role_applier::$into"; | |||||||||||||||||||||||||||
| 179 | 7 | ▶ | my $applier = $^H{$key} ||= Object::HashBase::_RoleApplier->new($into); | ||||||||||||||||||||||||||
|
Condition33%1/3
$^H{$key} ||= "Object::HashBase::_RoleApplier"->new($into)
MC/DC0%0/2
$^H{$key} ||= "Object::HashBase::_RoleApplier"->new($into)
$^H{$key}
"Object::HashBase::_RoleApplier"->new($into)
Truth table33%1/3
A ||= B
A= $^H{$key}B= "Object::HashBase::_RoleApplier"->new($into)
| |||||||||||||||||||||||||||||
| 180 | 7 | $applier->add($_) for @roles; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | sub args_to_subs { | ||||||||||||||||||||||||||||
| 185 | 49 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
args_to_subs: called CC=16 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 186 | 49 | my ($attr_list, $attr_subs, $args, $into) = @_; | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 49 | my $use_gen = $class->can('gen_accessor') ; | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 49 | my %out; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 49 | ▶ | while (@$args) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 70 | my $x = shift @$args; | |||||||||||||||||||||||||||
| 194 | 70 | my $p = substr($x, 0, 1); | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 70 | ▶ | my $spec = $class->spec->{$p} || {reader => 1, writer => 1}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$class->spec->{$p} || {'reader', 1, 'writer', 1}
MC/DC100%1/1
$class->spec->{$p} || {'reader', 1, 'writer', 1}
$class->spec->{$p}
Truth table100%2/2
A
A= $class->spec->{$p}
| |||||||||||||||||||||||||||||
| 197 | 70 | ▶ | substr($x, 0, 1) = '' if $spec->{strip}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 70 | push @$attr_list => $x; | |||||||||||||||||||||||||||
| 200 | 70 | my ($sub, $attr) = (uc $x, $x); | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 70 | ▶ | $attr_subs->{$sub} = sub() { $attr }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 203 | 70 | $out{$sub} = $attr_subs->{$sub}; | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 70 | my $copy = "$attr"; | |||||||||||||||||||||||||||
| 206 | 70 | ▶ | if ($spec->{reader}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 66 | ▶ | if ($use_gen) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 208 | 0 | $out{$attr} = $class->gen_accessor(reader => $copy, $spec, $args); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | elsif (CLASS_XS_ACCESSOR && !$spec->{no_xs}) { | ||||||||||||||||||||||||||||
| 211 | 66 | $out{$attr} = [\&Class::XSAccessor::newxs_getter, "$into\::$attr", $copy]; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | else { | ||||||||||||||||||||||||||||
| 214 | 0 | ▶ | $out{$attr} = sub { $_[0]->{$attr} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 70 | ▶ | if ($spec->{writer}) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 219 | 61 | ▶ | if ($use_gen) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 220 | 0 | $out{"set_$attr"} = $class->gen_accessor(writer => $copy, $spec, $args); | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | elsif(CLASS_XS_ACCESSOR && !$spec->{no_xs}) { | ||||||||||||||||||||||||||||
| 223 | 61 | $out{"set_$attr"} = [\&Class::XSAccessor::newxs_setter, "$into\::set_$attr", $copy, 0]; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | else { | ||||||||||||||||||||||||||||
| 226 | 0 | ▶ | $out{"set_$attr"} = sub { $_[0]->{$attr} = $_[1] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | elsif($spec->{read_only}) { | ||||||||||||||||||||||||||||
| 230 | 3 | ▶ | $out{"set_$attr"} = $use_gen ? $class->gen_accessor(read_only => $copy, $spec, $args) : sub { Carp::croak("'$attr' is read-only") }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | elsif($spec->{dep_writer}) { | ||||||||||||||||||||||||||||
| 233 | 2 | ▶ | $out{"set_$attr"} = $use_gen ? $class->gen_accessor(dep_writer => $copy, $spec, $args) : sub { Carp::carp("set_$attr() is deprecated"); $_[0]->{$attr} = $_[1] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 70 | ▶ | if ($spec->{custom}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | 0 | my %add = $class->gen_accessor(custom => $copy, $spec, $args); | |||||||||||||||||||||||||||
| 238 | 0 | $out{$_} = $add{$_} for keys %add; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 49 | return %out; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | sub attr_list { | ||||||||||||||||||||||||||||
| 246 | 6 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
attr_list: called CC=8 SCAR=21.7
Pod
documented
| |||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 6 | my $isa = _isa($class); | |||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 6 | my %seen; | |||||||||||||||||||||||||||
| 251 | my @list; | ||||||||||||||||||||||||||||
| 252 | 6 | for my $pkg (reverse @$isa) { | |||||||||||||||||||||||||||
| 253 | 9 | ▶ | if (0.004 > ($Object::HashBase::VERSION{$pkg} || 0)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$Object::HashBase::VERSION{$pkg} || 0
MC/DC0%0/1
$Object::HashBase::VERSION{$pkg} || 0
$Object::HashBase::VERSION{$pkg}
Truth table50%1/2
A
A= $Object::HashBase::VERSION{$pkg}
| |||||||||||||||||||||||||||||
| 254 | 0 | Carp::carp("$pkg uses an inlined version of Object::HashBase too old to support attr_list()"); | |||||||||||||||||||||||||||
| 255 | 0 | next; | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | 9 | my $own = $Object::HashBase::ATTR_LIST{$pkg}; | |||||||||||||||||||||||||||
| 258 | 9 | ▶ | my $role_attrs = $Object::HashBase::ROLE_ATTRS{$pkg} || []; | ||||||||||||||||||||||||||
|
Condition100%2/2
$Object::HashBase::ROLE_ATTRS{$pkg} || []
MC/DC100%1/1
$Object::HashBase::ROLE_ATTRS{$pkg} || []
$Object::HashBase::ROLE_ATTRS{$pkg}
Truth table100%2/2
A
A= $Object::HashBase::ROLE_ATTRS{$pkg}
| |||||||||||||||||||||||||||||
| 259 | 9 | ▶ | for my $a (@$role_attrs, ($own ? @$own : ())) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | 21 | ▶ | push @list, $a unless $seen{$a}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 6 | return @list; | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | sub _build_new { | ||||||||||||||||||||||||||||
| 268 | 38 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_new: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||
| 269 | 38 | my ($into, $pre_init, $post_init) = @_; | |||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 38 | ▶ | my $add_pre_init = sub(&) { push @$pre_init => $_[-1] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 272 | 38 | ▶ | my $add_post_init = sub(&) { push @$post_init => $_[-1] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 38 | my $__pre_init = $into->can('_pre_init'); | |||||||||||||||||||||||||||
| 275 | 38 | ▶ | my $_pre_init = $__pre_init ? sub { ($__pre_init->(), @$pre_init) } : sub { @$pre_init }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 38 | my $__post_init = $into->can('_post_init'); | |||||||||||||||||||||||||||
| 278 | 38 | ▶ | my $_post_init = $__post_init ? sub { ($__post_init->(), @$post_init) } : sub { @$post_init }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | my $new = sub { | ||||||||||||||||||||||||||||
| 281 | 20 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 20 | my $self; | |||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 20 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 286 | 4 | my $arg = shift; | |||||||||||||||||||||||||||
| 287 | 4 | my $type = ref($arg); | |||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 4 | ▶ | if ($type eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | 1 | $self = bless({%$arg}, $class); | |||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | else { | ||||||||||||||||||||||||||||
| 293 | 3 | ▶ | Carp::croak("Not sure what to do with '$type' in $class constructor") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | unless $type eq 'ARRAY'; | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | 3 | my %proto; | |||||||||||||||||||||||||||
| 297 | 3 | my @attributes = attr_list($class); | |||||||||||||||||||||||||||
| 298 | 3 | ▶ | while (@$arg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | 11 | my $val = shift @$arg; | |||||||||||||||||||||||||||
| 300 | 11 | ▶ | my $key = shift @attributes or Carp::croak("Too many arguments for $class constructor"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | 10 | $proto{$key} = $val; | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | 2 | $self = bless(\%proto, $class); | |||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | else { | ||||||||||||||||||||||||||||
| 308 | 16 | $self = bless({@_}, $class); | |||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | $Object::HashBase::CAN_CACHE{$class} = $self->can('init') | ||||||||||||||||||||||||||||
| 312 | 19 | ▶ | unless exists $Object::HashBase::CAN_CACHE{$class}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 19 | $self->$_() for $_pre_init->(); | |||||||||||||||||||||||||||
| 315 | 19 | ▶ | $self->init() if $Object::HashBase::CAN_CACHE{$class}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 316 | 19 | $self->$_() for reverse $_post_init->(); | |||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 19 | $self; | |||||||||||||||||||||||||||
| 319 | 38 | }; | |||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 38 | ▶ | my $new_lookup = $Object::HashBase::NEW_LOOKUP //= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$Object::HashBase::NEW_LOOKUP //= {}
MC/DC100%1/1
$Object::HashBase::NEW_LOOKUP //= {}
$Object::HashBase::NEW_LOOKUP
Truth table100%2/2
A
A= $Object::HashBase::NEW_LOOKUP
| |||||||||||||||||||||||||||||
| 322 | 38 | $new_lookup->{$new} = 1; | |||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 38 | my %out; | |||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | { | ||||||||||||||||||||||||||||
| 327 | 6 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 328 | 38 | ▶ | $out{new} = $new unless defined(&{"${into}\::new"}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | 38 | ▶ | $out{add_pre_init} = $add_pre_init unless defined(&{"${into}\::add_pre_init"}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 330 | 38 | ▶ | $out{add_post_init} = $add_post_init unless defined(&{"${into}\::add_post_init"}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 38 | ▶ | $out{_pre_init} = $_pre_init unless defined(&{"${into}\::_pre_init"}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 332 | 38 | ▶ | $out{_post_init} = $_post_init unless defined(&{"${into}\::_post_init"}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 38 | return %out; | |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | # _RoleApplier — deferred Role::Tiny composition. | ||||||||||||||||||||||||||||
| 339 | # | ||||||||||||||||||||||||||||
| 340 | # Object::HashBase's '&' import prefix copies role constants into the consumer | ||||||||||||||||||||||||||||
| 341 | # eagerly (so `$self->{+FOO}` resolves at compile time), then defers actual | ||||||||||||||||||||||||||||
| 342 | # Role::Tiny->apply_roles_to_package to end of consumer's compile scope by | ||||||||||||||||||||||||||||
| 343 | # storing a blessed object in %^H. Perl destroys %^H entries at end of compile | ||||||||||||||||||||||||||||
| 344 | # scope, triggering DESTROY here, which finally composes the role(s). | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | package # hide from PAUSE indexer | ||||||||||||||||||||||||||||
| 347 | Object::HashBase::_RoleApplier; | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | sub new { | ||||||||||||||||||||||||||||
| 350 | 7 | ▶ | my ($class, $into) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 351 | 7 | return bless { into => $into, roles => [] }, $class; | |||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | sub add { | ||||||||||||||||||||||||||||
| 355 | 8 | ▶ | my ($self, $role) = @_; | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 356 | 8 | push @{$self->{roles}}, $role | |||||||||||||||||||||||||||
| 357 | 8 | ▶ | unless grep { $_ eq $role } @{$self->{roles}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | sub DESTROY { | ||||||||||||||||||||||||||||
| 361 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=4 SCAR=17.0
| |||||||||||||||||||||||||||||
| 362 | 7 | ▶ | return unless @{$self->{roles}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | 7 | local $@; | |||||||||||||||||||||||||||
| 364 | 7 | my $ok = eval { Role::Tiny->apply_roles_to_package($self->{into}, @{$self->{roles}}); 1 }; | |||||||||||||||||||||||||||
| 365 | 7 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | 0 | ▶ | my $err = $@ || 'unknown error'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'unknown error'
MC/DC0%0/1
$@ || 'unknown error'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||
| 367 | 0 | my $into = $self->{into}; | |||||||||||||||||||||||||||
| 368 | 0 | my $roles = join(', ', @{$self->{roles}}); | |||||||||||||||||||||||||||
| 369 | 0 | warn "Object::HashBase: failed to compose role(s) [$roles] into $into: $err"; | |||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 6 | 1; | |||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | __END__ | ||||||||||||||||||||||||||||