| 1 | 6 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | package Types::ReadOnly; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | our $VERSION = '0.003'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Type::Tiny 1.006000 (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Type::Coercion (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Types::Standard qw( Any Dict HashRef Ref ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Type::Library -base, -declare => qw( ReadOnly Locked ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use Scalar::Util qw( reftype blessed refaddr ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | sub _dclone($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dclone: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | require Storable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | *_dclone = \&Storable::dclone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | goto &Storable::dclone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | my %skip = map { $_ => 1 } qw/CODE GLOB/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 16 | ▶ | sub _make_readonly { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_readonly: called CC=13 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 16 | my (undef, $dont_clone) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 16 | ▶ | if (my $reftype = reftype $_[0] and not blessed($_[0]) and not &Internals::SvREADONLY($_[0])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
my $reftype = builtin::reftype($_[0]) and not builtin::blessed($_[0]) and not &Internals::SvREADONLY($_[0])
my $reftype = builtin::reftype($_[0]) and not builtin::blessed($_[0])
MC/DC66%2/3
my $reftype = builtin::reftype($_[0]) and not builtin::blessed($_[0]) and not &Internals::SvREADONLY($_[0])
my $reftype = builtin::reftype($_[0])
not builtin::blessed($_[0])
not &Internals::SvREADONLY($_[0])
Truth table75%3/4
A and not(B) and not(C)
A= my $reftype = builtin::reftype($_[0])B= not builtin::blessed($_[0])C= not &Internals::SvREADONLY($_[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 6 | ▶ | $_[0] = _dclone($_[0]) if !$dont_clone && &Internals::SvREFCNT($_[0]) > 1 && !$skip{$reftype}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $dont_clone and &Internals::SvREFCNT($_[0]) > 1 and not $skip{$reftype}
not $dont_clone and &Internals::SvREFCNT($_[0]) > 1
MC/DC33%1/3
not $dont_clone and &Internals::SvREFCNT($_[0]) > 1 and not $skip{$reftype}
not $dont_clone
&Internals::SvREFCNT($_[0]) > 1
not $skip{$reftype}
Truth table50%2/4
not(A) and B and not(C)
A= not $dont_cloneB= &Internals::SvREFCNT($_[0]) > 1C= not $skip{$reftype}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 6 | &Internals::SvREADONLY($_[0], 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | ▶ | if ($reftype eq 'SCALAR' or $reftype eq 'REF') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
$reftype eq "SCALAR" or $reftype eq "REF"
MC/DC0%0/2
$reftype eq "SCALAR" or $reftype eq "REF"
$reftype eq "SCALAR"
$reftype eq "REF"
Truth table33%1/3
A or B
A= $reftype eq "SCALAR"B= $reftype eq "REF"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | _make_readonly(${ $_[0] }, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | elsif ($reftype eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | _make_readonly($_) for @{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | elsif ($reftype eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | &Internals::hv_clear_placeholders($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | _make_readonly($_) for values %{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 16 | Internals::SvREADONLY($_[0], 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | __PACKAGE__->meta->add_type({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | name => 'ReadOnly', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | parent => Ref, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | ▶ | constraint => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=20.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 9 | my $r = reftype($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 9 | ▶ | ($r eq 'HASH' or $r eq 'ARRAY' or $r eq 'SCALAR' or $r eq 'REF') and &Internals::SvREADONLY($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
$r eq "HASH" or $r eq "ARRAY" or $r eq "SCALAR" or $r eq "REF"
$r eq "HASH" or $r eq "ARRAY" or $r eq "SCALAR"
$r eq "HASH" or $r eq "ARRAY"
MC/DC0%0/4
$r eq "HASH" or $r eq "ARRAY" or $r eq "SCALAR" or $r eq "REF"
$r eq "HASH"
$r eq "ARRAY"
$r eq "SCALAR"
$r eq "REF"
Truth table40%2/5
A or B or C or D
A= $r eq "HASH"B= $r eq "ARRAY"C= $r eq "SCALAR"D= $r eq "REF"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | ▶ | constraint_generator => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 4 | ▶ | my ($parameter) = @_ or return $Type::Tiny::parameterize_type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | $parameter->compiled_check; # only need this because parent constraint (i.e. ReadOnly) is automatically checked | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 44 | ▶ | inlined => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 44 | my ($self, $varname) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 44 | sprintf('do { my $r = Scalar::Util::reftype(%s); $r eq "HASH" or $r eq "ARRAY" or $r eq "SCALAR" or $r eq "REF" }', $varname), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | sprintf('&Internals::SvREADONLY(%s)', $varname), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | ▶ | inline_generator => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | ▶ | my ($parameter) = @_ or return $Type::Tiny::parameterize_type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 4 | ▶ | return unless $parameter->can_be_inlined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 26 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 26 | my ($child, $varname) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 26 | my $me = $child->parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 26 | return ($me->inline_check($varname), $parameter->inline_check($varname)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | coercion => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | Ref ,=> 'do { Types::ReadOnly::_make_readonly(my $ro = $_); $ro }', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 4 | ▶ | coercion_generator => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | my ($me, $child) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 4 | my $parameter = $child->type_parameter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 4 | my @extra; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 4 | ▶ | if ($parameter->has_coercion) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 3 | my @map = @{ $parameter->coercion->type_coercion_map }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | ▶ | while (@map) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | my ($t, $code) = splice @map, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | ▶ | if (Types::TypeTiny::CodeLike->check($code)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | push @extra, $t, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | my $coerced = $code->(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | Types::ReadOnly::_make_readonly($coerced); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | $coerced; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | push @extra, $t, sprintf('do { my $coerced = %s; Types::ReadOnly::_make_readonly($coerced); $coerced }', $code); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | bless( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | { type_coercion_map => [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | $parameter => 'do { Types::ReadOnly::_make_readonly(my $ro = $_); $ro }', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | @extra, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 'Type::Coercion' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 6 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 20 | ▶ | my $_FIND_KEYS = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | my ($dict) = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 20 | ▶ | $_->is_parameterized | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$_->is_parameterized && $_->has_parent && $_->parent->strictly_equals(&Dict())
$_->is_parameterized and $_->has_parent
MC/DC66%2/3
$_->is_parameterized && $_->has_parent && $_->parent->strictly_equals(&Dict())
$_->is_parameterized
$_->has_parent
$_->parent->strictly_equals(&Dict())
Truth table75%3/4
A and B && C
A= $_->is_parameterizedB= $_->has_parentC= $_->parent->strictly_equals(&Dict())
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | and $_->has_parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | and $_->parent->strictly_equals(Dict) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } $_[0], $_[0]->parents; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 20 | ▶ | return unless $dict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 15 | ▶ | return if ref($dict->parameters->[-1]) eq q(HASH); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 15 | my @keys = sort keys %{ +{ @{ $dict->parameters } } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 15 | ▶ | return unless @keys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 15 | \@keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # Stolen from Hash::Util 0.15. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # In earlier versions, of Hash::Util, there is only a hashref_unlocked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # function, which happens to be very broken. :-/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 3 | ▶ | sub _hashref_locked { &Internals::SvREADONLY($_[0]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hashref_locked: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | __PACKAGE__->meta->add_type({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | name => 'Locked', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | parent => Ref['HASH'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 6 | ▶ | constraint => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | my $r = reftype($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 6 | &Internals::SvREADONLY($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 7 | ▶ | constraint_generator => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 7 | ▶ | my ($parameter) = @_ or return $Type::Tiny::parameterize_type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 7 | my $pchk = $parameter->compiled_check; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 7 | ▶ | my $KEYS = $parameter->$_FIND_KEYS or return $pchk; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 5 | my $keys = join "*#*", @$KEYS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 3 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 3 | my $legal = join "*#*", sort(&Hash::Util::legal_keys($_)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 3 | ▶ | return if $keys ne $legal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | goto $pchk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 90 | ▶ | inlined => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 90 | my ($self, $varname) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 90 | my $r = Ref['HASH']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 90 | $r->inline_check($varname), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | sprintf('&Internals::SvREADONLY(%s)', $varname), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 7 | ▶ | inline_generator => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 7 | require Hash::Util; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 7 | ▶ | my ($parameter) = @_ or return $Type::Tiny::parameterize_type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 7 | ▶ | return unless $parameter->can_be_inlined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 7 | my $KEYS = $parameter->$_FIND_KEYS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 7 | ▶ | my $keys = join "*#*", @{ $KEYS || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$KEYS || []
MC/DC100%1/1
$KEYS || []
$KEYS
Truth table100%2/2
A
A= $KEYS
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 66 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 66 | my ($child, $varname) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 66 | my @extras; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 66 | ▶ | if ($keys) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 34 | require Hash::Util; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 34 | push @extras, sprintf('%s eq join("*#*", sort(&Hash::Util::legal_keys(%s)))', B::perlstring($keys), $varname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 66 | (undef, @extras, $parameter->inline_check($varname)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | coercion => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | Ref['HASH'] , => 'do { Types::ReadOnly::_make_readonly(my $ro = $_); $ro }', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 6 | ▶ | coercion_generator => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 6 | require Hash::Util; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 6 | my ($me, $child) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 6 | my $parameter = $child->type_parameter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 6 | my $KEYS = $parameter->$_FIND_KEYS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 6 | ▶ | my $qkeys = $KEYS ? join(q[,], '', map B::perlstring($_), @$KEYS) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 6 | my @extra; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 6 | ▶ | if ($parameter->has_coercion) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 2 | my @map = @{ $parameter->coercion->type_coercion_map }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | ▶ | while (@map) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 2 | my ($t, $code) = splice @map, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 2 | ▶ | if (Types::TypeTiny::CodeLike->check($code)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | push @extra, $t, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my $coerced = $code->(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | &Hash::Util::unlock_hash($coerced); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | &Hash::Util::lock_hash($coerced, @{$KEYS||[]}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$KEYS || []
MC/DC0%0/1
$KEYS || []
$KEYS
Truth table0%0/2
A
A= $KEYS
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | $coerced; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | push @extra, $t, sprintf('do { my $coerced = %s; &Hash::Util::unlock_hash($coerced); &Hash::Util::lock_keys($coerced %s); $coerced }', $code, $qkeys); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | bless( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 6 | { type_coercion_map => [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | $parameter => sprintf('do { my $coerced = $_; &Hash::Util::unlock_hash($coerced); &Hash::Util::lock_keys($coerced %s); $coerced }', $qkeys), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | @extra, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | ] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 'Type::Coercion' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 6 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # This comparator allows Locked[Foo] to be seen as a child of Foo, and not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # just a child of Locked. It's probably not foolproof. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 6 | my $comparator; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 3 | ▶ | $comparator = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=28.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 3 | my $A = shift->find_constraining_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 3 | my $B = shift->find_constraining_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 3 | my $RO = __PACKAGE__->get_type('ReadOnly'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 3 | my $L = __PACKAGE__->get_type('Locked'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 3 | ▶ | my $Aprime = $A->find_parent(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 3 | ▶ | $_->is_parameterized and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$_->is_parameterized && $_->has_parent && ($_->parent->strictly_equals($L) || $_->parent->strictly_equals($RO))
$_->is_parameterized and $_->has_parent
$_->parent->strictly_equals($L) or $_->parent->strictly_equals($RO)
MC/DC0%0/4
$_->is_parameterized && $_->has_parent && ($_->parent->strictly_equals($L) || $_->parent->strictly_equals($RO))
$_->is_parameterized
$_->has_parent
$_->parent->strictly_equals($L)
$_->parent->strictly_equals($RO)
Truth table20%1/5
A and B && C or D
A= $_->is_parameterizedB= $_->has_parentC= $_->parent->strictly_equals($L)D= $_->parent->strictly_equals($RO)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | $_->has_parent and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | $_->parent->strictly_equals($L) || $_->parent->strictly_equals($RO) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 3 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 3 | ▶ | if ($Aprime) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 3 | my $param = $Aprime->type_parameter->find_constraining_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 3 | ▶ | if ($param->is_a_type_of($B)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 3 | return Type::Tiny::CMP_SUBTYPE(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | return Type::Tiny::CMP_UNKNOWN() if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my $r = $comparator->($B, $A, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | return $r if ($r eq Type::Tiny::CMP_EQUIVALENT()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | return -$r if ($r eq Type::Tiny::CMP_SUPERTYPE() || $r eq Type::Tiny::CMP_SUBTYPE()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$r eq -1 or $r eq 1
MC/DC0%0/2
$r eq -1 or $r eq 1
$r eq -1
$r eq 1
Truth table0%0/3
A or B
A= $r eq -1B= $r eq 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | Type::Tiny::CMP_UNKNOWN(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 6 | push @Type::Tiny::CMP, $comparator; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||