| 1 | package TUI::Help::HelpTopic; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: help-topic paragraphs, wrapping, and cross-references | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 9 | our $VERSION = '2.000003'; | |||||||||||||||||||||||||||
| 9 | 9 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 10 | 9 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 9 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 9 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 14 | THelpTopic | ||||||||||||||||||||||||||||
| 15 | new_THelpTopic | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 9 | ▶ | use Storable qw( freeze thaw ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 9 | ▶ | use TUI::toolkit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 9 | ▶ | use TUI::toolkit::Types qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | :is | ||||||||||||||||||||||||||||
| 22 | :types | ||||||||||||||||||||||||||||
| 23 | 9 | ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 9 | ▶ | use TUI::Const qw( INT_MAX ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 9 | ▶ | use TUI::Help::HelpBase; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 9 | ▶ | use TUI::Objects::Object; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 9 | ▶ | use TUI::Objects::Stream; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 9 | ▶ | use TUI::Objects::Streamable; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | sub THelpTopic() { __PACKAGE__ } | ||||||||||||||||||||||||||||
| 32 | sub name() { 'THelpTopic' } | ||||||||||||||||||||||||||||
| 33 | 9 | ▶ | sub new_THelpTopic { __PACKAGE__->from(@_) } | ||||||||||||||||||||||||||
|
Subroutine
new_THelpTopic: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 9 | extends TObject; | |||||||||||||||||||||||||||
| 36 | 9 | with: *DOES = TStreamable->can('DOES'); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # public attributes | ||||||||||||||||||||||||||||
| 39 | 9 | has paragraphs => ( is => 'rw', default => 0 ); | |||||||||||||||||||||||||||
| 40 | 9 | has numRefs => ( is => 'rw', default => 0 ); | |||||||||||||||||||||||||||
| 41 | 9 | has crossRefs => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # private attributes | ||||||||||||||||||||||||||||
| 44 | 9 | has width => ( is => 'bare', default => 0 ); | |||||||||||||||||||||||||||
| 45 | 9 | has lastOffset => ( is => 'bare', default => 0 ); | |||||||||||||||||||||||||||
| 46 | 9 | has lastLine => ( is => 'bare', default => INT_MAX ); | |||||||||||||||||||||||||||
| 47 | 9 | has lastParagraph => ( is => 'bare' ); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # private methods | ||||||||||||||||||||||||||||
| 50 | my ( | ||||||||||||||||||||||||||||
| 51 | 9 | $wrapText, | |||||||||||||||||||||||||||
| 52 | $readParagraphs, | ||||||||||||||||||||||||||||
| 53 | $readCrossRefs, | ||||||||||||||||||||||||||||
| 54 | $writeParagraphs, | ||||||||||||||||||||||||||||
| 55 | $writeCrossRefs, | ||||||||||||||||||||||||||||
| 56 | $disposeParagraphs | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 10 | ▶ | sub DEMOLISH { # void ($in_global_destruction) | ||||||||||||||||||||||||||
|
Subroutine
DEMOLISH: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 10 | my ( $self, $in_global_destruction ) = @_; | |||||||||||||||||||||||||||
| 61 | 10 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 10 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 10 | $self->$disposeParagraphs(); | |||||||||||||||||||||||||||
| 64 | 10 | undef $self->{crossRefs}; | |||||||||||||||||||||||||||
| 65 | 10 | return; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 3 | ▶ | sub addCrossRef { # void ($ref) | ||||||||||||||||||||||||||
|
Subroutine
addCrossRef: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 3 | state $sig = signature( | |||||||||||||||||||||||||||
| 70 | method => Object, | ||||||||||||||||||||||||||||
| 71 | pos => [Object], | ||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||
| 73 | 3 | my ( $self, $ref ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 74 | 3 | my $p = TCrossRef->new(); | |||||||||||||||||||||||||||
| 75 | 3 | @$p = @$ref; | |||||||||||||||||||||||||||
| 76 | 3 | $self->{crossRefs}[ $self->{numRefs} ] = $p; | |||||||||||||||||||||||||||
| 77 | 3 | ++$self->{numRefs}; | |||||||||||||||||||||||||||
| 78 | 3 | return; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 8 | ▶ | sub addParagraph { # void ($p) | ||||||||||||||||||||||||||
|
Subroutine
addParagraph: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 8 | state $sig = signature( | |||||||||||||||||||||||||||
| 83 | method => Object, | ||||||||||||||||||||||||||||
| 84 | pos => [Object], | ||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||
| 86 | 8 | my ( $self, $p ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 87 | 8 | ▶ | if ( !$self->{paragraphs} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 4 | $self->{paragraphs} = $p; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | else { | ||||||||||||||||||||||||||||
| 91 | 4 | my $pp = $self->{paragraphs}; | |||||||||||||||||||||||||||
| 92 | 4 | my $back = $pp; | |||||||||||||||||||||||||||
| 93 | 4 | ▶ | while ( $pp ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 4 | $back = $pp; | |||||||||||||||||||||||||||
| 95 | 4 | $pp = $pp->next; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 4 | $back->next( $p ); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 8 | $p->next( undef ); | |||||||||||||||||||||||||||
| 100 | 8 | return; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 4 | ▶ | sub getCrossRef { # void ($i, $loc, \$length, \$ref) | ||||||||||||||||||||||||||
|
Subroutine
getCrossRef: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | 4 | state $sig = signature( | |||||||||||||||||||||||||||
| 105 | method => Object, | ||||||||||||||||||||||||||||
| 106 | pos => [ | ||||||||||||||||||||||||||||
| 107 | Int, | ||||||||||||||||||||||||||||
| 108 | Object, | ||||||||||||||||||||||||||||
| 109 | ScalarRef[PositiveOrZeroInt], | ||||||||||||||||||||||||||||
| 110 | ScalarRef[Int], | ||||||||||||||||||||||||||||
| 111 | ], | ||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||
| 113 | 4 | my ( $self, $i, $loc, $length, $ref ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 114 | 4 | ▶ | assert ( $i >= 0 && $i < $self->{numRefs} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$i >= 0 and $i < $self->{"numRefs"}
MC/DC0%0/2
$i >= 0 and $i < $self->{"numRefs"}
$i >= 0
$i < $self->{"numRefs"}
Truth table33%1/3
A and B
A= $i >= 0B= $i < $self->{"numRefs"}
| |||||||||||||||||||||||||||||
| 115 | 4 | my $paraOffset = 0; | |||||||||||||||||||||||||||
| 116 | 4 | my $curOffset = 0; | |||||||||||||||||||||||||||
| 117 | 4 | my $oldOffset = 0; | |||||||||||||||||||||||||||
| 118 | 4 | my $line = 0; | |||||||||||||||||||||||||||
| 119 | 4 | my $crossRef = $self->{crossRefs}[$i]; | |||||||||||||||||||||||||||
| 120 | 4 | my $offset = $crossRef->offset; | |||||||||||||||||||||||||||
| 121 | 4 | my $p = $self->{paragraphs}; | |||||||||||||||||||||||||||
| 122 | 4 | ▶ | while ( $paraOffset + $curOffset < $offset ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 10 | my $buffer = ''; | |||||||||||||||||||||||||||
| 124 | 10 | $oldOffset = $paraOffset + $curOffset; | |||||||||||||||||||||||||||
| 125 | 10 | $self->$wrapText( | |||||||||||||||||||||||||||
| 126 | $p->text, $p->size, \$curOffset, $p->wrap, \$buffer, $p->size, | ||||||||||||||||||||||||||||
| 127 | ); | ||||||||||||||||||||||||||||
| 128 | 10 | ++$line; | |||||||||||||||||||||||||||
| 129 | 10 | ▶ | if ( $curOffset >= $p->size ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 5 | $paraOffset += $p->size; | |||||||||||||||||||||||||||
| 131 | 5 | $p = $p->next; | |||||||||||||||||||||||||||
| 132 | 5 | $curOffset = 0; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | 4 | $loc->x( $offset - $oldOffset - 1 ); | |||||||||||||||||||||||||||
| 136 | 4 | $loc->y( $line ); | |||||||||||||||||||||||||||
| 137 | 4 | $$length = $crossRef->length; | |||||||||||||||||||||||||||
| 138 | 4 | $$ref = $crossRef->ref; | |||||||||||||||||||||||||||
| 139 | 4 | return; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 14 | ▶ | sub getLine { # $line ($line, \$buffer, $buflen) | ||||||||||||||||||||||||||
|
Subroutine
getLine: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 143 | 14 | state $sig = signature( | |||||||||||||||||||||||||||
| 144 | method => Object, | ||||||||||||||||||||||||||||
| 145 | pos => [Int, ScalarRef[Str], Int], | ||||||||||||||||||||||||||||
| 146 | ); | ||||||||||||||||||||||||||||
| 147 | 14 | my ( $self, $line, $buffer, $buflen ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 148 | 14 | my ( $offset, $p ); | |||||||||||||||||||||||||||
| 149 | 14 | ▶ | if ( $self->{lastLine} < $line ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 8 | my $i = $line; | |||||||||||||||||||||||||||
| 151 | 8 | $line -= $self->{lastLine}; | |||||||||||||||||||||||||||
| 152 | 8 | $self->{lastLine} = $i; | |||||||||||||||||||||||||||
| 153 | 8 | $offset = $self->{lastOffset}; | |||||||||||||||||||||||||||
| 154 | 8 | $p = $self->{lastParagraph}; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | else { | ||||||||||||||||||||||||||||
| 157 | 6 | $p = $self->{paragraphs}; | |||||||||||||||||||||||||||
| 158 | 6 | $offset = 0; | |||||||||||||||||||||||||||
| 159 | 6 | $self->{lastLine} = $line; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | 14 | $$buffer = ''; | |||||||||||||||||||||||||||
| 162 | 14 | ▶ | while ( $p ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 17 | ▶ | while ( $offset < $p->size ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 16 | my $lineBuf = ''; | |||||||||||||||||||||||||||
| 165 | 16 | --$line; | |||||||||||||||||||||||||||
| 166 | 16 | $self->$wrapText( | |||||||||||||||||||||||||||
| 167 | $p->text, $p->size, \$offset, $p->wrap, \$lineBuf, $p->size, | ||||||||||||||||||||||||||||
| 168 | ); | ||||||||||||||||||||||||||||
| 169 | 16 | $$buffer = substr( $lineBuf, 0, $buflen ); | |||||||||||||||||||||||||||
| 170 | 16 | ▶ | if ( $line == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 13 | $self->{lastOffset} = $offset; | |||||||||||||||||||||||||||
| 172 | 13 | $self->{lastParagraph} = $p; | |||||||||||||||||||||||||||
| 173 | 13 | return $$buffer; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | 4 | $p = $p->next; | |||||||||||||||||||||||||||
| 177 | 4 | $offset = 0; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | 1 | $$buffer = ''; | |||||||||||||||||||||||||||
| 180 | 1 | return $$buffer; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 3 | ▶ | sub getNumCrossRefs { # $count () | ||||||||||||||||||||||||||
|
Subroutine
getNumCrossRefs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 184 | 3 | state $sig = signature( | |||||||||||||||||||||||||||
| 185 | method => Object, | ||||||||||||||||||||||||||||
| 186 | pos => [], | ||||||||||||||||||||||||||||
| 187 | ); | ||||||||||||||||||||||||||||
| 188 | 3 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 189 | 3 | return $self->{numRefs}; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 3 | ▶ | sub numLines { # $count () | ||||||||||||||||||||||||||
|
Subroutine
numLines: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 193 | 3 | state $sig = signature( | |||||||||||||||||||||||||||
| 194 | method => Object, | ||||||||||||||||||||||||||||
| 195 | pos => [], | ||||||||||||||||||||||||||||
| 196 | ); | ||||||||||||||||||||||||||||
| 197 | 3 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 198 | 3 | my $lines = 0; | |||||||||||||||||||||||||||
| 199 | 3 | ▶ | for ( my $p = $self->{paragraphs}; $p; $p = $p->next ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 4 | my $offset = 0; | |||||||||||||||||||||||||||
| 201 | 4 | ▶ | while ( $offset < $p->size ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 8 | my $buffer = ''; | |||||||||||||||||||||||||||
| 203 | 8 | ++$lines; | |||||||||||||||||||||||||||
| 204 | 8 | $self->$wrapText( | |||||||||||||||||||||||||||
| 205 | $p->text, $p->size, \$offset, $p->wrap, \$buffer, $p->size, | ||||||||||||||||||||||||||||
| 206 | ); | ||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | 3 | return $lines; | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 1 | ▶ | sub setCrossRef { # void ($i, $ref) | ||||||||||||||||||||||||||
|
Subroutine
setCrossRef: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 213 | 1 | state $sig = signature( | |||||||||||||||||||||||||||
| 214 | method => Object, | ||||||||||||||||||||||||||||
| 215 | pos => [Int, Object], | ||||||||||||||||||||||||||||
| 216 | ); | ||||||||||||||||||||||||||||
| 217 | 1 | my ( $self, $i, $ref ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 218 | 1 | ▶ | assert ( $i >= 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | 1 | ▶ | if ( $i < $self->{numRefs} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 1 | my $p = TCrossRef->new(); | |||||||||||||||||||||||||||
| 221 | 1 | @$p = @$ref; | |||||||||||||||||||||||||||
| 222 | 1 | $self->{crossRefs}[$i] = $p; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | 1 | return; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 4 | ▶ | sub setNumCrossRefs { # void ($i) | ||||||||||||||||||||||||||
|
Subroutine
setNumCrossRefs: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 228 | 4 | state $sig = signature( | |||||||||||||||||||||||||||
| 229 | method => Object, | ||||||||||||||||||||||||||||
| 230 | pos => [Int], | ||||||||||||||||||||||||||||
| 231 | ); | ||||||||||||||||||||||||||||
| 232 | 4 | my ( $self, $i ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 233 | 4 | ▶ | assert ( $i >= 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | return | ||||||||||||||||||||||||||||
| 235 | 4 | ▶ | if $self->{numRefs} == $i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 4 | ▶ | if ( $i < $self->{numRefs} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 2 | splice @{ $self->{crossRefs} }, $i; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | else { | ||||||||||||||||||||||||||||
| 241 | 2 | push @{ $self->{crossRefs} }, | |||||||||||||||||||||||||||
| 242 | 2 | map { TCrossRef->new() } $self->{numRefs} .. $i - 1; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | 4 | $self->{numRefs} = $i; | |||||||||||||||||||||||||||
| 245 | 4 | return; | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 10 | ▶ | sub setWidth { # void ($aWidth) | ||||||||||||||||||||||||||
|
Subroutine
setWidth: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 249 | 10 | state $sig = signature( | |||||||||||||||||||||||||||
| 250 | method => Object, | ||||||||||||||||||||||||||||
| 251 | pos => [Int], | ||||||||||||||||||||||||||||
| 252 | ); | ||||||||||||||||||||||||||||
| 253 | 10 | my ( $self, $aWidth ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 254 | 10 | $self->{width} = $aWidth; | |||||||||||||||||||||||||||
| 255 | 10 | return; | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 10 | ▶ | sub _wrapText { goto $wrapText } | ||||||||||||||||||||||||||
|
Subroutine
_wrapText: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 259 | 44 | ▶ | $wrapText = sub { # $text ($self, $text, $size, \$offset, $wrap, \$lineBuf, $lineBufLen) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=20 SCAR=31.3
| |||||||||||||||||||||||||||||
| 260 | 44 | my ( $self, $text, $size, $offset, $wrap, $lineBuf, $lineBufLen ) = @_; | |||||||||||||||||||||||||||
| 261 | 44 | ▶ | assert ( @_ == 7 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | 44 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 44 | ▶ | assert ( is_Str $text ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | 44 | ▶ | assert ( is_Int $size ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 44 | ▶ | assert ( is_ScalarRef $offset and is_Int $$offset ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&is_ScalarRef($offset) and &is_Int($$offset)
MC/DC0%0/2
&is_ScalarRef($offset) and &is_Int($$offset)
&is_ScalarRef($offset)
&is_Int($$offset)
Truth table33%1/3
A and B
A= &is_ScalarRef($offset)B= &is_Int($$offset)
| |||||||||||||||||||||||||||||
| 266 | 44 | ▶ | assert ( is_Bool $wrap ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | 44 | ▶ | assert ( is_ScalarRef $lineBuf and is_Str $$lineBuf ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&is_ScalarRef($lineBuf) and &is_Str($$lineBuf)
MC/DC0%0/2
&is_ScalarRef($lineBuf) and &is_Str($$lineBuf)
&is_ScalarRef($lineBuf)
&is_Str($$lineBuf)
Truth table33%1/3
A and B
A= &is_ScalarRef($lineBuf)B= &is_Str($$lineBuf)
| |||||||||||||||||||||||||||||
| 268 | 44 | ▶ | assert ( is_Int $lineBufLen ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 44 | my $start = $$offset; | |||||||||||||||||||||||||||
| 271 | 44 | my $remaining = substr( $text, $start, $size - $start ); | |||||||||||||||||||||||||||
| 272 | 44 | my $length = length $remaining; | |||||||||||||||||||||||||||
| 273 | 44 | ▶ | if ( $remaining =~ /\A[^\0]*?(\R)/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 274 | 8 | $length = $+[1]; | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 44 | my $width = $self->{width}; | |||||||||||||||||||||||||||
| 278 | 44 | ▶ | if ( $wrap && $length >= $width ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$wrap and $length >= $width
MC/DC100%2/2
$wrap and $length >= $width
$wrap
$length >= $width
Truth table100%3/3
A and B
A= $wrapB= $length >= $width
| |||||||||||||||||||||||||||||
| 279 | 14 | my $end = $start + $width; | |||||||||||||||||||||||||||
| 280 | 14 | ▶ | if ( $end > $size ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 281 | 0 | $end = $size; | |||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | else { | ||||||||||||||||||||||||||||
| 284 | 14 | my $textWithinWidth = substr( $text, $start, $width + 1 ); | |||||||||||||||||||||||||||
| 285 | 14 | ▶ | if ( $textWithinWidth =~ /\s\S*\z/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$textWithinWidth =~ /\s\S*\z/ and $-[0] > 0
MC/DC50%1/2
$textWithinWidth =~ /\s\S*\z/ and $-[0] > 0
$textWithinWidth =~ /\s\S*\z/
$-[0] > 0
Truth table66%2/3
A and B
A= $textWithinWidth =~ /\s\S*\z/B= $-[0] > 0
| |||||||||||||||||||||||||||||
| 286 | && $-[0] > 0 ) { | ||||||||||||||||||||||||||||
| 287 | 11 | $end = $start + $-[0] + 1; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | else { | ||||||||||||||||||||||||||||
| 290 | 3 | my $rest = substr( $text, $end, $size - $end ); | |||||||||||||||||||||||||||
| 291 | 3 | ▶ | $end = $rest =~ /\s/ ? $end + $-[0] + 1 : $size; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | 14 | ▶ | $end = $start + $width if $end == $start; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | 14 | $length = $end - $start; | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 44 | ▶ | $length = $lineBufLen if $length > $lineBufLen; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | 44 | $$lineBuf = substr( $text, $start, $length ); | |||||||||||||||||||||||||||
| 300 | 44 | $$lineBuf =~ s/\0.*\z//s; | |||||||||||||||||||||||||||
| 301 | 44 | $$lineBuf =~ s/\R\z//; | |||||||||||||||||||||||||||
| 302 | 44 | $$offset += $length; | |||||||||||||||||||||||||||
| 303 | 44 | return $$lineBuf; | |||||||||||||||||||||||||||
| 304 | 9 | }; | |||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 1 | ▶ | $readParagraphs = sub { # void ($self, $s) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||
| 307 | 1 | my ( $self, $s ) = @_; | |||||||||||||||||||||||||||
| 308 | 1 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | 1 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 1 | ▶ | assert ( is_Object $s ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 1 | ▶ | assert ( Storable::is_retrieving ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | 1 | my $count = $s->get(); | |||||||||||||||||||||||||||
| 313 | 1 | $self->{paragraphs} = 0; | |||||||||||||||||||||||||||
| 314 | 1 | for ( 1 .. $count ) { | |||||||||||||||||||||||||||
| 315 | 2 | my $size = $s->get(); | |||||||||||||||||||||||||||
| 316 | 2 | my $wrap = $s->get(); | |||||||||||||||||||||||||||
| 317 | 2 | my $text = $s->get(); | |||||||||||||||||||||||||||
| 318 | 2 | $self->addParagraph( | |||||||||||||||||||||||||||
| 319 | TParagraph->new( size => $size, wrap => $wrap, text => $text ), | ||||||||||||||||||||||||||||
| 320 | ); | ||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | 1 | return; | |||||||||||||||||||||||||||
| 323 | 9 | }; | |||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 1 | ▶ | $readCrossRefs = sub { # void ($self, $s) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||
| 326 | 1 | my ( $self, $s ) = @_; | |||||||||||||||||||||||||||
| 327 | 1 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 328 | 1 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | 1 | ▶ | assert ( is_Object $s ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 330 | 1 | ▶ | assert ( Storable::is_retrieving ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 1 | $self->{numRefs} = $s->get(); | |||||||||||||||||||||||||||
| 332 | 1 | $self->{crossRefs} = []; | |||||||||||||||||||||||||||
| 333 | 1 | for ( 1 .. $self->{numRefs} ) { | |||||||||||||||||||||||||||
| 334 | 2 | my $ref = $s->get(); | |||||||||||||||||||||||||||
| 335 | 2 | my $offset = $s->get(); | |||||||||||||||||||||||||||
| 336 | 2 | my $length = $s->get(); | |||||||||||||||||||||||||||
| 337 | 2 | push @{ $self->{crossRefs} }, TCrossRef->new( | |||||||||||||||||||||||||||
| 338 | ref => $ref, offset => $offset, length => $length, | ||||||||||||||||||||||||||||
| 339 | ); | ||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | 1 | return; | |||||||||||||||||||||||||||
| 342 | 9 | }; | |||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | 1 | ▶ | $writeParagraphs = sub { # void ($self, $s) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||
| 345 | 1 | my ( $self, $s ) = @_; | |||||||||||||||||||||||||||
| 346 | 1 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 347 | 1 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 1 | ▶ | assert ( is_Object $s ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 349 | 1 | ▶ | assert ( Storable::is_storing ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | 1 | my $count = 0; | |||||||||||||||||||||||||||
| 351 | 1 | ▶ | for ( my $p = $self->{paragraphs}; $p; $p = $p->next ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 352 | 2 | ++$count; | |||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||
| 354 | 1 | $s->put( $count ); | |||||||||||||||||||||||||||
| 355 | 1 | ▶ | for ( my $p = $self->{paragraphs}; $p; $p = $p->next ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 356 | 2 | $s->put( $p->size, $p->wrap, substr( $p->text, 0, $p->size ) ); | |||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | 1 | return; | |||||||||||||||||||||||||||
| 359 | 9 | }; | |||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 1 | ▶ | $writeCrossRefs = sub { # void ($self, $s) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||
| 362 | 1 | my ( $self, $s ) = @_; | |||||||||||||||||||||||||||
| 363 | 1 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | 1 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 365 | 1 | ▶ | assert ( is_Object $s ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | 1 | ▶ | assert ( Storable::is_storing ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | 1 | $s->put( $self->{numRefs} ); | |||||||||||||||||||||||||||
| 368 | 1 | for my $i ( 0 .. $self->{numRefs} - 1 ) { | |||||||||||||||||||||||||||
| 369 | 2 | my $ref = $self->{crossRefs}[$i]; | |||||||||||||||||||||||||||
| 370 | 2 | $s->put( $ref->ref, $ref->offset, $ref->length ); | |||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | 1 | return; | |||||||||||||||||||||||||||
| 373 | 9 | }; | |||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 10 | ▶ | $disposeParagraphs = sub { # void ($self) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 376 | 10 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 377 | 10 | ▶ | assert ( @_ == 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 10 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | 10 | undef $self->{paragraphs}; | |||||||||||||||||||||||||||
| 380 | 10 | return; | |||||||||||||||||||||||||||
| 381 | 9 | }; | |||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 1 | ▶ | sub STORABLE_freeze { # @list ($cloning) | ||||||||||||||||||||||||||
|
Subroutine
STORABLE_freeze: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 384 | 1 | my ( $self, $cloning ) = @_; | |||||||||||||||||||||||||||
| 385 | 1 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 386 | 1 | ▶ | assert ( is_Bool $cloning ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 387 | 1 | ▶ | assert ( not $cloning ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | 1 | my $stream = TStream->new(); | |||||||||||||||||||||||||||
| 390 | 1 | $self->write( $stream ); | |||||||||||||||||||||||||||
| 391 | 1 | return freeze $stream; | |||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 1 | ▶ | sub STORABLE_attach { # $obj ($cloning, $serialized) | ||||||||||||||||||||||||||
|
Subroutine
STORABLE_attach: called CC=5 SCAR=16.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 395 | 1 | my ( $class, $cloning, $serialized ) = @_; | |||||||||||||||||||||||||||
| 396 | 1 | ▶ | assert ( is_Str $class ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 397 | 1 | ▶ | assert ( is_Bool $cloning ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 398 | 1 | ▶ | assert ( is_Str $serialized ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 399 | 1 | ▶ | assert ( not $cloning ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | 1 | my $self = $class->build(); | |||||||||||||||||||||||||||
| 402 | 1 | my $stream = thaw $serialized; | |||||||||||||||||||||||||||
| 403 | 1 | return $self->read( $stream ); | |||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 1 | ▶ | sub write :method { # void ($os) | ||||||||||||||||||||||||||
|
Subroutine
write: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 407 | 1 | state $sig = signature( | |||||||||||||||||||||||||||
| 408 | method => Object, | ||||||||||||||||||||||||||||
| 409 | pos => [Object], | ||||||||||||||||||||||||||||
| 410 | ); | ||||||||||||||||||||||||||||
| 411 | 1 | my ( $self, $os ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 412 | 1 | ▶ | assert ( Storable::is_storing ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 413 | 1 | $self->$writeParagraphs( $os ); | |||||||||||||||||||||||||||
| 414 | 1 | $self->$writeCrossRefs( $os ); | |||||||||||||||||||||||||||
| 415 | 1 | return; | |||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 1 | ▶ | sub read :method { # $self ($is) | ||||||||||||||||||||||||||
|
Subroutine
read: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 419 | 1 | state $sig = signature( | |||||||||||||||||||||||||||
| 420 | method => Object, | ||||||||||||||||||||||||||||
| 421 | pos => [Object], | ||||||||||||||||||||||||||||
| 422 | ); | ||||||||||||||||||||||||||||
| 423 | 1 | my ( $self, $is ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 424 | 1 | ▶ | assert ( Storable::is_retrieving ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 425 | 1 | $self->$readParagraphs( $is ); | |||||||||||||||||||||||||||
| 426 | 1 | $self->$readCrossRefs( $is ); | |||||||||||||||||||||||||||
| 427 | 1 | $self->{width} = 0; | |||||||||||||||||||||||||||
| 428 | 1 | $self->{lastLine} = INT_MAX; | |||||||||||||||||||||||||||
| 429 | 1 | return $self; | |||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | 1 | ▶ | sub build { # $obj () | ||||||||||||||||||||||||||
|
Subroutine
build: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 433 | 1 | my ( $class ) = @_; | |||||||||||||||||||||||||||
| 434 | 1 | ▶ | assert ( @_ == 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 435 | 1 | ▶ | assert ( is_Str $class ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 436 | 1 | ▶ | assert ( Storable::is_retrieving ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 437 | 1 | return $class->new(); | |||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | 9 | 1 | |||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | __END__ | ||||||||||||||||||||||||||||