| 1 | 88 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 2 | 88 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||
| 5 | # MarpaX::Java::ClassFile is doing a LOT of new(). | ||||||||||||||||||||||||||||||||||
| 6 | # In development/author phases it is ok to do type checkings, | ||||||||||||||||||||||||||||||||||
| 7 | # but in production mode, this is too expensive, so we go | ||||||||||||||||||||||||||||||||||
| 8 | # back to the old style. In addition, I want objects to | ||||||||||||||||||||||||||||||||||
| 9 | # "look like" a C structure and ALWAYS READ-ONLY. | ||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||
| 11 | # This module, when running in production mode, creates | ||||||||||||||||||||||||||||||||||
| 12 | # an object that, when inspected via dumper modules, will | ||||||||||||||||||||||||||||||||||
| 13 | # truely look like an array with read-only accessors. | ||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||
| 15 | # We se a trick specific to our implementation: SCALAR references | ||||||||||||||||||||||||||||||||||
| 16 | # never exist in input to new(). We fake a SCALAR reference when needed, | ||||||||||||||||||||||||||||||||||
| 17 | # just to have something pretty in dumper modules. | ||||||||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | package MarpaX::Java::ClassFile::Struct::_Base; | ||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | # ABSTRACT: Base class for all structure - optimized to a very basic array-based object in production mode | ||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | 88 | our $VERSION = '0.008'; # VERSION | |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | 88 | our $AUTHORITY = 'cpan:JDDPAUSE'; # AUTHORITY | |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | 88 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 29 | 88 | ▶ | use Import::Into; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 30 | 88 | ▶ | use Class::Method::Modifiers qw/install_modifier/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 31 | 88 | ▶ | use Scalar::Util qw/reftype blessed/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 32 | 88 | require Moo; | |||||||||||||||||||||||||||||||||
| 33 | 88 | require Class::XSAccessor::Array; | |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | 88 | my %_HAS_TRACKED = (); | |||||||||||||||||||||||||||||||||
| 36 | 88 | my @_GETTER = (); | |||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | sub import { | ||||||||||||||||||||||||||||||||||
| 39 | 87 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=22 SCAR=46.9
| |||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | 87 | my $target = caller; | |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 87 | ▶ | if ($ENV{AUTHOR_TESTING}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 44 | # | ||||||||||||||||||||||||||||||||||
| 45 | # Import Moo into caller | ||||||||||||||||||||||||||||||||||
| 46 | # | ||||||||||||||||||||||||||||||||||
| 47 | 0 | Moo->import::into($target) | |||||||||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||||||||
| 49 | # | ||||||||||||||||||||||||||||||||||
| 50 | # In tiny mode, we inject Class::XSAccessor::Array, based on the same logic than Object::Tiny::XS | ||||||||||||||||||||||||||||||||||
| 51 | # | ||||||||||||||||||||||||||||||||||
| 52 | 87 | ▶ | if ($args{-tiny} || $args{-tiny_rw}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"-tiny"} or $args{"-tiny_rw"}
MC/DC0%0/2
$args{"-tiny"} or $args{"-tiny_rw"}
$args{"-tiny"}
$args{"-tiny_rw"}
Truth table33%1/3
A or B
A= $args{"-tiny"}B= $args{"-tiny_rw"}
| |||||||||||||||||||||||||||||||||||
| 53 | # | ||||||||||||||||||||||||||||||||||
| 54 | # Caller has to make sure -tiny => [qw/.../] and -tiny_rw => [qw/.../] and | ||||||||||||||||||||||||||||||||||
| 55 | # | ||||||||||||||||||||||||||||||||||
| 56 | # Almost the same thingy as is Object::Tiny::XS | ||||||||||||||||||||||||||||||||||
| 57 | # but using eventually accessors | ||||||||||||||||||||||||||||||||||
| 58 | # | ||||||||||||||||||||||||||||||||||
| 59 | 87 | ▶ | $args{-tiny} //= []; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"-tiny"} //= []
MC/DC0%0/1
$args{"-tiny"} //= []
$args{"-tiny"}
Truth table50%1/2
A
A= $args{"-tiny"}
| |||||||||||||||||||||||||||||||||||
| 60 | 87 | ▶ | $args{-tiny_rw} //= []; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"-tiny_rw"} //= []
MC/DC0%0/1
$args{"-tiny_rw"} //= []
$args{"-tiny_rw"}
Truth table50%1/2
A
A= $args{"-tiny_rw"}
| |||||||||||||||||||||||||||||||||||
| 61 | # | ||||||||||||||||||||||||||||||||||
| 62 | # Okay, we /know/ that members starting with a '_' are internal and should be | ||||||||||||||||||||||||||||||||||
| 63 | # read-write | ||||||||||||||||||||||||||||||||||
| 64 | # | ||||||||||||||||||||||||||||||||||
| 65 | 87 | my @forced_tiny_rw = (); | |||||||||||||||||||||||||||||||||
| 66 | 87 | my @ok_tiny_ro = (); | |||||||||||||||||||||||||||||||||
| 67 | 87 | foreach (@{$args{-tiny}}) { | |||||||||||||||||||||||||||||||||
| 68 | 309 | ▶ | if (/^_/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 69 | 54 | push(@forced_tiny_rw, $_) | |||||||||||||||||||||||||||||||||
| 70 | } else { | ||||||||||||||||||||||||||||||||||
| 71 | 255 | push(@ok_tiny_ro, $_) | |||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||
| 74 | 87 | $args{-tiny} = \@ok_tiny_ro; | |||||||||||||||||||||||||||||||||
| 75 | 87 | foreach my $forced_rw (@forced_tiny_rw) { | |||||||||||||||||||||||||||||||||
| 76 | 54 | ▶ | push(@{$args{-tiny_rw}}, $forced_rw) unless (grep { $_ eq $forced_rw } @{$args{-tiny_rw}}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||
| 78 | 87 | my $indice = 0; | |||||||||||||||||||||||||||||||||
| 79 | 87 | my @indice2name = (); | |||||||||||||||||||||||||||||||||
| 80 | my $innerGettersAsString = join(", ", | ||||||||||||||||||||||||||||||||||
| 81 | 255 | map { "'$_' => " . do { $indice2name[$indice] = $_; $indice++ } } | |||||||||||||||||||||||||||||||||
| 82 | 255 | ▶ | grep { defined and ! ref and /^[^\W\d]\w*$/s } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_ and not ref $_
MC/DC0%0/2
defined $_ and not ref $_
defined $_
not ref $_
Truth table33%1/3
A and not(B)
A= defined $_B= not ref $_
| |||||||||||||||||||||||||||||||||||
| 83 | 87 | @{$args{-tiny}} | |||||||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||||||||
| 85 | my $innerAccessorsAsString = join(", ", | ||||||||||||||||||||||||||||||||||
| 86 | 54 | map { "'$_' => " . do { $indice2name[$indice] = $_; $indice++ } } | |||||||||||||||||||||||||||||||||
| 87 | 54 | ▶ | grep { defined and ! ref and /^[^\W\d]\w*$/s } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_ and not ref $_
MC/DC0%0/2
defined $_ and not ref $_
defined $_
not ref $_
Truth table33%1/3
A and not(B)
A= defined $_B= not ref $_
| |||||||||||||||||||||||||||||||||||
| 88 | 87 | @{$args{-tiny_rw}} | |||||||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||||||||
| 90 | 88 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 91 | 87 | ▶ | my $hashRefGetters = eval " { $innerGettersAsString } " || croak $@; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
eval " { $innerGettersAsString } " || croak($@)
MC/DC0%0/2
eval " { $innerGettersAsString } " || croak($@)
eval " { $innerGettersAsString } "
croak($@)
Truth table33%1/3
A || B
A= eval " { $innerGettersAsString } "B= croak($@)
| |||||||||||||||||||||||||||||||||||
| 92 | 87 | ▶ | my $hashRefAccessors = eval " { $innerAccessorsAsString } " || croak $@; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
eval " { $innerAccessorsAsString } " || croak($@)
MC/DC0%0/2
eval " { $innerAccessorsAsString } " || croak($@)
eval " { $innerAccessorsAsString } "
croak($@)
Truth table33%1/3
A || B
A= eval " { $innerAccessorsAsString } "B= croak($@)
| |||||||||||||||||||||||||||||||||||
| 93 | 87 | Class::XSAccessor::Array->import::into($target, | |||||||||||||||||||||||||||||||||
| 94 | getters => $hashRefGetters, | ||||||||||||||||||||||||||||||||||
| 95 | accessors => $hashRefAccessors); | ||||||||||||||||||||||||||||||||||
| 96 | # | ||||||||||||||||||||||||||||||||||
| 97 | # 'has' is then dummy routine | ||||||||||||||||||||||||||||||||||
| 98 | # | ||||||||||||||||||||||||||||||||||
| 99 | 87 | ▶ | install_modifier($target, 'fresh', has => sub { }); | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 100 | # | ||||||||||||||||||||||||||||||||||
| 101 | # And our version of 'new': default constructor provided by Class::XSAccessor::Array | ||||||||||||||||||||||||||||||||||
| 102 | # is doing nothing useful | ||||||||||||||||||||||||||||||||||
| 103 | # | ||||||||||||||||||||||||||||||||||
| 104 | # | ||||||||||||||||||||||||||||||||||
| 105 | my $new = " | ||||||||||||||||||||||||||||||||||
| 106 | my (\$class, \%args) = \@_; | ||||||||||||||||||||||||||||||||||
| 107 | bless([" . | ||||||||||||||||||||||||||||||||||
| 108 | 87 | join(', ', map { "\$args{$indice2name[$_]}" } (0..$#indice2name)) . | |||||||||||||||||||||||||||||||||
| 109 | "], \$class) | ||||||||||||||||||||||||||||||||||
| 110 | "; | ||||||||||||||||||||||||||||||||||
| 111 | 87 | ▶ | my $stub = eval "sub { $new }" || croak $@; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
eval "sub { $new }" || croak($@)
MC/DC0%0/2
eval "sub { $new }" || croak($@)
eval "sub { $new }"
croak($@)
Truth table33%1/3
A || B
A= eval "sub { $new }"B= croak($@)
| |||||||||||||||||||||||||||||||||||
| 112 | 87 | install_modifier($target, 'fresh', new => $stub) | |||||||||||||||||||||||||||||||||
| 113 | } else { | ||||||||||||||||||||||||||||||||||
| 114 | # | ||||||||||||||||||||||||||||||||||
| 115 | # Our version of 'has'. We support only that. | ||||||||||||||||||||||||||||||||||
| 116 | # | ||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | install_modifier($target, 'fresh', has => sub { _has($target, @_) } ); | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 118 | # | ||||||||||||||||||||||||||||||||||
| 119 | # And our version of 'new'. | ||||||||||||||||||||||||||||||||||
| 120 | # | ||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | install_modifier($target, 'fresh', new => sub { _new($target, @_) } ) | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 122 | 0 | } | |||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||
| 124 | 87 | ▶ | if ($args{'""'}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 125 | # | ||||||||||||||||||||||||||||||||||
| 126 | # We provide a default stringification which always obey to the following: | ||||||||||||||||||||||||||||||||||
| 127 | # | ||||||||||||||||||||||||||||||||||
| 128 | # Any object always expand to: | ||||||||||||||||||||||||||||||||||
| 129 | # | ||||||||||||||||||||||||||||||||||
| 130 | # NAME [ | ||||||||||||||||||||||||||||||||||
| 131 | # DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 132 | # ] | ||||||||||||||||||||||||||||||||||
| 133 | # | ||||||||||||||||||||||||||||||||||
| 134 | # NAME default is the last blessed name component. Can be overwriten with $args{-name}. | ||||||||||||||||||||||||||||||||||
| 135 | # DESCRIPTION default is the stringified list of members in the following format: | ||||||||||||||||||||||||||||||||||
| 136 | # | ||||||||||||||||||||||||||||||||||
| 137 | # WHAT [",\n" WHAT [",\n" WHAT]] | ||||||||||||||||||||||||||||||||||
| 138 | # | ||||||||||||||||||||||||||||||||||
| 139 | # The list of members is always empty. Can be overwiten with $arg{'""'} = [LIST_OF_MEMBERS_TO_STRINGIFY]. | ||||||||||||||||||||||||||||||||||
| 140 | # | ||||||||||||||||||||||||||||||||||
| 141 | # LIST_OF_MEMBERS_TO_STRINGIFY impacts WHAT: | ||||||||||||||||||||||||||||||||||
| 142 | # - an arrayref [ x ] Stringified as "$self->x". x must be a CODE reference. | ||||||||||||||||||||||||||||||||||
| 143 | # - an arrayref [ x, y ] Stringified as "$self->x => $self->y". x and y must be CODE references. | ||||||||||||||||||||||||||||||||||
| 144 | # | ||||||||||||||||||||||||||||||||||
| 145 | # Any output is always automatically indented by adding two spaces ' ' to any stringified members if there | ||||||||||||||||||||||||||||||||||
| 146 | # is more than once member, or left on a single line if there at maximum one member. | ||||||||||||||||||||||||||||||||||
| 147 | # Indent can be overwriten with $arg{indent} | ||||||||||||||||||||||||||||||||||
| 148 | # | ||||||||||||||||||||||||||||||||||
| 149 | # Please note that there is type-checking on %args values. | ||||||||||||||||||||||||||||||||||
| 150 | # | ||||||||||||||||||||||||||||||||||
| 151 | 87 | ▶ | my $name = $args{-name} // (split(/::/, $target))[-1]; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args{"-name"} // (split(/::/, $target, 0))[-1]
MC/DC0%0/2
$args{"-name"} // (split(/::/, $target, 0))[-1]
$args{"-name"}
(split(/::/, $target, 0))[-1]
Truth table33%1/3
A // B
A= $args{"-name"}B= (split(/::/, $target, 0))[-1]
| |||||||||||||||||||||||||||||||||||
| 152 | 87 | ▶ | my $list = $args{'""'} // []; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"\"\""} // []
MC/DC0%0/1
$args{"\"\""} // []
$args{"\"\""}
Truth table50%1/2
A
A= $args{"\"\""}
| |||||||||||||||||||||||||||||||||||
| 153 | 87 | ▶ | my $indent = $args{-indent} // ' '; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"-indent"} // " "
MC/DC0%0/1
$args{"-indent"} // " "
$args{"-indent"}
Truth table50%1/2
A
A= $args{"-indent"}
| |||||||||||||||||||||||||||||||||||
| 154 | 87 | my $oneLineDescription = $args{-oneLineDescription}; | |||||||||||||||||||||||||||||||||
| 155 | 87 | ▶ | my $oneLineDescriptionJoinString = $args{-oneLineDescriptionJoinString} || ''; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'-oneLineDescriptionJoinString'} || ''
MC/DC100%1/1
$args{'-oneLineDescriptionJoinString'} || ''
$args{'-oneLineDescriptionJoinString'}
Truth table100%2/2
A
A= $args{'-oneLineDescriptionJoinString'}
| |||||||||||||||||||||||||||||||||||
| 156 | # | ||||||||||||||||||||||||||||||||||
| 157 | # Let our importer the possiblity to modify the stringification setup (not the stringification routine itself) | ||||||||||||||||||||||||||||||||||
| 158 | # | ||||||||||||||||||||||||||||||||||
| 159 | 87 | ▶ | install_modifier($target, 'fresh', stringifySetup => sub { $list }); | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||
| 161 | my $stub = sub { | ||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | my $setup = $_[0]->stringifySetup; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||||
| 163 | # | ||||||||||||||||||||||||||||||||||
| 164 | # There is no way to pass private arguments in the '""' overload | ||||||||||||||||||||||||||||||||||
| 165 | # this is why we use this localized variable | ||||||||||||||||||||||||||||||||||
| 166 | # | ||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | my $currentLevel = $MarpaX::Java::ClassFile::Struct::STRINGIFICATION_LEVEL // 0; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$MarpaX::Java::ClassFile::Struct::STRINGIFICATION_LEVEL // 0
MC/DC0%0/1
$MarpaX::Java::ClassFile::Struct::STRINGIFICATION_LEVEL // 0
$MarpaX::Java::ClassFile::Struct::STRINGIFICATION_LEVEL
Truth table0%0/2
A
A= $MarpaX::Java::ClassFile::Struct::STRINGIFICATION_LEVEL
| |||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | my $currentOneLine = $MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINE // $oneLineDescription; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINE // $oneLineDescription
MC/DC0%0/2
$MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINE // $oneLineDescription
$MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINE
$oneLineDescription
Truth table0%0/3
A // B
A= $MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINEB= $oneLineDescription
| |||||||||||||||||||||||||||||||||||
| 169 | # | ||||||||||||||||||||||||||||||||||
| 170 | # Current recursivity level represent a forced indentation | ||||||||||||||||||||||||||||||||||
| 171 | # when we deply a multiline output | ||||||||||||||||||||||||||||||||||
| 172 | # | ||||||||||||||||||||||||||||||||||
| 173 | 0 | my $forceIndent = $indent x $currentLevel; | |||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | my $localIndent = $#{$setup} ? $forceIndent . $indent : ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 175 | # | ||||||||||||||||||||||||||||||||||
| 176 | # We have to localize again, in case stringification happens | ||||||||||||||||||||||||||||||||||
| 177 | # implicitely INSIDE the callbacks, not explicitely | ||||||||||||||||||||||||||||||||||
| 178 | # | ||||||||||||||||||||||||||||||||||
| 179 | 0 | local $MarpaX::Java::ClassFile::Struct::STRINGIFICATION_LEVEL = ++$currentLevel; | |||||||||||||||||||||||||||||||||
| 180 | # | ||||||||||||||||||||||||||||||||||
| 181 | # For pretty printing, align the 'x'. | ||||||||||||||||||||||||||||||||||
| 182 | # In the case of one-line stringification only the originator of this pragma | ||||||||||||||||||||||||||||||||||
| 183 | # has x => y (when y is defined). Then all subsequent overloads return | ||||||||||||||||||||||||||||||||||
| 184 | # y in the case x=>y, x otherwise. | ||||||||||||||||||||||||||||||||||
| 185 | # | ||||||||||||||||||||||||||||||||||
| 186 | 0 | my (@x, @y); | |||||||||||||||||||||||||||||||||
| 187 | 0 | my $xMaxSize = 0; | |||||||||||||||||||||||||||||||||
| 188 | 0 | foreach (@{$setup}) { | |||||||||||||||||||||||||||||||||
| 189 | 0 | my ($x, $y) = @{$_}; | |||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if ($MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINE && $y) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINE and $y
MC/DC0%0/2
$MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINE and $y
$MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINE
$y
Truth table0%0/3
A and B
A= $MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINEB= $y
| |||||||||||||||||||||||||||||||||||
| 191 | 0 | local $MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINE = $currentOneLine; | |||||||||||||||||||||||||||||||||
| 192 | 0 | push(@x, $_[0]->$y); | |||||||||||||||||||||||||||||||||
| 193 | 0 | push(@y, undef) | |||||||||||||||||||||||||||||||||
| 194 | } else { | ||||||||||||||||||||||||||||||||||
| 195 | 0 | local $MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINE = $currentOneLine; | |||||||||||||||||||||||||||||||||
| 196 | 0 | push(@x, $_[0]->$x); | |||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | push(@y, $y ? $_[0]->$y : undef); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||
| 199 | 0 | my $lengthX = length($x[-1]); | |||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | $xMaxSize = $lengthX if ($lengthX > $xMaxSize) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||
| 202 | 0 | my $iDescription = 0; | |||||||||||||||||||||||||||||||||
| 203 | 0 | $xMaxSize = -$xMaxSize; # Left aligned x => y | |||||||||||||||||||||||||||||||||
| 204 | my @description = map { | ||||||||||||||||||||||||||||||||||
| 205 | 0 | my ($x, $y) = @{$setup->[$_]}; | |||||||||||||||||||||||||||||||||
| 206 | 0 | my $xDescription = sprintf('%*s', $xMaxSize, $x[$_]); | |||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if ($MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINE && $y) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINE and $y
MC/DC0%0/2
$MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINE and $y
$MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINE
$y
Truth table0%0/3
A and B
A= $MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINEB= $y
| |||||||||||||||||||||||||||||||||||
| 208 | # | ||||||||||||||||||||||||||||||||||
| 209 | # No local indentation in the oneline mode | ||||||||||||||||||||||||||||||||||
| 210 | # | ||||||||||||||||||||||||||||||||||
| 211 | 0 | $x[$_] | |||||||||||||||||||||||||||||||||
| 212 | } else { | ||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | $localIndent . ($y ? join(' => ', $xDescription, $y[$_]) : $x[$_]) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||
| 215 | } (0..$#x); | ||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | if ($MarpaX::Java::ClassFile::Struct::STRINGIFICATION_ONELINE) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 217 | 0 | join($oneLineDescriptionJoinString, @description) | |||||||||||||||||||||||||||||||||
| 218 | } else { | ||||||||||||||||||||||||||||||||||
| 219 | 0 | my $description = join(",\n", @description); | |||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | ($#{$setup} > 0) ? "${name} [\n${description}\n$forceIndent]" : "${name} [${description}]" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||
| 222 | 87 | }; | |||||||||||||||||||||||||||||||||
| 223 | # | ||||||||||||||||||||||||||||||||||
| 224 | # Inject overload | ||||||||||||||||||||||||||||||||||
| 225 | # | ||||||||||||||||||||||||||||||||||
| 226 | 87 | overload->import::into($target, '""' => $stub) | |||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||
| 230 | sub _has { | ||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | my $target = shift; | ||||||||||||||||||||||||||||||||
|
Subroutine
_has: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||
| 232 | 0 | my $name = shift; | |||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | my @proto = ((reftype($name) //'') eq 'ARRAY') ? @{$name} : $name; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
builtin::reftype($name) // ""
MC/DC0%0/1
builtin::reftype($name) // ""
builtin::reftype($name)
Truth table0%0/2
A
A= builtin::reftype($name)
| |||||||||||||||||||||||||||||||||||
| 234 | # | ||||||||||||||||||||||||||||||||||
| 235 | # No check, will carp naturally if this does not expand to a hash | ||||||||||||||||||||||||||||||||||
| 236 | # | ||||||||||||||||||||||||||||||||||
| 237 | 0 | my %spec = @_; | |||||||||||||||||||||||||||||||||
| 238 | # | ||||||||||||||||||||||||||||||||||
| 239 | # Keep track of members as the 'has' appears | ||||||||||||||||||||||||||||||||||
| 240 | # | ||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | my $has_tracked = $_HAS_TRACKED{$target} //= {}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$_HAS_TRACKED{$target} //= {}
MC/DC0%0/1
$_HAS_TRACKED{$target} //= {}
$_HAS_TRACKED{$target}
Truth table0%0/2
A
A= $_HAS_TRACKED{$target}
| |||||||||||||||||||||||||||||||||||
| 242 | 0 | foreach my $proto (@proto) { | |||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | next if (exists($has_tracked->{$proto})); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 244 | # | ||||||||||||||||||||||||||||||||||
| 245 | # Member not yet registered | ||||||||||||||||||||||||||||||||||
| 246 | # | ||||||||||||||||||||||||||||||||||
| 247 | 0 | my $proto_indice = scalar(keys %{$has_tracked}); | |||||||||||||||||||||||||||||||||
| 248 | 0 | $has_tracked->{$proto} = $proto_indice; | |||||||||||||||||||||||||||||||||
| 249 | # | ||||||||||||||||||||||||||||||||||
| 250 | # We do NO CHECK whatever on 'is', 'isa', etc... | ||||||||||||||||||||||||||||||||||
| 251 | # Everything is assumed to be a mutator eventually initalized at new() time. | ||||||||||||||||||||||||||||||||||
| 252 | # There is NO type checking - full point. | ||||||||||||||||||||||||||||||||||
| 253 | # | ||||||||||||||||||||||||||||||||||
| 254 | # Oh, our new() ensures everything is a reference, so reftype() always return a non-null value. | ||||||||||||||||||||||||||||||||||
| 255 | # | ||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | $_GETTER[$proto_indice] //= eval "sub { \$_[0]->[$proto_indice] = \$_[1] if (\$#_); my \$value = \$_[0]->[$proto_indice]; (Scalar::Util::reftype(\$value) eq 'SCALAR') ? \${\$value} : \$value }" || croak $@; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$_GETTER[$proto_indice] //= eval "sub { \$_[0]->[$proto_indice] = \$_[1] if (\$#_); my \$value = \$_[0]->[$proto_indice]; (Scalar::Util::reftype(\$value) eq 'SCALAR') ? \${\$value} : \$value }" || croak($@)
eval "sub { \$_[0]->[$proto_indice] = \$_[1] if (\$#_); my \$value = \$_[0]->[$proto_indice]; (Scalar::Util::reftype(\$value) eq 'SCALAR') ? \${\$value} : \$value }" || croak($@)
MC/DC0%0/3
$_GETTER[$proto_indice] //= eval "sub { \$_[0]->[$proto_indice] = \$_[1] if (\$#_); my \$value = \$_[0]->[$proto_indice]; (Scalar::Util::reftype(\$value) eq 'SCALAR') ? \${\$value} : \$value }" || croak($@)
$_GETTER[$proto_indice]
eval "sub { \$_[0]->[$proto_indice] = \$_[1] if (\$#_); my \$value = \$_[0]->[$proto_indice]; (Scalar::Util::reftype(\$value) eq 'SCALAR') ? \${\$value} : \$value }"
croak($@)
Truth table0%0/4
A //= B || C
A= $_GETTER[$proto_indice]B= eval "sub { \$_[0]->[$proto_indice] = \$_[1] if (\$#_); my \$value = \$_[0]->[$proto_indice]; (Scalar::Util::reftype(\$value) eq 'SCALAR') ? \${\$value} : \$value }"C= croak($@)
| |||||||||||||||||||||||||||||||||||
| 257 | 0 | install_modifier($target, 'fresh', $proto => $_GETTER[$proto_indice]) | |||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||
| 261 | sub _new { | ||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | my ($target, $class, %args) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_new: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||
| 264 | 0 | my $has_tracked = $_HAS_TRACKED{$target}; | |||||||||||||||||||||||||||||||||
| 265 | 0 | my @array = (); | |||||||||||||||||||||||||||||||||
| 266 | 0 | foreach my $proto (keys %{$has_tracked}) { | |||||||||||||||||||||||||||||||||
| 267 | 0 | my $value = $args{$proto}; | |||||||||||||||||||||||||||||||||
| 268 | 0 | my $indice = $has_tracked->{$proto}; | |||||||||||||||||||||||||||||||||
| 269 | # | ||||||||||||||||||||||||||||||||||
| 270 | # NO type checking nor safety checking | ||||||||||||||||||||||||||||||||||
| 271 | # | ||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if (blessed($value)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 273 | 0 | $array[$indice] = $args{$proto} | |||||||||||||||||||||||||||||||||
| 274 | } else { | ||||||||||||||||||||||||||||||||||
| 275 | # | ||||||||||||||||||||||||||||||||||
| 276 | # scalars are explicitely stored as a reference (i.e. ref() will return 'SCALAR' | ||||||||||||||||||||||||||||||||||
| 277 | # | ||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | if (ref($value)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 279 | 0 | $array[$indice] = bless($value, $proto) | |||||||||||||||||||||||||||||||||
| 280 | } else { | ||||||||||||||||||||||||||||||||||
| 281 | 0 | $array[$indice] = bless(\$value, $proto) | |||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||
| 285 | # | ||||||||||||||||||||||||||||||||||
| 286 | # In conclusion...: reftype() will never return a null value | ||||||||||||||||||||||||||||||||||
| 287 | # | ||||||||||||||||||||||||||||||||||
| 288 | 0 | bless(\@array, $class) | |||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||
| 291 | 88 | 1; | |||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||
| 293 | __END__ | ||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||
| 295 | =pod | ||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||
| 297 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||
| 299 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||
| 301 | MarpaX::Java::ClassFile::Struct::_Base - Base class for all structure - optimized to a very basic array-based object in production mode | ||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||
| 303 | =head1 VERSION | ||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||
| 305 | version 0.008 | ||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||
| 307 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||
| 309 | Jean-Damien Durand <jeandamiendurand@free.fr> | ||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||
| 311 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||
| 313 | This software is copyright (c) 2016 by Jean-Damien Durand. | ||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||
| 315 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||
| 316 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||
| 318 | =cut | ||||||||||||||||||||||||||||||||||