lib/Chj/Class/Array.pm

filter: Statementstmt 41.2% 175 / 424 Branchbran 33.8% 69 / 204 Conditioncond 33.3% 24 / 72 MC/DCmcdc 8.8% 4 / 45 Subroutinesub 32.4% 24 / 74 Podpod 0.0% 0 / 15 totaltotal 35.4% 296 / 834 CC 137 SCAR 57.4
CC
137
Cov
38%
import
988.0
transport
421.9
alias_fields
61.8
CRAP 311.1
« lib/FP/Repl/Repl.pm ↑ Summary lib/Chj/Class/methodnames.pm »
1  
2 ### This is a COPY from the file in the repository at
3 ### https://github.com/pflanze/Class-Array with the sole purpose to
4 ### make it easier to use chj-perllib; see original repo for the
5 ### complete thing including docs.
6  
7 package Chj::Class::Array;
8  
9 # Copyright 2001-2008 by Christian Jaeger, copying@christianjaeger.ch
10 #
11 # This is free software, offered under either the same terms as perl 5
12 # or the terms of the Artistic License version 2 or the terms of the
13 # MIT License (Expat version). See the file COPYING.md that came
14 # bundled with this file.
15  
16 #$VERSION = '0.10pre1';
17  
18 80 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 80 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 80 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 80 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 #use constant DEBUG => 0;
24 80 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=12.0
25 80 ▶ eval 'sub DEBUG () {' . ((!!$ENV{CLASS_ARRAY_DEBUG}) || 0) . '}';
Condition50%1/2
!!$ENV{'CLASS_ARRAY_DEBUG'} || 0
l!l
080
MC/DC0%0/1
!!$ENV{'CLASS_ARRAY_DEBUG'} || 0
!!$ENV{'CLASS_ARRAY_DEBUG'}
Truth table50%1/2
A
A= !!$ENV{'CLASS_ARRAY_DEBUG'}
Aresult
11
00
26 80 ▶ die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 80 80
27 }
28 80 $| = 1 if DEBUG;
29  
30 #use enum qw(PUBLIC PROTECTED PRIVATE);
31 sub PUBLIC () {0}
32 sub PROTECTED () {1}
33 sub PRIVATE () {2}; # enum is not in the base perl 5.005 dist
34 sub PUBLICA () {3}; # (new 04/10/31) public only via accessors, not via field constant export.
35  
36 # lexicalized copy from Chj::load: (most of the code here should really not be in the base class of all class array based classes sigh..)
37 0 ▶my $load = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
38 0 for $_ (@_) {
39 0 my $name = $_;
40 0 $name =~ s|::|/|sg;
41 0 $name .= ".pm";
42 0 require $name;
43 }
44 80 };
45  
46 402 ▶sub import {
Subroutine import: called CC=63 SCAR=69.0
47 402 my $class = shift;
48 402 my $calling_class;
49  
50 # sort out arguments:
51 402 my (@normal_import, @only_fields, @newpublicfields, @newpublicafields,
52 @newprotectedfields, @newprivatefields, @pmixin);
53 402 my $publicity = PROTECTED; # default behaviour!
54 402 my $namehash;
55 my (
56 402 $flag_fields, $flag_extend, $flag_onlyfields, $flag_base,
57 $flag_nowarn, $flag_namehash, $flag_caller, $flag_pmixin
58 ); #hmm it really starts to cry for a $i or shift approach.
59 402 for (@_) {
60 1939 ▶ if ($flag_base) {
Branch: 17 branches
BranchTrueFalseTotal
if ($flag_base) { } 0 1939 1939
elsif ($flag_namehash) { } 0 1939 1939
elsif ($flag_pmixin) { } 0 1939 1939
elsif ($flag_caller) { } 0 1939 1939
elsif ($_ eq '-caller') { } 0 1939 1939
elsif ($_ eq '-nowarn') { } 0 1939 1939
elsif ($_ eq '-fields' or $_ eq '-members') { } 321 1618 1939
elsif ($_ eq '-extend') { } 0 1618 1618
elsif ($_ eq '-public') { } 0 1618 1618
elsif ($_ eq '-publica' or $_ eq '-pub') { } 321 1297 1618
elsif ($_ eq '-shared' or $_ eq '-protected') { } 0 1297 1297
elsif ($_ eq '-private') { } 0 1297 1297
elsif ($_ eq '-onlyfields' or $_ eq '-onlymembers') { } 0 1297 1297
elsif ($_ eq '-class') { } 0 1297 1297
elsif ($_ eq '-namehash') { } 0 1297 1297
elsif ($_ eq '-pmixin') { } 0 1297 1297
elsif (/^-/) { } 0 1297 1297
61 0 $flag_base = 0;
62 0 $class = $_;
63 } elsif ($flag_namehash) {
64 0 $flag_namehash = 0;
65 0 $namehash = $_;
66 } elsif ($flag_pmixin) {
67 0 $flag_pmixin = 0;
68 0 push @pmixin, $_;
69 ##(or should we actually accept as many arguments as there are non-dashed ones?)
70 } elsif ($flag_caller) {
71 0 $flag_caller = 0;
72 0 $calling_class = $_;
73 } elsif ($_ eq '-caller') {
74 0 ▶ croak "Multiple occurrence of -caller argument"
Branch: 1 branch
BranchTrueFalseTotal
if defined $calling_class 0 0 0
75 if defined $calling_class;
76 0 $flag_caller = 1;
77 } elsif ($_ eq '-nowarn') {
78 0 $flag_nowarn = 1;
79 ▶ } elsif ($_ eq '-fields' or $_ eq '-members') {
Condition66%2/3
$_ eq "-fields" or $_ eq "-members"
l!l&&r!l&&!r
32101618
MC/DC50%1/2
$_ eq "-fields" or $_ eq "-members"
$_ eq "-fields" $_ eq "-members"
Truth table66%2/3
A or B
A= $_ eq "-fields"B= $_ eq "-members"
ABresult
1X1
011
000
80 321 $flag_fields = 1;
81 } elsif ($_ eq '-extend') {
82 0 $flag_extend = 1;
83 } elsif ($_ eq '-public') {
84 0 ▶ if ($flag_extend || $flag_fields) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag_extend or $flag_fields) { } 0 0 0
Condition0%0/3
$flag_extend or $flag_fields
l!l&&r!l&&!r
000
MC/DC0%0/2
$flag_extend or $flag_fields
$flag_extend $flag_fields
Truth table0%0/3
A or B
A= $flag_extendB= $flag_fields
ABresult
1X1
011
000
85 0 $publicity = PUBLIC;
86 } else {
87 0 croak __PACKAGE__
88 . ": missing -extend or -fields option before -public";
89 }
90 ▶ } elsif ($_ eq '-publica' or $_ eq '-pub') {
Condition66%2/3
$_ eq "-publica" or $_ eq "-pub"
l!l&&r!l&&!r
32101297
MC/DC50%1/2
$_ eq "-publica" or $_ eq "-pub"
$_ eq "-publica" $_ eq "-pub"
Truth table66%2/3
A or B
A= $_ eq "-publica"B= $_ eq "-pub"
ABresult
1X1
011
000
91 321 ▶ if ($flag_extend || $flag_fields) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag_extend or $flag_fields) { } 321 0 321
Condition33%1/3
$flag_extend or $flag_fields
l!l&&r!l&&!r
03210
MC/DC0%0/2
$flag_extend or $flag_fields
$flag_extend $flag_fields
Truth table33%1/3
A or B
A= $flag_extendB= $flag_fields
ABresult
1X1
011
000
92 321 $publicity = PUBLICA;
93 } else {
94 0 croak __PACKAGE__
95 . ": missing -extend or -fields option before -publica";
96 }
97 ▶ } elsif ($_ eq '-shared' || $_ eq '-protected') {
Condition33%1/3
$_ eq "-shared" or $_ eq "-protected"
l!l&&r!l&&!r
001297
MC/DC0%0/2
$_ eq "-shared" or $_ eq "-protected"
$_ eq "-shared" $_ eq "-protected"
Truth table33%1/3
A or B
A= $_ eq "-shared"B= $_ eq "-protected"
ABresult
1X1
011
000
98 0 ▶ if ($flag_extend || $flag_fields) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag_extend or $flag_fields) { } 0 0 0
Condition0%0/3
$flag_extend or $flag_fields
l!l&&r!l&&!r
000
MC/DC0%0/2
$flag_extend or $flag_fields
$flag_extend $flag_fields
Truth table0%0/3
A or B
A= $flag_extendB= $flag_fields
ABresult
1X1
011
000
99 0 $publicity = PROTECTED;
100 } else {
101 0 croak __PACKAGE__
102 . ": missing -extend or -fields option before -protected";
103 }
104 } elsif ($_ eq '-private') {
105 0 ▶ if ($flag_extend || $flag_fields) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag_extend or $flag_fields) { } 0 0 0
Condition0%0/3
$flag_extend or $flag_fields
l!l&&r!l&&!r
000
MC/DC0%0/2
$flag_extend or $flag_fields
$flag_extend $flag_fields
Truth table0%0/3
A or B
A= $flag_extendB= $flag_fields
ABresult
1X1
011
000
106 0 $publicity = PRIVATE;
107 } else {
108 0 croak __PACKAGE__
109 . ": missing -extend or -fields option before -private";
110 }
111 ▶ } elsif ($_ eq '-onlyfields' or $_ eq '-onlymembers') {
Condition33%1/3
$_ eq "-onlyfields" or $_ eq "-onlymembers"
l!l&&r!l&&!r
001297
MC/DC0%0/2
$_ eq "-onlyfields" or $_ eq "-onlymembers"
$_ eq "-onlyfields" $_ eq "-onlymembers"
Truth table33%1/3
A or B
A= $_ eq "-onlyfields"B= $_ eq "-onlymembers"
ABresult
1X1
011
000
112 0 ▶ if ($flag_extend || $flag_fields) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag_extend or $flag_fields) { } 0 0 0
Condition0%0/3
$flag_extend or $flag_fields
l!l&&r!l&&!r
000
MC/DC0%0/2
$flag_extend or $flag_fields
$flag_extend $flag_fields
Truth table0%0/3
A or B
A= $flag_extendB= $flag_fields
ABresult
1X1
011
000
113 0 croak __PACKAGE__
114 . ": -onlyfields option not allowed after -extend or -fields";
115 } else {
116 0 $flag_onlyfields = 1;
117 }
118 } elsif ($_ eq '-class') {
119 0 ▶ if (defined $flag_base) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $flag_base) { } 0 0 0
120 0 croak __PACKAGE__ . ": only one -class option possible";
121 } else {
122 0 $flag_base = 1;
123 }
124 0 $flag_base = 1;
125 } elsif ($_ eq '-namehash') {
126 0 $flag_namehash = 1
127 ; ## wieso dieser hack?, warum nicht nächstes argument clobbern? Hmm.
128 } elsif ($_ eq '-pmixin') {
129 0 $flag_pmixin = 1; #dito
130 } elsif (/^-/) {
131 0 croak __PACKAGE__ . ": don't understand option `$_'";
132 } else {
133 1297 ▶ if ($flag_fields || $flag_extend) {
Branch: 2 branches
BranchTrueFalseTotal
if ($flag_fields or $flag_extend) { } 1297 0 1297
elsif ($flag_onlyfields) { } 0 0 0
Condition33%1/3
$flag_fields or $flag_extend
l!l&&r!l&&!r
129700
MC/DC0%0/2
$flag_fields or $flag_extend
$flag_fields $flag_extend
Truth table33%1/3
A or B
A= $flag_fieldsB= $flag_extend
ABresult
1X1
011
000
134 1297 ▶ if ($publicity == PUBLIC) {
Branch: 3 branches
BranchTrueFalseTotal
if ($publicity == 0) { } 0 1297 1297
elsif ($publicity == 3) { } 1297 0 1297
elsif ($publicity == 1) { } 0 0 0
135 0 push @newpublicfields, $class->class_array_conformize($_);
136 } elsif ($publicity == PUBLICA) {
137 1297 push @newpublicafields, $class->class_array_conformize($_);
138 } elsif ($publicity == PROTECTED) {
139 0 push @newprotectedfields,
140 $class->class_array_conformize($_);
141 } else {
142 0 push @newprivatefields, $class->class_array_conformize($_);
143 }
144 } elsif ($flag_onlyfields) {
145 0 push @only_fields, $_;
146 } else {
147 0 push @normal_import, $_;
148 }
149 }
150 }
151  
152 402 ▶ croak "Missing argument to '-caller'" if $flag_caller;
Branch: 1 branch
BranchTrueFalseTotal
if $flag_caller 0 402 402
153 402 ▶ unless (defined $calling_class) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $calling_class) 402 0 402
154 402 $calling_class = caller;
155 402 ▶ croak
Branch: 1 branch
BranchTrueFalseTotal
if $class eq $calling_class 0 402 402
156 "Won't import class '$class' into itself (use the -caller option to specify the export target)"
157 if $class eq $calling_class;
158 }
159 402 warn "importing '$class' to '$calling_class'" if DEBUG;
160  
161 #if ($flag_namehash && ! $namehash) {
162 # croak __PACKAGE__.": missing argument to -namehash option";
163 #} els
164 # nein, es soll undef erlaubt sein für den Fall von fields/inherit, dann einfach kein alias kreieren?
165 # çç
166 402 ▶ if ($flag_fields && defined $flag_base) {
Branch: 5 branches
BranchTrueFalseTotal
if ($flag_fields and defined $flag_base) { } 0 402 402
elsif ($flag_fields and $flag_extend) { } 0 402 402
elsif ($flag_fields and $flag_onlyfields) { } 0 402 402
elsif ($flag_fields) { } 321 81 402
elsif ($flag_extend) { } 0 81 81
Condition66%2/3
$flag_fields and defined $flag_base
!ll&&!rl&&r
813210
MC/DC0%0/2
$flag_fields and defined $flag_base
$flag_fields defined $flag_base
Truth table66%2/3
A and B
A= $flag_fieldsB= defined $flag_base
ABresult
0X0
100
111
167 0 croak __PACKAGE__ . ": you can't give both -fields and -class options";
168 ▶ } elsif ($flag_fields && $flag_extend) {
Condition66%2/3
$flag_fields and $flag_extend
!ll&&!rl&&r
813210
MC/DC0%0/2
$flag_fields and $flag_extend
$flag_fields $flag_extend
Truth table66%2/3
A and B
A= $flag_fieldsB= $flag_extend
ABresult
0X0
100
111
169 0 croak __PACKAGE__ . ": you can't give both -fields and -extend options";
170 ▶ } elsif ($flag_fields and $flag_onlyfields) {
Condition66%2/3
$flag_fields and $flag_onlyfields
!ll&&!rl&&r
813210
MC/DC0%0/2
$flag_fields and $flag_onlyfields
$flag_fields $flag_onlyfields
Truth table66%2/3
A and B
A= $flag_fieldsB= $flag_onlyfields
ABresult
0X0
100
111
171 0 croak __PACKAGE__
172 . ": you can't give both -fields and -onlyfields options";
173 } elsif ($flag_fields) { # set up $calling_class as base class
174 321 my $counter = 0
175 ; ##PS. könnte bei 1 anfangen und ins arrayelement 0 was anderes stopfen...
176 321 create_fields_and_bless_class($calling_class, $counter,
177 \@newpublicfields, \@newpublicafields, \@newprotectedfields,
178 \@newprivatefields, $class);
179 321 ▶ if ($namehash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($namehash) 0 321 321
180 0 $calling_class->class_array_namehash($namehash, 1, $calling_class,
181 1);
182 }
183  
184 } elsif ($flag_extend) { # Inherit a class
185 80 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
186 0 my $counter = ${"${class}::_CLASS_ARRAY_COUNTER"};
187 0 ▶ unless (defined $counter) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $counter) 0 0 0
188 0 ▶ if ($class eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) { } 0 0 0
189 0 croak __PACKAGE__
190 . ": please use the '-fields' argument instead of '-extend' for deriving from the Chj::Class::Array base class";
191  
192 # (Hmm, does it really make sense?, should we just drop the '-fields' arg in favour of -extend in all cases?)
193 } else {
194 0 croak __PACKAGE__
195 . ": class $class doesn't seem to be a Chj::Class::Array type class";
196 }
197 }
198 warn
199 0 " going to call create_fields_and_bless_class for extension, calling_class=$calling_class, counter=$counter, class=$class"
200 if DEBUG;
201 0 create_fields_and_bless_class($calling_class, $counter,
202 \@newpublicfields, \@newpublicafields, \@newprotectedfields,
203 \@newprivatefields, $class);
204 0 ▶ if ( # $class ne __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined ${"${class}::_CLASS_ARRAY_SUPERCLASS";}) 0 0 0
205 0 defined ${"${class}::_CLASS_ARRAY_SUPERCLASS"}
206 )
207 {
208 alias_fields(
209 $class,
210 $calling_class,
211 0 $flag_onlyfields ? { map { $_ => 1 } @only_fields } : undef,
212 $flag_nowarn,
213 !$flag_fields,
214 {
215 0 ▶ map { $_ => 1 } @newpublicfields, @newpublicafields,
Branch: 1 branch
BranchTrueFalseTotal
$flag_onlyfields ? : 0 0 0
216 @newprivatefields
217 },
218 );
219 }
220 0 ▶ if ($namehash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($namehash) 0 0 0
221 0 $calling_class->class_array_namehash($namehash, 1, $calling_class,
222 1);
223 }
224  
225 } else { # 'normal' use of a class without inheriting it.
226 croak "$class is of no use without defining fields on top of it"
227 81 ▶ unless do {
Branch: 1 branch
BranchTrueFalseTotal
unless do { no strict 'refs'; defined ${"${class}::_CLASS_ARRAY_SUPERCLASS";} } 0 81 81
228 80 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
229 81 defined ${"${class}::_CLASS_ARRAY_SUPERCLASS"};
230 };
231  
232 # don't simply test '$class eq __PACKAGE__' since this would
233 # stop one to extent Chj::Class::Array itself.
234 alias_fields($class, $calling_class,
235 0 ▶ $flag_onlyfields ? { map { $_ => 1 } @only_fields } : undef,
Branch: 1 branch
BranchTrueFalseTotal
$flag_onlyfields ? : 0 81 81
236 $flag_nowarn, 0);
237 81 ▶ if ($namehash)
Branch: 1 branch
BranchTrueFalseTotal
if ($namehash) 0 81 81
238 { # create (if needed) and import name lookup hash (and cache it)
239 0 $class->class_array_namehash($namehash, 0, $calling_class, 1);
240 }
241 }
242  
243 402 ▶ if (@pmixin) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pmixin) 0 402 402
244 0 $load->(@pmixin);
245 80 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
246 0 push @{ $calling_class . "::ISA" }, @pmixin;
247 }
248  
249 # 'normal' export mechanism
250 402 for (@normal_import) {
251 0 transport([$_], $class, $calling_class, $flag_nowarn);
252 }
253 }
254  
255 162 ▶sub alias_fields {
Subroutine alias_fields: called CC=16 SCAR=41.2
Pod undocumented
256 my (
257 162 $class, $calling_class, $only_fields, $flag_nowarn, $flag_inherit,
258 $ignore_fields
259 , # optional; the opposite of only_fields, 'usually' contains those fields that have been newly created or already aliased.
260 ) = @_;
261 162 ▶ $ignore_fields ||= {};
Condition100%2/2
$ignore_fields ||= {}
l!l
8181
MC/DC100%1/1
$ignore_fields ||= {}
$ignore_fields
Truth table100%2/2
A
A= $ignore_fields
Aresult
11
00
262 80 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
263 162 ▶ if (defined *{"${class}::_CLASS_ARRAY_PUBLIC_FIELDS"}{ARRAY}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"${class}::_CLASS_ARRAY_PUBLIC_FIELDS";}{"ARRAY"}) 162 0 162
264 162 for (
265 162 ▶ @{"${class}::_CLASS_ARRAY_PUBLIC_FIELDS"},
Branch: 1 branch
BranchTrueFalseTotal
$flag_inherit ? : 0 162 162
266 (
267 $flag_inherit
268 ? (
269 0 @{"${class}::_CLASS_ARRAY_PROTECTED_FIELDS"},
270 0 @{"${class}::_CLASS_ARRAY_PUBLICA_FIELDS"}
271 )
272 : ()
273 )
274 )
275 {
276 0 ▶ if (!$only_fields or $only_fields->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $only_fields or $only_fields->{$_}) 0 0 0
Condition0%0/3
not $only_fields or $only_fields->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $only_fields or $only_fields->{$_}
not $only_fields $only_fields->{$_}
Truth table0%0/3
not(A) or B
A= not $only_fieldsB= $only_fields->{$_}
ABresult
1X1
011
000
277 0 ▶ if ($ignore_fields->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ignore_fields->{$_}) { } 0 0 0
278 0 warn "alias_fields: ignoring field '$_' in class '$class'"
279 if DEBUG;
280 } else {
281 0 ▶ if (defined *{"${calling_class}::$_"}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"${calling_class}::$_";}{'CODE'}) { } 0 0 0
282 0 ▶ if (*{"${calling_class}::$_"}{CODE}
Branch: 1 branch
BranchTrueFalseTotal
if (*{"${calling_class}::$_";}{'CODE'} == *{"${class}::$_";}{'CODE'}) { } 0 0 0
283 0 == *{"${class}::$_"}{CODE})
284 {
285 0 warn
286 "${calling_class}::$_ exists already but is the same as ${class}::$_"
287 if DEBUG;
288 0 $ignore_fields->{$_} = 1;
289 } else {
290 0 ▶ carp __PACKAGE__
Branch: 1 branch
BranchTrueFalseTotal
unless $flag_nowarn 0 0 0
291 . ": conflicting name `$_': ignoring and also removing existing entry (all of \*$_ !)"
292 unless $flag_nowarn;
293  
294 #delete *{"${calling_class}::$_"}{CODE}; ## geht nicht, muss undef?:
295 #undef *{"${calling_class}::$_"}{CODE}; ## geht auch nicht, Can't modify glob elem in undef operator
296 #*{"${calling_class}::$_"} = undef; ## ist doch wüst weil es auch alle andern löscht.
297 #*{"${calling_class}::$_"} = *Chj::Class::Array::nonexistant{CODE}; ist genaudasselbe.
298 #*{"${calling_class}::$_"} = sub { print "SCheisse\n" }; #"
299 0 delete ${"${calling_class}::"}{$_}
300 ; #" OK! Works, but deletes all glob fields, not only CODE. Does anybody know how to do this correctly? In Perl?, in a C extension?
301 }
302 } else {
303 0 *{"${calling_class}::$_"} = *{"${class}::$_"}{CODE};
304 0 $ignore_fields->{$_} = 1;
305 }
306 }
307 }
308 }
309 162 my $superclass = ${"${class}::_CLASS_ARRAY_SUPERCLASS"};
310 162 warn "! ${class}::_CLASS_ARRAY_SUPERCLASS = $superclass\n" if DEBUG;
311  
312 162 ▶ unless ($superclass) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($superclass) 81 81 162
313 81 my $isaref = *{"${class}::ISA"}{ARRAY};
314  
315 #print STDERR "! ${class}::ISA = ".(join ",",@$isaref )."\n";
316 81 ▶ if ($isaref and @$isaref >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isaref and @$isaref >= 1) 0 81 81
Condition33%1/3
$isaref and @$isaref >= 1
!ll&&!rl&&r
0810
MC/DC0%0/2
$isaref and @$isaref >= 1
$isaref @$isaref >= 1
Truth table33%1/3
A and B
A= $isarefB= @$isaref >= 1
ABresult
0X0
100
111
317 0 $superclass = ${$isaref}[0];
318 }
319 }
320 162 ▶ $superclass or do {
Branch: 1 branch
BranchTrueFalseTotal
$superclass or do { warn 'Chj::Class::Array' . ": Error: class $class is set up as Chj::Class::Array type class except that _CLASS_ARRAY_SUPERCLASS is not defined" unless $class eq "Chj::Class::Array"; return } 81 81 162
321 81 ▶ warn __PACKAGE__
Branch: 1 branch
BranchTrueFalseTotal
unless $class eq "Chj::Class::Array" 0 81 81
322 . ": Error: class $class is set up as Chj::Class::Array type class except that _CLASS_ARRAY_SUPERCLASS is not defined"
323 unless $class eq 'Chj::Class::Array'
324 ; ### don't warn when class = Chj::Class::Array, happens often
325 81 return;
326 };
327  
328 81 alias_fields(
329 $superclass, $calling_class, $only_fields,
330 $flag_nowarn, $flag_inherit, $ignore_fields
331 );
332 } # else something is strange, isn't it? ##
333 }
334  
335 #use Carp 'cluck';
336  
337 # von theaterblut:
338 sub class_array_namehash_allprotected
339 0 ▶{ # get all protected field definitions in the given package/package of given object, regardless of caller
Subroutine class_array_namehash_allprotected: not called CC=5 SCAR=30.9
Pod undocumented
340 0 my $proto = shift;
341 0 ▶ my $class = ref($proto) || $proto; #minimal gefahrlich
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
342 #warn "class_array_namehash_allprotected: class=$class";
343 0 my $hashref;
344 80 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
345 0 ▶ if ($hashref = *{"${class}::_CLASS_ARRAY_NAMEHASHALLPROTECTED"}{HASH}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hashref = *{"${class}::_CLASS_ARRAY_NAMEHASHALLPROTECTED";}{'HASH'}) { } 0 0 0
346  
347 #warn "reuse cached hash";
348 } else {
349 0 $hashref
350 = {}; # könnte es ja sein dass gar nirgends protected fields sind!
351 0 my $workclass = $class;
352 do {
353 #warn "class_array_namehash_allprotected: werde über \@${workclass}::_CLASS_ARRAY_PROTECTED_FIELDS loopen..";
354 0 for (@{"${workclass}::_CLASS_ARRAY_PROTECTED_FIELDS"}) {
355 0 $hashref->{$_} = eval "${workclass}::$_"; # XX security?
356 #warn "class_array_namehash_allprotected: did set name '$_' to $hashref->{$_}";
357 }
358 0 ▶ } while ($workclass = ${"${workclass}::_CLASS_ARRAY_SUPERCLASS"});
Branch: 1 branch
BranchTrueFalseTotal
$workclass = ${"${workclass}::_CLASS_ARRAY_SUPERCLASS";} and do { do { foreach $_ (@{"${workclass}::_CLASS_ARRAY_PROTECTED_FIELDS";}) { $hashref->{$_} = eval "${workclass}::$_"; } } } 0 0 0
359 0 *{"${class}::_CLASS_ARRAY_NAMEHASHALLPROTECTED"} = $hashref;
360 }
361 0 return $hashref
362 }
363  
364 sub class_array_namehash
365 642 ▶{ #(cj 05/10/05: offensichtlich keine publica felder bekommbar so, egal was für flags.??)
Subroutine class_array_namehash: called CC=19 SCAR=36.8
Pod undocumented
366 642 my $class = shift;
367 642 my ($hashname, $flag_inherit, $calling_class, $flag_cachehash,
368 $incomplete_hashref)
369 = @_;
370 642 ▶ $calling_class = caller unless defined $calling_class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $calling_class 321 321 642
371 642 ▶ $flag_inherit = ($calling_class->isa($class) || $class->isa($calling_class))
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flag_inherit 321 321 642
Condition33%1/3
$calling_class->isa($class) || $class->isa($calling_class)
l!l&&r!l&&!r
03210
MC/DC0%0/2
$calling_class->isa($class) || $class->isa($calling_class)
$calling_class->isa($class) $class->isa($calling_class)
Truth table33%1/3
A || B
A= $calling_class->isa($class)B= $class->isa($calling_class)
ABresult
1X1
011
000
372 unless defined $flag_inherit;
373 80 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
374 642 my $hashref;
375 642 ▶ if ($hashref
Branch: 2 branches
BranchTrueFalseTotal
if ($hashref = $flag_inherit ? *{"${calling_class}::CLASS_ARRAY_NAMEHASH";}{'HASH'} : *{"${class}::_CLASS_ARRAY_NAMEHASHFOREXTERNALUSE";}{'HASH'}) { } 0 642 642
$flag_inherit ? : 642 0 642
376 = $flag_inherit
377 642 ? *{"${calling_class}::CLASS_ARRAY_NAMEHASH"}{HASH}
378 0 : *{"${class}::_CLASS_ARRAY_NAMEHASHFOREXTERNALUSE"}{HASH})
379 {
380 0 warn "using cached namehash for '$class'" if DEBUG;
381 } else {
382 642 warn "need to create it" if DEBUG;
383 642 ▶ $hashref = $incomplete_hashref ? $incomplete_hashref : {};
Branch: 1 branch
BranchTrueFalseTotal
$incomplete_hashref ? : 321 321 642
384 642 my $superclass = ${"${class}::_CLASS_ARRAY_SUPERCLASS"};
385 642 ▶ if ($superclass) {
Branch: 1 branch
BranchTrueFalseTotal
if ($superclass) 321 321 642
386 321 warn
387 "DEBUG: going to call $superclass->class_array_namehash(undef, $flag_inherit, $calling_class, 0, \$hashref) where hash has "
388 . (keys %$hashref) . " keys"
389 if DEBUG;
390 321 $superclass->class_array_namehash(undef, $flag_inherit,
391 $calling_class, 0, $hashref)
392 ; ## eigentlich würd ein flag anstelle calling_class ja reichen.
393 321 warn "DEBUG: now hash has " . (keys %$hashref) . " keys" if DEBUG;
394 }
395  
396 # use Data::Dumper;
397 # warn "Public: ",Dumper(\@{"${class}::_CLASS_ARRAY_PUBLIC_FIELDS"});
398 # warn "Publica: ",Dumper(\@{"${class}::_CLASS_ARRAY_PUBLICA_FIELDS"});
399 642 for (
400 642 @{"${class}::_CLASS_ARRAY_PUBLIC_FIELDS"},
401 642 ▶ @{"${class}::_CLASS_ARRAY_PUBLICA_FIELDS"},
Branch: 1 branch
BranchTrueFalseTotal
$flag_inherit ? : 642 0 642
402 642 ▶ ($flag_inherit ? @{"${class}::_CLASS_ARRAY_PROTECTED_FIELDS"} : ()),
Branch: 1 branch
BranchTrueFalseTotal
$flag_inherit && $calling_class eq $class ? : 321 321 642
Condition66%2/3
$flag_inherit and $calling_class eq $class
!ll&&!rl&&r
0321321
MC/DC50%1/2
$flag_inherit and $calling_class eq $class
$flag_inherit $calling_class eq $class
Truth table66%2/3
A and B
A= $flag_inheritB= $calling_class eq $class
ABresult
0X0
100
111
403 (
404 ($flag_inherit and $calling_class eq $class)
405 321 ? @{"${class}::_CLASS_ARRAY_PRIVATE_FIELDS"}
406 : ()
407 )
408 )
409 {
410 #if (exists $hashref->{$_}) {
411 # warn "DUPLIKAT KEY für '$_' in '$class'";##
412 #} nope just overwrite it. since we first gathered the superclass'es values first, we have to.
413 1297 $hashref->{$_} = eval "${class}::$_"; # XX security?
414 }
415  
416 # save it?
417 642 ▶ if ($hashname or $flag_cachehash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hashname or $flag_cachehash) 0 642 642
Condition33%1/3
$hashname or $flag_cachehash
l!l&&r!l&&!r
00642
MC/DC0%0/2
$hashname or $flag_cachehash
$hashname $flag_cachehash
Truth table33%1/3
A or B
A= $hashnameB= $flag_cachehash
ABresult
1X1
011
000
418 0 ▶ if ($flag_inherit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag_inherit) { } 0 0 0
419 0 *{"${calling_class}::CLASS_ARRAY_NAMEHASH"} = $hashref;
420 0 warn
421 "DEBUG: saved namehash as ${calling_class}::CLASS_ARRAY_NAMEHASH"
422 if DEBUG;
423 } else {
424 0 *{"${class}::_CLASS_ARRAY_NAMEHASHFOREXTERNALUSE"} = $hashref;
425 0 warn
426 "DEBUG: saved namehash as ${class}::_CLASS_ARRAY_NAMEHASHFOREXTERNALUSE"
427 if DEBUG;
428 }
429 }
430 }
431  
432 # create alias for it?
433 642 ▶ if ( $hashname
Branch: 1 branch
BranchTrueFalseTotal
if ($hashname and $hashname ne 1 and !$flag_inherit || $hashname ne "CLASS_ARRAY_NAMEHASH") 0 642 642
Condition22%2/9
$hashname and $hashname ne 1 and !$flag_inherit || $hashname ne "CLASS_ARRAY_NAMEHASH"
!ll&&!rl&&r
64200
$hashname and $hashname ne 1
!ll&&!rl&&r
64200
not $flag_inherit or $hashname ne "CLASS_ARRAY_NAMEHASH"
l!l&&r!l&&!r
000
MC/DC0%0/4
$hashname and $hashname ne 1 and !$flag_inherit || $hashname ne "CLASS_ARRAY_NAMEHASH"
$hashname $hashname ne 1 not $flag_inherit $hashname ne "CLASS_ARRAY_NAMEHASH"
Truth table20%1/5
A and B and not(C) or D
A= $hashnameB= $hashname ne 1C= not $flag_inheritD= $hashname ne "CLASS_ARRAY_NAMEHASH"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
434 and $hashname ne '1'
435 and (!$flag_inherit or $hashname ne 'CLASS_ARRAY_NAMEHASH'))
436 {
437 0 *{"${calling_class}::$hashname"} = $hashref;
438 }
439  
440 $hashref
441 642 }
442  
443 0 ▶sub class_array_indices {
Subroutine class_array_indices: not called CC=2 SCAR=17.9
Pod undocumented
444 0 my $class = shift;
445 0 my $hash = $class->class_array_namehash(undef, undef, caller)
446 ; # is is required to get caller already here!, it would be Chj::Class::Array otherwise
447  
448 #use Data::Dumper;
449 #warn "class_array_indices bekam ".Dumper($hash);
450 map {
451 0 exists $hash->{$_}
452 0 ▶ ? $hash->{$_}
Branch: 1 branch
BranchTrueFalseTotal
exists $hash->{$_} ? : 0 0 0
453 : confess
454 "class_array_indices: '$_': no such field (known in your namespace)"
455 } @_;
456 }
457  
458 0 ▶sub transport {
Subroutine transport: not called CC=21 SCAR=60.4
Pod undocumented
459 0 my ($items, $class, $calling_class, $flag_nowarn) = @_;
460 80 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
461 0 for (@$items) {
462 0 ▶ if (/^\$(.*)/) { # scalar
Branch: 3 branches
BranchTrueFalseTotal
if (/^\$(.*)/) { } 0 0 0
elsif (/^\@(.*)/) { } 0 0 0
elsif (/^\%(.*)/) { } 0 0 0
463 0 ▶ if (defined *{"${class}::$1"}{SCALAR})
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"${class}::$1";}{'SCALAR'}) { } 0 0 0
464 { ## DOES IN FACT ALWAYS RETURN TRUE!
465 0 ▶ if (defined *{"${calling_class}::$1"}{SCALAR})
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"${calling_class}::$1";}{'SCALAR'}) { } 0 0 0
466 { ## DOES IN FACT ALWAYS RETURN TRUE!
467 0 ▶ if (*{"${calling_class}::$1"}{SCALAR}
Branch: 1 branch
BranchTrueFalseTotal
if (*{"${calling_class}::$1";}{'SCALAR'} == *{"${class}::$1";}{'SCALAR'}) { } 0 0 0
468 0 == *{"${class}::$1"}{SCALAR})
469 {
470 0 carp __PACKAGE__ . ": symbol `$_' already imported"
471 if DEBUG;
472 } else {
473 0 ▶ carp __PACKAGE__ . ": conflicting name `$_' - ignoring"
Branch: 1 branch
BranchTrueFalseTotal
unless $flag_nowarn 0 0 0
474 unless $flag_nowarn;
475 }
476 } else {
477 0 *{"${calling_class}::$1"} = *{"${class}::$1"}{SCALAR};
478 }
479 } else {
480 0 croak __PACKAGE__
481 . ": can't export \$${class}::$1 since it doesn't exist";
482 }
483 } elsif (/^\@(.*)/) { # array
484 0 ▶ if (defined *{"${class}::$1"}{ARRAY}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"${class}::$1";}{'ARRAY'}) { } 0 0 0
485 0 ▶ if (defined *{"${calling_class}::$1"}{ARRAY}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"${calling_class}::$1";}{'ARRAY'}) { } 0 0 0
486 0 ▶ if (*{"${calling_class}::$1"}{ARRAY}
Branch: 1 branch
BranchTrueFalseTotal
if (*{"${calling_class}::$1";}{'ARRAY'} == *{"${class}::$1";}{'ARRAY'}) { } 0 0 0
487 0 == *{"${class}::$1"}{ARRAY})
488 {
489 0 carp __PACKAGE__ . ": symbol `$_' already imported"
490 if DEBUG;
491 } else {
492 0 ▶ carp __PACKAGE__ . ": conflicting name `$_' - ignoring"
Branch: 1 branch
BranchTrueFalseTotal
unless $flag_nowarn 0 0 0
493 unless $flag_nowarn;
494 }
495 } else {
496 0 *{"${calling_class}::$1"} = *{"${class}::$1"}{ARRAY};
497 }
498 } else {
499 0 croak __PACKAGE__
500 . ": can't export \@${class}::$1 since it doesn't exist";
501 }
502 } elsif (/^\%(.*)/) { # hash
503 0 ▶ if (defined *{"${class}::$1"}{HASH}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"${class}::$1";}{'HASH'}) { } 0 0 0
504 0 ▶ if (defined *{"${calling_class}::$1"}{HASH}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"${calling_class}::$1";}{'HASH'}) { } 0 0 0
505 0 ▶ if (*{"${calling_class}::$1"}{HASH}
Branch: 1 branch
BranchTrueFalseTotal
if (*{"${calling_class}::$1";}{'HASH'} == *{"${class}::$1";}{'HASH'}) { } 0 0 0
506 0 == *{"${class}::$1"}{HASH})
507 {
508 0 carp __PACKAGE__ . ": symbol `$_' already imported"
509 if DEBUG;
510 } else {
511 0 ▶ carp __PACKAGE__ . ": conflicting name `$_' - ignoring"
Branch: 1 branch
BranchTrueFalseTotal
unless $flag_nowarn 0 0 0
512 unless $flag_nowarn;
513 }
514 } else {
515 0 *{"${calling_class}::$1"} = *{"${class}::$1"}{HASH};
516 }
517 } else {
518 0 croak __PACKAGE__
519 . ": can't export \%${class}::$1 since it doesn't exist";
520 }
521 } else { # subroutine/constant
522 0 ▶ if (defined *{"${class}::$_"}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"${class}::$_";}{'CODE'}) { } 0 0 0
523 0 ▶ if (defined *{"${calling_class}::$_"}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"${calling_class}::$_";}{'CODE'}) { } 0 0 0
524 0 ▶ if (*{"${calling_class}::$_"}{CODE}
Branch: 1 branch
BranchTrueFalseTotal
if (*{"${calling_class}::$_";}{'CODE'} == *{"${class}::$_";}{'CODE'}) { } 0 0 0
525 0 == *{"${class}::$_"}{CODE})
526 {
527 0 carp __PACKAGE__ . ": symbol `$_' already imported"
528 if DEBUG;
529 } else {
530 0 ▶ carp __PACKAGE__ . ": conflicting name `$_' - ignoring"
Branch: 1 branch
BranchTrueFalseTotal
unless $flag_nowarn 0 0 0
531 unless $flag_nowarn;
532 }
533 } else {
534 0 *{"${calling_class}::$_"} = *{"${class}::$_"}{CODE}; #"
535 }
536 } else {
537 0 croak __PACKAGE__
538 . ": can't export ${class}::$_ since it doesn't exist";
539 }
540 }
541 }
542 }
543  
544 #use Carp 'cluck';
545 # sub create_name_lookup_hash { # only call this if needed since it's slow; only call if sure that the given class is Chj::Class::Array based.
546 # my $class = shift;
547 # #cluck "DEBUG: create_name_lookup_hash for class '$class'";
548 # my $superclass;
549 # no strict 'refs';
550 # for (@{"${class}::ISA"}) {
551 # if (defined ${"${_}::_CLASS_ARRAY_COUNTER"}) { # ok it's the class::array based class
552 # $superclass = $_;
553 #
554 # # copy lookup hash from super class
555 # unless (*{"${superclass}::CLASS_ARRAY_NAMEHASH"}{HASH}) {
556 # $superclass->create_name_lookup_hash;
557 # }
558 # %{"${class}::CLASS_ARRAY_NAMEHASH"} = %{"${superclass}::CLASS_ARRAY_NAMEHASH"};
559 #
560 # last;# for
561 # }
562 # } # else there is no superclass. (Except ("hopefully") Chj::Class::Array itself)
563 #
564 # # Put members from this class into the hash
565 # for (@{"${class}::_CLASS_ARRAY_PUBLIC_FIELDS"}, @{"${class}::_CLASS_ARRAY_PROTECTED_FIELDS"}, @{"${class}::_CLASS_ARRAY_PRIVATE_FIELDS"}) {
566 # ${"${class}::CLASS_ARRAY_NAMEHASH"}{$_} = eval "${class}::$_";
567 # }
568 # }
569  
570 321 ▶sub create_fields_and_bless_class {
Subroutine create_fields_and_bless_class: called CC=3 SCAR=11.0
Pod undocumented
571 321 my ($calling_class, $counter, $newpublicfields, $newpublicafields,
572 $newprotectedfields, $newprivatefields, $class)
573 = @_;
574 80 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
575  
576 # if ($namehash and $class ne __PACKAGE__) { # last compare is needed (for -fields creation step) to stop from creating stuff in Chj::Class::Array itself
577 # ##ç defined ${"${class}::_CLASS_ARRAY_COUNTER"}) {
578 # ##der scheiss ist aber eigtl sollt ichs doch von oben von params her kriegen?
579 # # copy nameindex from inherited class.
580 # unless (*{"${class}::CLASS_ARRAY_NAMEHASH"}{HASH}) {
581 # $class->create_name_lookup_hash;
582 # }
583 # %{"${calling_class}::CLASS_ARRAY_NAMEHASH"} = %{"${class}::CLASS_ARRAY_NAMEHASH"};
584 # }
585 321 for (
586 @$newpublicfields, @$newpublicafields,
587 @$newprotectedfields, @$newprivatefields
588 )
589 {
590 1297 ▶ if (defined *{"${calling_class}::$_"}{CODE}) { # coderef exists
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"${calling_class}::$_";}{'CODE'}) { } 0 1297 1297
591 0 croak __PACKAGE__
592 . ": conflicting name `$_': can't create initial member constant";
593 } else {
594 1297 my $scalar = $counter++;
595 0 ▶ *{"${calling_class}::$_"} = sub () {$scalar};
Subroutine __ANON__: not called CC=1 SCAR=0.4
596  
597 # The following isn't any better. It's accelerated in both cases (perl5.00503). In both cases the constants are valid during global destruction. The following doesn't work if $_ eq 'ç' or some such.
598 #eval "sub ${calling_class}::$_ () { $scalar }"; ## somewhat dangerous, maybe we should check vars
599 #warn "Chj::Class::Array: $@ (`$_')" if $@;
600 # if ($namehash) {
601 # ${"${calling_class}::CLASS_ARRAY_NAMEHASH"}{$_} = $scalar;
602 # }
603 }
604 }
605  
606 # warn " create_fields_and_bless_class: calling_class=$calling_class, newpublicfields=".Data::Dumper::Dumper($newpublicfields).", newprotectedfields=".Dumper($newprotectedfields).", newprivatefields=".Dumper($newprivatefields) if DEBUG;
607 321 *{"${calling_class}::_CLASS_ARRAY_PUBLIC_FIELDS"} = $newpublicfields;
608 321 *{"${calling_class}::_CLASS_ARRAY_PUBLICA_FIELDS"} = $newpublicafields;
609 321 *{"${calling_class}::_CLASS_ARRAY_PROTECTED_FIELDS"} = $newprotectedfields;
610 321 *{"${calling_class}::_CLASS_ARRAY_PRIVATE_FIELDS"} = $newprivatefields
611 ; # required for creating name lookup hashes and the like.
612 321 *{"${calling_class}::_CLASS_ARRAY_COUNTER"} = \$counter;
613 321 *{"${calling_class}::ISA"} = [$class];
614 321 *{"${calling_class}::_CLASS_ARRAY_SUPERCLASS"} = \$class;
615 }
616  
617 321 ▶sub createaccessors {
Subroutine createaccessors: called CC=7 SCAR=30.7
Pod undocumented
618 321 my ($calling_class) = @_;
619 80 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
620 321 my $public = *{"${calling_class}::_CLASS_ARRAY_PUBLIC_FIELDS"}{ARRAY};
621 321 my $publica = *{"${calling_class}::_CLASS_ARRAY_PUBLICA_FIELDS"}{ARRAY};
622 321 ▶ if (!$publica) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($publica) 0 321 321
623 0 croak __PACKAGE__
624 . "::createaccessors: class '$calling_class' does not seem to be a Chj::Class::Array based class";
625 }
626 321 my $namehash = $calling_class->class_array_namehash;
627  
628 # use Data::Dumper;
629 # warn "createaccessors: for '$calling_class', namehash=",Dumper($namehash),", public= ",Dumper($public),", publica=",Dumper($publica);
630 321 for (@$public, @$publica) {
631  
632 # warn "loop: $_";
633 1297 my $methodbasename = lcfirstletter($_);
634 1297 ▶ if (not defined *{"${calling_class}::$methodbasename"}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined *{"${calling_class}::$methodbasename";}{"CODE"}) 1297 0 1297
635 1297 *{"${calling_class}::$methodbasename"}
636 = eval 'sub { shift->['
637 0 ▶ . $namehash->{$_}
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
Subroutine __ANON__: not called CC=1 SCAR=6.1
638 . '] }'; # XX security?
639 1297 ▶ die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1297 1297
640  
641 #warn "did create '${calling_class}::$methodbasename'";
642 }
643 1297 ▶ if (not defined *{"${calling_class}::set_$methodbasename"}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined *{"${calling_class}::set_$methodbasename";}{"CODE"}) 1297 0 1297
644 1297 *{"${calling_class}::set_$methodbasename"}
645 = eval 'sub {my $s = shift; ($$s['
646 0 ▶ . $namehash->{$_}
Subroutine __ANON__: not called CC=1 SCAR=6.5
Subroutine __ANON__: not called CC=1 SCAR=6.5
Subroutine __ANON__: not called CC=1 SCAR=6.5
Subroutine __ANON__: not called CC=1 SCAR=6.5
Subroutine __ANON__: not called CC=1 SCAR=6.5
Subroutine __ANON__: not called CC=1 SCAR=6.5
Subroutine __ANON__: not called CC=1 SCAR=6.5
Subroutine __ANON__: not called CC=1 SCAR=6.5
Subroutine __ANON__: not called CC=1 SCAR=6.5
Subroutine __ANON__: not called CC=1 SCAR=6.5
Subroutine __ANON__: not called CC=1 SCAR=6.5
Subroutine __ANON__: not called CC=1 SCAR=6.5
Subroutine __ANON__: not called CC=1 SCAR=6.5
Subroutine __ANON__: not called CC=1 SCAR=6.5
Subroutine __ANON__: not called CC=1 SCAR=6.5
Subroutine __ANON__: not called CC=1 SCAR=6.5
647 . ']) = @_ }'; # XX security?
648 1297 ▶ die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1297 1297
649  
650 #warn "did create '${calling_class}::set_$methodbasename'";
651 }
652 }
653 }
654  
655 321 ▶sub end { # or finalize or so.
Subroutine end: called CC=1 SCAR=0.0
Pod undocumented
656 321 my $calling_class = caller;
657 321 createaccessors($calling_class);
658 321 1; # so that the end call can be the last statement in a module.
659 }
660  
661 # "callback" on reading the class. ps. this should not be done by a method here, but in a different axe (would that be mop like?)
662 1297 ▶sub class_array_conformize {
Subroutine class_array_conformize: called CC=2 SCAR=6.9
Pod undocumented
663 1297 shift;
664  
665 # if a all-lowercase fieldname is given, upcase the first letter
666 1297 my ($name) = @_;
667 1297 ▶ if (lc($name) eq ($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $name eq $name) { } 1280 17 1297
668 1280 ucfirstletter($name)
669 } else {
670 17 $name
671 }
672 }
673  
674 # those are functions and should be in their own namespace
675 1280 ▶sub ucfirstletter {
Subroutine ucfirstletter: called CC=1 SCAR=0.0
Pod undocumented
676 1280 my ($str) = @_;
677 1280 $str =~ s/([a-zA-Z])/uc($1)/se; # or warn ... but we don't care here.
678  
679 # warn "ucfirstletter: @_ -> $str";
680 1280 $str;
681 }
682  
683 1297 ▶sub lcfirstletter {
Subroutine lcfirstletter: called CC=1 SCAR=0.0
Pod undocumented
684 1297 my ($str) = @_;
685 1297 $str =~ s/([a-zA-Z])/lc($1)/se; # or warn ... but we don't care here.
686  
687 # warn "lcfirstletter: @_ -> $str";
688 1297 $str;
689 }
690  
691 # default constructor:
692 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
693 0 my $class = shift;
694 0 bless [], $class;
695 }
696  
697 # default cloner:
698 0 ▶sub clone {
Subroutine clone: not called CC=1 SCAR=6.9
Pod undocumented
699 0 my $self = shift;
700 0 my @new = @$self;
701 0 bless \@new, ref($self)
702 }
703  
704 # default destructor: (this is needed so subclasses can call ->SUPER::DESTROY regardless whether there is one or not)
705 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
706 }
707  
708 # sub dump {
709 # my $s = shift;
710 # # eruiere visible fields
711 # my $caller = caller;
712 # #my $namehash = $s->class_array_namehash(undef,undef,$caller);
713 # # nope. mannn muss doch schon was geben?
714 # # all publicly available fields only?
715 # # oder soll ich echt einfach durch alle Felder gehen, sie dann nach priv/prot/publ zusammenfassen öh unddann ausgeben regardless of feldname? fully qualified feldname geben?
716 # # eigentlich will ich ne darstellung mit feld konstanten? non fully qual optional
717 # die "unfinishedç"
718 # # use Data::Dumper;
719 # # Dumper $namehash
720 # }
721  
722 0 ▶sub class_array_publica_fields {
Subroutine class_array_publica_fields: not called CC=5 SCAR=30.9
Pod undocumented
723 0 my ($class, $result) = @_;
724 0 ▶ if (ref $class) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 0 0 0
725 0 $class = ref $class
726 } # so that it can be used as object method,too.
727 0 ▶ $result ||= [];
Condition0%0/2
$result ||= []
l!l
00
MC/DC0%0/1
$result ||= []
$result
Truth table0%0/2
A
A= $result
Aresult
11
00
728 80 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
729 0 my $publica = *{"${class}::_CLASS_ARRAY_PUBLICA_FIELDS"}{ARRAY};
730 0 ▶ if (!$publica) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($publica) 0 0 0
731 0 croak __PACKAGE__
732 . "::class_array_publica_fields: class '$class' does not seem to be a Chj::Class::Array based class";
733 }
734 0 unshift @$result, @$publica;
735  
736 # und MUSS ich noch hoch iterieren oder nicht? DOCH man muss.
737 0 my $superclass = *{"${class}::_CLASS_ARRAY_SUPERCLASS"}{SCALAR};
738 0 ▶ if ($$superclass)
Branch: 1 branch
BranchTrueFalseTotal
if ($$superclass) { } 0 0 0
739 { # auf $superclass prüfen geht eben nicht, das ist immer ein true ref. MANN. todo oben ist das wohl überall buggy.
740 #warn "superclass '$$superclass'\n";
741 0 class_array_publica_fields($$superclass, $result)
742 } else {
743 0 @$result
744 }
745 }
746  
747 0 ▶sub dump_publica {
Subroutine dump_publica: not called CC=1 SCAR=6.9
Pod undocumented
748 0 my $s = shift;
749 0 require Chj::singlequote;
750 "$s:\n" . join(
751 "",
752 map {
753 0 my $field = $_;
754 0 my $method = lcfirstletter $field;
755 0 " $method: " . Chj::singlequote($s->$method) . "\n"
756 } $s->class_array_publica_fields
757 )
758 }
759  
760 80 *dump = \&dump_publica
761 ; # as long as we don't have a better dump method; note that I'm almost always using publica fields now, so that's just fine for me most of the time..
762  
763 80 1;
764 __END__
« lib/FP/Repl/Repl.pm ↑ Summary lib/Chj/Class/methodnames.pm »