| 1 | # Copyright 2011, 2012, 2013, 2014, 2016, 2019, 2020 Kevin Ryde | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # This file is part of Math-NumSeq. | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Math-NumSeq is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # it under the terms of the GNU General Public License as published by the | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Free Software Foundation; either version 3, or (at your option) any later | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # version. | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Math-NumSeq is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # for more details. | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # You should have received a copy of the GNU General Public License along | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # characteristic('increasing') | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # characteristic('integer') | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # only by reading the whole file | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # assume seekable | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | package Math::NumSeq::File; | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use 5.004; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | use vars '$VERSION', '@ISA'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | $VERSION = 75; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | use Math::NumSeq; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | @ISA = ('Math::NumSeq'); | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | *_to_bigint = \&Math::NumSeq::_to_bigint; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # uncomment this to run the ### lines | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | #use Smart::Comments; | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # use constant name => Math::NumSeq::__('File'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | use constant i_start => 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | use constant description => Math::NumSeq::__('Numbers from a file'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | use constant parameter_info_array => | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | [ { name => 'filename', | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | type => 'filename', | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | display => Math::NumSeq::__('Filename'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | width => 40, | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | default => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | } ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | my $max_value = POSIX::FLT_RADIX() ** (POSIX::DBL_MANT_DIG()-5); | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | if ((~0 >> 1) > $max_value) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | $max_value = (~0 >> 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | my $min_value = -$max_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | sub rewind { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rewind: called CC=6 SCAR=20.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | ### Values-File rewind() | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | ▶ | if ($self->{'fh'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | _seek ($self, 0); | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | my $filename = $self->{'filename'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | if (defined $filename && $filename !~ /^\s*$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $filename and not $filename =~ /^\s*$/
MC/DC0%0/2
defined $filename and not $filename =~ /^\s*$/
defined $filename
not $filename =~ /^\s*$/
Truth table33%1/3
A and not(B)
A= defined $filenameB= not $filename =~ /^\s*$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | my $fh; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | ($] >= 5.006 | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ? open $fh, '<', $filename | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | : open $fh, "< $filename") | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | or croak "Cannot open ",$filename,": ",$!; | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | $self->{'fh'} = $fh; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | $self->{'i'} = $self->i_start - 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 4 | ▶ | sub next { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: called CC=8 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 4 | ▶ | my $fh = $self->{'fh'} || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'fh'} || (return)
MC/DC0%0/1
$self->{'fh'} || (return)
$self->{'fh'}
Truth table50%1/2
A
A= $self->{'fh'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | for (;;) { | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 22 | my $line = readline $fh; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 22 | ▶ | if (! defined $line) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ### EOF ... | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 21 | ▶ | if ($line =~ /^\s*(-?\d+)(\s+(-?(\d+(\.\d*)?|\.\d+)))?/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | my ($i, $value); | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | ▶ | if (defined $3) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | $i = $self->{'i'} = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | $value = $3; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $i = ++$self->{'i'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $value = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # large integer values returned as Math::BigInt | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | ▶ | if (($value > $max_value || $value < $min_value) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$value > $max_value || $value < $min_value and not $value =~ /\./
$value > $max_value or $value < $min_value
MC/DC0%0/3
$value > $max_value || $value < $min_value and not $value =~ /\./
$value > $max_value
$value < $min_value
not $value =~ /\./
Truth table20%1/5
A or B and not(C)
A= $value > $max_valueB= $value < $min_valueC= not $value =~ /\./
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | && $value !~ /\./) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $value = _to_bigint($value); | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | return ($i, $value); | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub _seek { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_seek: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my ($self, $pos) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | seek ($self->{'fh'}, $pos, 0) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | or croak "Cannot seek $self->{'filename'}: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||