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