| 1 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # MODULE: Convert::Binary::C::Cached | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # DESCRIPTION: Cached version of Convert::Binary::C module | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||
| 9 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # Copyright (c) 2002-2020 Marcus Holland-Moritz. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||
| 15 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | package Convert::Binary::C::Cached; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | ▶ | use Convert::Binary::C; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | ▶ | use vars qw( @ISA $VERSION ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | @ISA = qw(Convert::Binary::C); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | $VERSION = '0.84'; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 938 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 938 | my $self = $class->SUPER::new; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 938 | $self->{cache} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 938 | $self->{parsed} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 938 | $self->{uses_cache} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 938 | ▶ | @_ % 2 and croak "Number of configuration arguments to new must be even"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 937 | ▶ | @_ and $self->configure(@_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 934 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | sub configure | ||||||||||||||||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 1973 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
configure: called CC=20 SCAR=30.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1973 | ▶ | if (@_ < 2 and not defined wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ < 2 and not defined wantarray
MC/DC100%2/2
@_ < 2 and not defined wantarray
@_ < 2
not defined wantarray
Truth table100%3/3
A and not(B)
A= @_ < 2B= not defined wantarray
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | $^W and carp "Useless use of configure in void context"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 1970 | ▶ | if (@_ == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 960 | my $cfg = $self->SUPER::configure; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 960 | $cfg->{Cache} = $self->{cache}; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 960 | return $cfg; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | ▶ | elsif (@_ == 1 and $_[0] eq 'Cache') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
@_ == 1 and $_[0] eq "Cache"
MC/DC0%0/2
@_ == 1 and $_[0] eq "Cache"
@_ == 1
$_[0] eq "Cache"
Truth table33%1/3
A and B
A= @_ == 1B= $_[0] eq "Cache"
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return $self->{cache}; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 1010 | my @args; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 1010 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | elsif (@_ % 2 == 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 1010 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 1373 | my %arg = splice @_, 0, 2; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 1373 | ▶ | if (exists $arg{Cache}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 930 | ▶ | if ($self->{parsed}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | croak 'Cache cannot be configured after parsing'; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | elsif (ref $arg{Cache}) { | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | croak 'Cache must be a string value, not a reference'; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 929 | ▶ | if (defined $arg{Cache}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 929 | my @missing; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 929 | eval { require Data::Dumper }; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 929 | ▶ | $@ and push @missing, 'Data::Dumper'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 929 | eval { require IO::File }; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 929 | ▶ | $@ and push @missing, 'IO::File'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 929 | ▶ | if (@missing) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | ▶ | $^W and carp "Cannot load ", join(' and ', @missing), ", disabling cache"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | undef $arg{Cache}; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 929 | $self->{cache} = $arg{Cache}; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 443 | else { push @args, %arg } | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 1009 | my $opt = $self; | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 1009 | ▶ | if (@args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 117 | $opt = eval { $self->SUPER::configure(@args) }; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 117 | ▶ | $@ =~ s/\s+at.*?Cached\.pm.*//s, croak $@ if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 965 | $opt; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | sub clean | ||||||||||||||||||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 46 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 46 | delete $self->{$_} for grep !/^(?:|cache|parsed|uses_cache)$/, keys %$self; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 46 | $self->{parsed} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 46 | $self->{uses_cache} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 46 | $self->SUPER::clean; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | sub clone | ||||||||||||||||||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=6 SCAR=26.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 3 | ▶ | unless (defined wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | ▶ | $^W and carp "Useless use of clone in void context"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $clone = $self->SUPER::clone; | |||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | for (keys %$self) { | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ($_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | $clone->{$_} = ref $_ eq 'ARRAY' ? [@{$self->{$_}}] : $self->{$_}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $clone; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | sub parse_file | ||||||||||||||||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 47 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_file: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 47 | my($warn,$error) = $self->__parse('file', $_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 46 | for my $w ( @$warn ) { carp $w } | |||||||||||||||||||||||||||||||||||||||||
| 143 | 46 | ▶ | defined $error and croak $error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 40 | ▶ | defined wantarray and return $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | sub parse | ||||||||||||||||||||||||||||||||||||||||||
| 148 | { | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 976 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 976 | my($warn,$error) = $self->__parse('code', $_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 151 | 975 | for my $w ( @$warn ) { carp $w } | |||||||||||||||||||||||||||||||||||||||||
| 152 | 975 | ▶ | defined $error and croak $error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 918 | ▶ | defined wantarray and return $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | sub dependencies | ||||||||||||||||||||||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 20 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dependencies: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 20 | ▶ | $self->{parsed} or croak "Call to dependencies without parse data"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 17 | ▶ | unless (defined wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 3 | ▶ | $^W and carp "Useless use of dependencies in void context"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 14 | ▶ | $self->{files} || $self->SUPER::dependencies; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | sub __uses_cache | ||||||||||||||||||||||||||||||||||||||||||
| 171 | { | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 904 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__uses_cache: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 904 | $self->{uses_cache}; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | sub __parse | ||||||||||||||||||||||||||||||||||||||||||
| 177 | { | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 1023 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__parse: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 1023 | ▶ | if (defined $self->{cache}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 927 | ▶ | $self->{parsed} and croak "Cannot parse more than once for cached objects"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 926 | $self->{$_[0]} = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 926 | ▶ | if ($self->__can_use_cache) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 43 | my @WARN; | |||||||||||||||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 43 | ▶ | local $SIG{__WARN__} = sub { push @WARN, $_[0] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 43 | eval { $self->SUPER::parse_file($self->{cache}) }; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 43 | ▶ | unless ($@ or @WARN) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$@ or @WARN
MC/DC50%1/2
$@ or @WARN
$@
@WARN
Truth table66%2/3
A or B
A= $@B= @WARN
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 26 | $self->{parsed} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 26 | $self->{uses_cache} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 26 | return; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 17 | $self->clean; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 996 | $self->{parsed} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 996 | my(@warnings, $error); | |||||||||||||||||||||||||||||||||||||||||
| 203 | { | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 996 | ▶ | local $SIG{__WARN__} = sub { push @warnings, $_[0] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 996 | ▶ | if ($_[0] eq 'file') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 23 | eval { $self->SUPER::parse_file($_[1]) }; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 973 | eval { $self->SUPER::parse($_[1]) }; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 996 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 63 | $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 63 | $error =~ s/\s+at.*?Cached\.pm.*//s; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 933 | ▶ | defined $self->{cache} and $self->__save_cache; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 995 | for (@warnings) { s/\s+at.*?Cached\.pm.*//s } | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 995 | (\@warnings, $error); | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | sub __can_use_cache | ||||||||||||||||||||||||||||||||||||||||||
| 228 | { | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 926 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__can_use_cache: called CC=28 SCAR=39.3
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 926 | my $fh = IO::File->new; | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 926 | ▶ | unless (-e $self->{cache} and -s _) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-e $self->{"cache"} and -s _
MC/DC50%1/2
-e $self->{"cache"} and -s _
-e $self->{"cache"}
-s _
Truth table66%2/3
A and B
A= -e $self->{"cache"}B= -s _
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 5 | ▶ | $ENV{CBCC_DEBUG} and print STDERR "CBCC: cache file '$self->{cache}' doesn't exist or is empty\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 921 | ▶ | unless ($fh->open($self->{cache})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | $^W and carp "Cannot open '$self->{cache}': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | $ENV{CBCC_DEBUG} and print STDERR "CBCC: cannot open cache file '$self->{cache}'\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 921 | my @warnings; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 921 | my @config = do { | |||||||||||||||||||||||||||||||||||||||||
| 245 | 921 | my $config; | |||||||||||||||||||||||||||||||||||||||||
| 246 | 921 | ▶ | unless (defined($config = <$fh>)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | $ENV{CBCC_DEBUG} and print STDERR "CBCC: cannot read configuration\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 921 | ▶ | unless ($config =~ /^#if\s+0/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 5 | ▶ | $ENV{CBCC_DEBUG} and print STDERR "CBCC: invalid configuration\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 5 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 916 | local $/ = $/.'#endif'; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 916 | chomp($config = <$fh>); | |||||||||||||||||||||||||||||||||||||||||
| 256 | 916 | $config =~ s/^\*//gms; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 916 | ▶ | local $SIG{__WARN__} = sub { push @warnings, $_[0] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 916 | eval $config; | |||||||||||||||||||||||||||||||||||||||||
| 259 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | # corrupt config | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 916 | ▶ | if ($@ or @warnings or @config % 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$@ or @warnings or @config % 2
$@ or @warnings
MC/DC33%1/3
$@ or @warnings or @config % 2
$@
@warnings
@config % 2
Truth table50%2/4
A or B or C
A= $@B= @warningsC= @config % 2
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 867 | ▶ | $ENV{CBCC_DEBUG} and print STDERR "CBCC: broken configuration\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 867 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 49 | my %config = @config; | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 49 | ▶ | my $what = exists $self->{code} ? 'code' : 'file'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 49 | ▶ | unless (exists $config{$what} and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
exists $config{$what} and $config{$what} eq $self->{$what} and __reccmp($config{"cfg"}, $self->configure)
exists $config{$what} and $config{$what} eq $self->{$what}
MC/DC100%3/3
exists $config{$what} and $config{$what} eq $self->{$what} and __reccmp($config{"cfg"}, $self->configure)
exists $config{$what}
$config{$what} eq $self->{$what}
__reccmp($config{"cfg"}, $self->configure)
Truth table100%4/4
A and B and C
A= exists $config{$what}B= $config{$what} eq $self->{$what}C= __reccmp($config{"cfg"}, $self->configure)
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | $config{$what} eq $self->{$what} and | ||||||||||||||||||||||||||||||||||||||||||
| 273 | __reccmp($config{cfg}, $self->configure)) { | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 3 | ▶ | if ($ENV{CBCC_DEBUG}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | print STDERR "CBCC: configuration has changed\n"; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | print STDERR "CBCC: what='$what', \$config{$what}='$config{$what}' \$self->{$what}='$self->{$what}'\n"; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | my $dump = Data::Dumper->Dump([$config{cfg}, $self->configure], ['config', 'self']); | |||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $dump =~ s/^/CBCC: /mg; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | print STDERR $dump; | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 46 | ▶ | while (my($file, $spec) = each %{$config{files}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 936 | ▶ | unless (-e $file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | $ENV{CBCC_DEBUG} and print STDERR "CBCC: file '$file' deleted\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 936 | my($size, $mtime, $ctime) = (stat(_))[7,9,10]; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 936 | ▶ | unless ($spec->{size} == $size and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$spec->{"size"} == $size and $spec->{"mtime"} == $mtime and $spec->{"ctime"} == $ctime
$spec->{"size"} == $size and $spec->{"mtime"} == $mtime
MC/DC66%2/3
$spec->{"size"} == $size and $spec->{"mtime"} == $mtime and $spec->{"ctime"} == $ctime
$spec->{"size"} == $size
$spec->{"mtime"} == $mtime
$spec->{"ctime"} == $ctime
Truth table75%3/4
A and B and C
A= $spec->{"size"} == $sizeB= $spec->{"mtime"} == $mtimeC= $spec->{"ctime"} == $ctime
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | $spec->{mtime} == $mtime and | ||||||||||||||||||||||||||||||||||||||||||
| 292 | $spec->{ctime} == $ctime) { | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 3 | ▶ | $ENV{CBCC_DEBUG} and print STDERR "CBCC: size/mtime/ctime of '$file' changed\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 43 | $self->{files} = $config{files}; | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 43 | ▶ | $ENV{CBCC_DEBUG} and print STDERR "CBCC: '$self->{cache}' is usable\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 43 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | sub __save_cache | ||||||||||||||||||||||||||||||||||||||||||
| 305 | { | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 900 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__save_cache: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 900 | my $fh = IO::File->new; | |||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 900 | ▶ | $fh->open(">$self->{cache}") or croak "Cannot open '$self->{cache}': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 899 | ▶ | my $what = exists $self->{code} ? 'code' : 'file'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 899 | my $config = Data::Dumper->new([{ $what => $self->{$what}, | |||||||||||||||||||||||||||||||||||||||||
| 314 | cfg => $self->configure, | ||||||||||||||||||||||||||||||||||||||||||
| 315 | files => scalar $self->SUPER::dependencies, | ||||||||||||||||||||||||||||||||||||||||||
| 316 | }], ['*'])->Indent(1)->Dump; | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 899 | $config =~ s/[^(]*//; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 899 | $config =~ s/^/*/gms; | |||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | print $fh "#if 0\n", $config, "#endif\n\n", | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 899 | do { local $^W; $self->sourcify({ Context => 1 }) }; | |||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | sub __reccmp | ||||||||||||||||||||||||||||||||||||||||||
| 325 | { | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 3499 | ▶ | my($ref, $val) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__reccmp: called CC=14 SCAR=27.7
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 3499 | ▶ | !defined($ref) && !defined($val) and return 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $ref or defined $val
MC/DC50%1/2
defined $ref or defined $val
defined $ref
defined $val
Truth table66%2/3
A or B
A= defined $refB= defined $val
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 3489 | ▶ | !defined($ref) || !defined($val) and return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $ref and defined $val
MC/DC0%0/2
defined $ref and defined $val
defined $ref
defined $val
Truth table33%1/3
A and B
A= defined $refB= defined $val
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 3489 | ▶ | ref $ref or return $ref eq $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 325 | ▶ | if (ref $ref eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 186 | ▶ | @$ref == @$val or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 185 | for (0..$#$ref) { | |||||||||||||||||||||||||||||||||||||||||
| 336 | 2044 | ▶ | __reccmp($ref->[$_], $val->[$_]) or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | elsif (ref $ref eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 139 | ▶ | keys %$ref == keys %$val or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 139 | for (keys %$ref) { | |||||||||||||||||||||||||||||||||||||||||
| 342 | 1408 | ▶ | __reccmp($ref->{$_}, $val->{$_}) or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | else { return 0 } | |||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | 323 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | __END__ | ||||||||||||||||||||||||||||||||||||||||||