Quiq/Reference.pm

filter: Statementstmt 100% 37 / 37 Branchbran 100% 10 / 10 Conditioncond 85.7% 12 / 14 MC/DCmcdc 77.7% 7 / 9 Subroutinesub 100% 12 / 12 Podpod 100% 6 / 6 totaltotal 95.4% 84 / 88 CC 11 SCAR 8.2
CC
11
Cov
97%
isHashRef
3.0
isCodeRef
3.0
isArrayRef
3.0
CRAP 2.3
« Quiq/Test/Class/Method.pm ↑ Summary Quiq/List.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Reference - Operationen auf Referenzen
8  
9 =head1 DESCRIPTION
10  
11 Die Klasse stellt Methoden auf Referenzen zur Verfügung, insbesondere,
12 um den Grundtyp einer Referenz zu ermitteln.
13  
14 =cut
15  
16 # -----------------------------------------------------------------------------
17  
18 package Quiq::Reference;
19  
20 270 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 270 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 270 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 270 our $VERSION = '1.240';
25  
26 270 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 # -----------------------------------------------------------------------------
29  
30 =head1 METHODS
31  
32 =head2 Klassenmethoden
33  
34 =head3 refType() - Liefere Grundtyp der Referenz
35  
36 =head4 Synopsis
37  
38 $refType = $class->refType($ref);
39  
40 =head4 Alias
41  
42 reftype()
43  
44 =head4 Description
45  
46 Ist $ref eine Referenz, liefere den Grundtyp der Referenz. Ist $ref
47 keine Referenz, liefere einen Leerstring.
48  
49 Grundtypen sind:
50  
51 SCALAR
52 ARRAY
53 HASH
54 CODE
55 GLOB
56 IO
57 REF
58  
59 Details siehe: C<perldoc -f ref>.
60  
61 =cut
62  
63 # -----------------------------------------------------------------------------
64  
65 35 ▶sub refType {
Subroutine refType: called CC=2 SCAR=6.9
Pod documented
66 35 ▶ return Scalar::Util::reftype($_[1]) // '';
Condition100%2/2
builtin::reftype($_[1]) // ""
l!l
1025
MC/DC100%1/1
builtin::reftype($_[1]) // ""
builtin::reftype($_[1])
Truth table100%2/2
A
A= builtin::reftype($_[1])
Aresult
11
00
67 }
68  
69 {
70 270 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
71 270 *reftype = \&refType;
72 }
73  
74 # -----------------------------------------------------------------------------
75  
76 =head3 isBlessedRef() - Test, ob Referenz geblesst ist
77  
78 =head4 Synopsis
79  
80 $bool = $class->isBlessedRef($ref);
81  
82 =head4 Alias
83  
84 isBlessed()
85  
86 =cut
87  
88 # -----------------------------------------------------------------------------
89  
90 6 ▶sub isBlessedRef {
Subroutine isBlessedRef: called CC=2 SCAR=6.9
Pod documented
91 6 my ($class,$ref) = @_;
92 6 ▶ return Scalar::Util::blessed($ref)? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($ref) ? : 3 3 6
93 }
94  
95 {
96 270 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
97 270 *isBlessed = \&isBlessedRef;
98 }
99  
100 # -----------------------------------------------------------------------------
101  
102 =head3 isArrayRef() - Teste auf Array-Referenz
103  
104 =head4 Synopsis
105  
106 $bool = $class->isArrayRef($ref);
107  
108 =cut
109  
110 # -----------------------------------------------------------------------------
111  
112 29 ▶sub isArrayRef {
Subroutine isArrayRef: called CC=3 SCAR=11.0
Pod documented
113 29 my ($class,$ref) = @_;
114 29 $ref = Scalar::Util::reftype($ref);
115 29 ▶ return defined $ref && $ref eq 'ARRAY'? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && $ref eq 'ARRAY' ? : 7 22 29
Condition100%3/3
defined $ref and $ref eq "ARRAY"
!ll&&!rl&&r
1937
MC/DC100%2/2
defined $ref and $ref eq "ARRAY"
defined $ref $ref eq "ARRAY"
Truth table100%3/3
A and B
A= defined $refB= $ref eq "ARRAY"
ABresult
0X0
100
111
116 }
117  
118 # -----------------------------------------------------------------------------
119  
120 =head3 isHashRef() - Teste auf Hash-Referenz
121  
122 =head4 Synopsis
123  
124 $bool = $class->isHashRef($ref);
125  
126 =cut
127  
128 # -----------------------------------------------------------------------------
129  
130 4 ▶sub isHashRef {
Subroutine isHashRef: called CC=3 SCAR=11.0
Pod documented
131 4 my ($class,$ref) = @_;
132 4 $ref = Scalar::Util::reftype($ref);
133 4 ▶ return defined $ref && $ref eq 'HASH'? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && $ref eq 'HASH' ? : 1 3 4
Condition66%2/3
defined $ref and $ref eq "HASH"
!ll&&!rl&&r
301
MC/DC50%1/2
defined $ref and $ref eq "HASH"
defined $ref $ref eq "HASH"
Truth table66%2/3
A and B
A= defined $refB= $ref eq "HASH"
ABresult
0X0
100
111
134 }
135  
136 # -----------------------------------------------------------------------------
137  
138 =head3 isCodeRef() - Teste auf Code-Referenz
139  
140 =head4 Synopsis
141  
142 $bool = $class->isCodeRef($ref);
143  
144 =cut
145  
146 # -----------------------------------------------------------------------------
147  
148 8 ▶sub isCodeRef {
Subroutine isCodeRef: called CC=3 SCAR=11.0
Pod documented
149 8 my ($class,$ref) = @_;
150 8 $ref = Scalar::Util::reftype($ref);
151 8 ▶ return defined $ref && $ref eq 'CODE'? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && $ref eq 'CODE' ? : 4 4 8
Condition66%2/3
defined $ref and $ref eq "CODE"
!ll&&!rl&&r
044
MC/DC50%1/2
defined $ref and $ref eq "CODE"
defined $ref $ref eq "CODE"
Truth table66%2/3
A and B
A= defined $refB= $ref eq "CODE"
ABresult
0X0
100
111
152 }
153  
154 # -----------------------------------------------------------------------------
155  
156 =head3 isRegexRef() - Teste auf Regex-Referenz
157  
158 =head4 Synopsis
159  
160 $bool = $class->isRegexRef($ref);
161  
162 =head4 Caveats
163  
164 Wenn die Regex-Referenz umgeblesst wurde, muss sie auf
165 eine Subklasse von Regex geblesst worden sein, sonst schlägt
166 der Test fehl. Aktuell gibt es nicht den Grundtyp REGEX, der
167 von reftype() geliefert würde, sondern eine Regex-Referenz gehört
168 standardmäßig zu der Klasse Regex.
169  
170 =cut
171  
172 # -----------------------------------------------------------------------------
173  
174 3 ▶sub isRegexRef {
Subroutine isRegexRef: called CC=3 SCAR=11.0
Pod documented
175 3 my ($class,$ref) = @_;
176 3 ▶ return Scalar::Util::blessed($ref) && $ref->isa('Regexp')? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($ref) && $ref->isa('Regexp') ? : 1 2 3
Condition100%3/3
builtin::blessed($ref) and $ref->isa("Regexp")
!ll&&!rl&&r
111
MC/DC100%2/2
builtin::blessed($ref) and $ref->isa("Regexp")
builtin::blessed($ref) $ref->isa("Regexp")
Truth table100%3/3
A and B
A= builtin::blessed($ref)B= $ref->isa("Regexp")
ABresult
0X0
100
111
177 }
178  
179 # -----------------------------------------------------------------------------
180  
181 =head1 VERSION
182  
183 1.240
184  
185 =head1 AUTHOR
186  
187 Frank Seitz, L<http://fseitz.de/>
188  
189 =head1 COPYRIGHT
190  
191 Copyright (C) 2026 Frank Seitz
192  
193 =head1 LICENSE
194  
195 This code is free software; you can redistribute it and/or modify
196 it under the same terms as Perl itself.
197  
198 =cut
199  
200 # -----------------------------------------------------------------------------
201  
202 270 1;
203  
204 # eof
« Quiq/Test/Class/Method.pm ↑ Summary Quiq/List.pm »