| 1 | package TUI::Dialogs::HistoryViewer::HistList; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Implements the behavior of the HistRec list | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 14 | our $VERSION = '2.000002'; | |||||||||||||||||||||||||||
| 9 | 14 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 10 | 14 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 14 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 14 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 14 | historyCount | ||||||||||||||||||||||||||||
| 15 | historyAdd | ||||||||||||||||||||||||||||
| 16 | historyStr | ||||||||||||||||||||||||||||
| 17 | clearHistory | ||||||||||||||||||||||||||||
| 18 | initHistory | ||||||||||||||||||||||||||||
| 19 | doneHistory | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 14 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||
| 23 | all => \@EXPORT_OK, | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 14 | ▶ | use TUI::toolkit qw( :utils ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 14 | ▶ | use TUI::toolkit::Types qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | Maybe | ||||||||||||||||||||||||||||
| 29 | :Int | ||||||||||||||||||||||||||||
| 30 | :Str | ||||||||||||||||||||||||||||
| 31 | 14 | ); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # declare global variables | ||||||||||||||||||||||||||||
| 34 | 14 | our $historyBlock = undef; # array reference, not a packed string | |||||||||||||||||||||||||||
| 35 | 14 | our $historySize = 1024; # initial size of history block | |||||||||||||||||||||||||||
| 36 | 14 | our $historyUsed = 0; # taken from the Turbo Pascal implementation | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # predeclare private subs | ||||||||||||||||||||||||||||
| 39 | my ( | ||||||||||||||||||||||||||||
| 40 | 14 | $advanceStringPointer, | |||||||||||||||||||||||||||
| 41 | $deleteString, | ||||||||||||||||||||||||||||
| 42 | $insertString, | ||||||||||||||||||||||||||||
| 43 | $startId, | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # declare local variables | ||||||||||||||||||||||||||||
| 47 | 14 | my $curId; | |||||||||||||||||||||||||||
| 48 | 14 | my $curRec; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # Advance curRec to next string with an id of $curId | ||||||||||||||||||||||||||||
| 51 | 27 | ▶ | $advanceStringPointer = sub { # void () | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.8
| |||||||||||||||||||||||||||||
| 52 | 27 | ▶ | assert ( @_ == 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 27 | $curRec++; | |||||||||||||||||||||||||||
| 54 | 27 | ▶ | while ( $curRec < $historyUsed && $historyBlock->[$curRec]->{id} != $curId ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$curRec < $TUI::Dialogs::HistoryViewer::HistList::historyUsed and $TUI::Dialogs::HistoryViewer::HistList::historyBlock->[$curRec]{"id"} != $curId
MC/DC0%0/2
$curRec < $TUI::Dialogs::HistoryViewer::HistList::historyUsed and $TUI::Dialogs::HistoryViewer::HistList::historyBlock->[$curRec]{"id"} != $curId
$curRec < $TUI::Dialogs::HistoryViewer::HistList::historyUsed
$TUI::Dialogs::HistoryViewer::HistList::historyBlock->[$curRec]{"id"} != $curId
Truth table66%2/3
A and B
A= $curRec < $TUI::Dialogs::HistoryViewer::HistList::historyUsedB= $TUI::Dialogs::HistoryViewer::HistList::historyBlock->[$curRec]{"id"} != $curId
| |||||||||||||||||||||||||||||
| 55 | 0 | $curRec++; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 27 | ▶ | $curRec = -1 if $curRec >= $historyUsed; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 27 | return; | |||||||||||||||||||||||||||
| 59 | 14 | }; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # Deletes the current string from the table | ||||||||||||||||||||||||||||
| 62 | 1 | ▶ | $deleteString = sub { # void () | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||
| 63 | 1 | ▶ | assert ( @_ == 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 1 | ▶ | splice( @$historyBlock, $curRec, 1 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | if $curRec < @$historyBlock; | ||||||||||||||||||||||||||||
| 66 | 1 | $historyUsed = @$historyBlock; | |||||||||||||||||||||||||||
| 67 | 1 | return; | |||||||||||||||||||||||||||
| 68 | 14 | }; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # Insert a string into the table | ||||||||||||||||||||||||||||
| 71 | 6 | ▶ | $insertString = sub { # void ($id, $str) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 72 | 6 | my ( $id, $str ) = @_; | |||||||||||||||||||||||||||
| 73 | 6 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 6 | ▶ | assert ( is_Int $id ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 6 | ▶ | assert ( is_Str $str ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 6 | my $len = length $str; | |||||||||||||||||||||||||||
| 77 | 6 | my $n = @$historyBlock; | |||||||||||||||||||||||||||
| 78 | 6 | my $size = 0; | |||||||||||||||||||||||||||
| 79 | 6 | for ( reverse @$historyBlock ) { | |||||||||||||||||||||||||||
| 80 | 4 | ▶ | last if $len > $historySize - $size; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 3 | $size += length $_->{str}; | |||||||||||||||||||||||||||
| 82 | 3 | $n--; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 6 | ▶ | splice( @$historyBlock, 0, $n ) if $n > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 6 | push @$historyBlock => { id => $id, str => $str }; | |||||||||||||||||||||||||||
| 86 | 6 | $historyUsed = @$historyBlock; | |||||||||||||||||||||||||||
| 87 | 6 | return; | |||||||||||||||||||||||||||
| 88 | 14 | }; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 14 | ▶ | $startId = sub { # void ($id) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 91 | 14 | ▶ | assert ( @_ == 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 14 | ▶ | assert ( is_Int $_[0] ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 14 | $curId = shift; | |||||||||||||||||||||||||||
| 94 | 14 | $curRec = -1; | |||||||||||||||||||||||||||
| 95 | 14 | return; | |||||||||||||||||||||||||||
| 96 | 14 | }; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 6 | ▶ | sub historyAdd { # void ($id, $str|undef) | ||||||||||||||||||||||||||
|
Subroutine
historyAdd: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 6 | state $sig = signature( | |||||||||||||||||||||||||||
| 100 | pos => [Int, Maybe[Str]] | ||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||
| 102 | 6 | my ( $id, $str ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 6 | ▶ | return unless defined $str; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 6 | &$startId( $id ); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # Delete duplicates | ||||||||||||||||||||||||||||
| 108 | 6 | &$advanceStringPointer(); | |||||||||||||||||||||||||||
| 109 | 6 | ▶ | while ( $curRec >= 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | &$deleteString() | ||||||||||||||||||||||||||||
| 111 | 5 | ▶ | if $str eq $historyBlock->[$curRec]->{str}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 5 | &$advanceStringPointer(); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 6 | &$insertString( $id, $str ); | |||||||||||||||||||||||||||
| 116 | 6 | return; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 4 | ▶ | sub historyCount { # $count ($id) | ||||||||||||||||||||||||||
|
Subroutine
historyCount: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | 4 | state $sig = signature( | |||||||||||||||||||||||||||
| 121 | pos => [Int] | ||||||||||||||||||||||||||||
| 122 | ); | ||||||||||||||||||||||||||||
| 123 | 4 | my ( $id ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 4 | &$startId( $id ); | |||||||||||||||||||||||||||
| 126 | 4 | my $count = 0; | |||||||||||||||||||||||||||
| 127 | 4 | &$advanceStringPointer(); | |||||||||||||||||||||||||||
| 128 | 4 | ▶ | while ( $curRec >= 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 6 | $count++; | |||||||||||||||||||||||||||
| 130 | 6 | &$advanceStringPointer(); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | 4 | return $count; | |||||||||||||||||||||||||||
| 133 | } #/ sub historyCount | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 4 | ▶ | sub historyStr { # $str ($id, $index) | ||||||||||||||||||||||||||
|
Subroutine
historyStr: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 136 | 4 | state $sig = signature( | |||||||||||||||||||||||||||
| 137 | pos => [Int, Int] | ||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||
| 139 | 4 | my ( $id, $index ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 4 | &$startId( $id ); | |||||||||||||||||||||||||||
| 142 | 4 | &$advanceStringPointer() for ( 0..$index ); | |||||||||||||||||||||||||||
| 143 | return $curRec >= 0 | ||||||||||||||||||||||||||||
| 144 | ? $historyBlock->[$curRec]->{str} | ||||||||||||||||||||||||||||
| 145 | 4 | ▶ | : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 2 | ▶ | sub clearHistory { # void () | ||||||||||||||||||||||||||
|
Subroutine
clearHistory: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 149 | 2 | state $sig = signature( | |||||||||||||||||||||||||||
| 150 | pos => [] | ||||||||||||||||||||||||||||
| 151 | ); | ||||||||||||||||||||||||||||
| 152 | 2 | $sig->( @_ ); | |||||||||||||||||||||||||||
| 153 | 2 | $historyBlock = []; | |||||||||||||||||||||||||||
| 154 | 2 | $historyUsed = @$historyBlock; | |||||||||||||||||||||||||||
| 155 | return | ||||||||||||||||||||||||||||
| 156 | 2 | } | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 1 | ▶ | sub initHistory { # void () | ||||||||||||||||||||||||||
|
Subroutine
initHistory: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | 1 | state $sig = signature( | |||||||||||||||||||||||||||
| 160 | pos => [] | ||||||||||||||||||||||||||||
| 161 | ); | ||||||||||||||||||||||||||||
| 162 | 1 | $sig->( @_ ); | |||||||||||||||||||||||||||
| 163 | 1 | clearHistory(); | |||||||||||||||||||||||||||
| 164 | return | ||||||||||||||||||||||||||||
| 165 | 1 | } | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 4 | ▶ | sub doneHistory { # void () | ||||||||||||||||||||||||||
|
Subroutine
doneHistory: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 168 | 4 | state $sig = signature( | |||||||||||||||||||||||||||
| 169 | pos => [] | ||||||||||||||||||||||||||||
| 170 | ); | ||||||||||||||||||||||||||||
| 171 | 4 | $sig->( @_ ); | |||||||||||||||||||||||||||
| 172 | 4 | $historyBlock = undef; | |||||||||||||||||||||||||||
| 173 | 4 | $historyUsed = 0; | |||||||||||||||||||||||||||
| 174 | return | ||||||||||||||||||||||||||||
| 175 | 4 | } | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 14 | 1 | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | __END__ | ||||||||||||||||||||||||||||