blib/lib/Zuzu/Weak.pm

filter: Statementstmt 100% 45 / 45 Branchbran 90.9% 20 / 22 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 5 / 5 totaltotal 97.7% 86 / 88 CC 13 SCAR 14.2
CC
13
Cov
97%
is_weakable_value
8.0
store_value
4.0
_assert_storage_ref
2.0
CRAP 4.1
« blib/lib/Zuzu/Value/Set.pm ↑ Summary blib/lib/Zuzu/Module/Task.pm »
1 package Zuzu::Weak;
2  
3 70 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 70 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 70 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 70 our $VERSION = '0.007002';
8  
9 70 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 70 ▶use Scalar::Util qw( blessed weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 70 our @EXPORT_OK = qw(
13 is_weakable_value
14 make_weak_value
15 resolve_weak_value
16 slot_value
17 store_value
18 );
19  
20 458 ▶sub is_weakable_value {
Subroutine is_weakable_value: called CC=8 SCAR=20.8
Pod documented
21 458 my ( $value ) = @_;
22  
23 458 ▶ return 0 if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 227 231 458
24 231 ▶ return 0 if !ref $value;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value 11 220 231
25 220 ▶ return 0 if ref($value) eq 'Regexp';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "Regexp" 0 220 220
26  
27 220 ▶ if ( blessed($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($value)) 217 3 220
28 217 ▶ return 0 if $value->isa('Zuzu::Value::Boolean');
Branch: 1 branch
BranchTrueFalseTotal
if $value->isa("Zuzu::Value::Boolean") 2 215 217
29 215 ▶ return 0 if $value->isa('Zuzu::Value::BinaryString');
Branch: 1 branch
BranchTrueFalseTotal
if $value->isa("Zuzu::Value::BinaryString") 2 213 215
30 213 ▶ return 0 if $value->isa('Zuzu::Value::Regexp');
Branch: 1 branch
BranchTrueFalseTotal
if $value->isa("Zuzu::Value::Regexp") 1 212 213
31 }
32  
33 215 return 1;
34 }
35  
36 18 ▶sub make_weak_value {
Subroutine make_weak_value: called CC=1 SCAR=0.0
Pod documented
37 18 my ( $value ) = @_;
38  
39 18 return $value;
40 }
41  
42 18 ▶sub resolve_weak_value {
Subroutine resolve_weak_value: called CC=1 SCAR=0.0
Pod documented
43 18 my ( $value ) = @_;
44  
45 18 return $value;
46 }
47  
48 26367 ▶sub _assert_storage_ref {
Subroutine _assert_storage_ref: called CC=2 SCAR=7.0
49 26367 my ( $slot_ref, $context ) = @_;
50  
51 26367 my $ok = eval {
52 26367 my $unused = $$slot_ref;
53 26367 1;
54 };
55 26367 ▶ die "$context requires a scalar reference" if !$ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 26367 26367
56  
57 26367 return;
58 }
59  
60 130957 ▶sub store_value {
Subroutine store_value: called CC=4 SCAR=13.9
Pod documented
61 130957 my ( $slot_ref, $value, $is_weak ) = @_;
62  
63 130957 ▶ _assert_storage_ref( $slot_ref, 'Weak storage' )
Branch: 1 branch
BranchTrueFalseTotal
if ref $slot_ref ne "SCALAR" 1399 129558 130957
64 if ref($slot_ref) ne 'SCALAR';
65  
66 130957 $$slot_ref = $value;
67 130957 ▶ weaken($$slot_ref)
Branch: 1 branch
BranchTrueFalseTotal
if $is_weak and is_weakable_value($value) 202 130755 130957
Condition100%3/3
$is_weak and is_weakable_value($value)
!ll&&!rl&&r
130518237202
MC/DC100%2/2
$is_weak and is_weakable_value($value)
$is_weak is_weakable_value($value)
Truth table100%3/3
A and B
A= $is_weakB= is_weakable_value($value)
ABresult
0X0
100
111
68 if $is_weak && is_weakable_value($value);
69  
70 130957 return $value;
71 }
72  
73 59102 ▶sub slot_value {
Subroutine slot_value: called CC=2 SCAR=6.9
Pod documented
74 59102 my ( $slot_ref ) = @_;
75  
76 59102 ▶ _assert_storage_ref( $slot_ref, 'Weak storage read' )
Branch: 1 branch
BranchTrueFalseTotal
if ref $slot_ref ne "SCALAR" 24968 34134 59102
77 if ref($slot_ref) ne 'SCALAR';
78  
79 59102 return $$slot_ref;
80 }
81  
82 70 1;
83  
84 =pod
85  
86 =head1 NAME
87  
88 Zuzu::Weak - weak-reference classification helpers
89  
90 =head1 DESCRIPTION
91  
92 Provides the shared Perl-side classification for values that may later
93 be stored through weak-storage rules. The classification is based on
94 ZuzuScript semantics rather than host implementation details.
95  
96 =head1 FUNCTIONS
97  
98 =head2 is_weakable_value( $value )
99  
100 Returns true for reference-capable Zuzu values and false for scalar Zuzu
101 values. C<null>, booleans, numbers, strings, binary strings, and
102 regular expressions are scalar values and are never weakened.
103  
104 =head2 make_weak_value( $value )
105  
106 Compatibility helper for code that needs a value-level API. Perl weak
107 storage must weaken the target scalar itself, so new storage code should
108 use C<store_value> instead.
109  
110 =head2 resolve_weak_value( $value )
111  
112 Returns the value unchanged. Perl weak storage resolves through the
113 target scalar itself.
114  
115 =head2 store_value( $slot_ref, $value, $is_weak )
116  
117 Stores C<$value> into C<$slot_ref>. When C<$is_weak> is true and the
118 value is weakable from ZuzuScript's perspective, weakens the stored
119 reference in that slot.
120  
121 =head2 slot_value( $slot_ref )
122  
123 Reads a storage scalar. A dead Perl weak reference naturally reads as
124 C<undef>, matching the core weak-storage representation.
125  
126 =head1 COPYRIGHT AND LICENCE
127  
128 B<< Zuzu::Weak >> is copyright Toby Inkster.
129  
130 It is free software; you may redistribute it and/or modify it under
131 the terms of either the Artistic License 1.0 or the GNU General Public
132 License version 2.
133  
134 =cut
« blib/lib/Zuzu/Value/Set.pm ↑ Summary blib/lib/Zuzu/Module/Task.pm »