| 1 | package TUI::Outline::Outline; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: outline viewer that displays a tree of TNode objects | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 7 | our $VERSION = '2.000003'; | |||||||||||||||||||||||||||
| 9 | 7 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 10 | 7 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 7 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 14 | TOutline | ||||||||||||||||||||||||||||
| 15 | new_TOutline | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use Storable; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 7 | ▶ | use TUI::toolkit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 7 | ▶ | use TUI::toolkit::Types qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | Maybe | ||||||||||||||||||||||||||||
| 23 | :is | ||||||||||||||||||||||||||||
| 24 | :types | ||||||||||||||||||||||||||||
| 25 | 7 | ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 7 | ▶ | use TUI::Objects::Rect; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 7 | ▶ | use TUI::Outline::Node; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 7 | ▶ | use TUI::Outline::OutlineViewer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | sub TOutline() { __PACKAGE__ } | ||||||||||||||||||||||||||||
| 32 | sub name() { 'TOutline' } | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub new_TOutline { __PACKAGE__->from(@_) } | ||||||||||||||||||||||||||
|
Subroutine
new_TOutline: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 7 | extends TOutlineViewer; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # public attributes | ||||||||||||||||||||||||||||
| 38 | 7 | has root => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub BUILDARGS { # \%args (%args) | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 43 | method => 1, | ||||||||||||||||||||||||||||
| 44 | named => [ | ||||||||||||||||||||||||||||
| 45 | bounds => Object, | ||||||||||||||||||||||||||||
| 46 | hScrollBar => Maybe[Object], { alias => 'aHScrollBar' }, | ||||||||||||||||||||||||||||
| 47 | vScrollBar => Maybe[Object], { alias => 'aVScrollBar' }, | ||||||||||||||||||||||||||||
| 48 | root => Maybe[Object], { alias => 'aRoot' }, | ||||||||||||||||||||||||||||
| 49 | ], | ||||||||||||||||||||||||||||
| 50 | caller_level => +1, | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | 0 | my ( $class, $args ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 53 | 0 | return { %$args }; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub BUILD { # void (\%args) | ||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 0 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | $self->update(); | |||||||||||||||||||||||||||
| 61 | 0 | return; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub from { # $outline ($bounds, $aHScrollBar|undef, $aVScrollBar|undef, $aRoot) | ||||||||||||||||||||||||||
|
Subroutine
from: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 66 | method => 1, | ||||||||||||||||||||||||||||
| 67 | pos => [Object, Maybe[Object], Maybe[Object], Maybe[Object]], | ||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||
| 69 | 0 | my ( $class, @args ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 70 | 0 | return $class->new( bounds => $args[0], hScrollBar => $args[1], | |||||||||||||||||||||||||||
| 71 | vScrollBar => $args[2], root => $args[3] ); | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub adjust { # void ($node, $expand) | ||||||||||||||||||||||||||
|
Subroutine
adjust: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 76 | method => Object, | ||||||||||||||||||||||||||||
| 77 | pos => [Object, Bool], | ||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||
| 79 | 0 | my ( $self, $node, $expand ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 80 | 0 | $node->expanded( $expand ); | |||||||||||||||||||||||||||
| 81 | 0 | return; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub getRoot { # $node () | ||||||||||||||||||||||||||
|
Subroutine
getRoot: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 86 | method => Object, | ||||||||||||||||||||||||||||
| 87 | pos => [], | ||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||
| 89 | 0 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 90 | 0 | return $self->root; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub getNumChildren { # $count ($node) | ||||||||||||||||||||||||||
|
Subroutine
getNumChildren: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 95 | method => Object, | ||||||||||||||||||||||||||||
| 96 | pos => [Object], | ||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||
| 98 | 0 | my ( $self, $node ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 99 | 0 | my $count = 0; | |||||||||||||||||||||||||||
| 100 | 0 | my $p = $node->childList; | |||||||||||||||||||||||||||
| 101 | 0 | ▶ | while ( $p ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | $count++; | |||||||||||||||||||||||||||
| 103 | 0 | $p = $p->next; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 0 | return $count; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub getChild { # $node ($node, $i) | ||||||||||||||||||||||||||
|
Subroutine
getChild: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 110 | method => Object, | ||||||||||||||||||||||||||||
| 111 | pos => [Object, Int], | ||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||
| 113 | 0 | my ( $self, $node, $i ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 114 | 0 | my $p = $node->childList; | |||||||||||||||||||||||||||
| 115 | 0 | ▶ | while ( $i != 0 && $p ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$i != 0 and $p
MC/DC0%0/2
$i != 0 and $p
$i != 0
$p
Truth table0%0/3
A and B
A= $i != 0B= $p
| |||||||||||||||||||||||||||||
| 116 | 0 | $i--; | |||||||||||||||||||||||||||
| 117 | 0 | $p = $p->next; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 0 | return $p; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub getText { # $text ($node) | ||||||||||||||||||||||||||
|
Subroutine
getText: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 124 | method => Object, | ||||||||||||||||||||||||||||
| 125 | pos => [Object], | ||||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||
| 127 | 0 | my ( $self, $node ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 128 | 0 | return $node->text; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub isExpanded { # $bool ($node) | ||||||||||||||||||||||||||
|
Subroutine
isExpanded: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 132 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 133 | method => Object, | ||||||||||||||||||||||||||||
| 134 | pos => [Object], | ||||||||||||||||||||||||||||
| 135 | ); | ||||||||||||||||||||||||||||
| 136 | 0 | my ( $self, $node ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 137 | 0 | return $node->expanded; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub hasChildren { # $bool ($node) | ||||||||||||||||||||||||||
|
Subroutine
hasChildren: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 141 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 142 | method => Object, | ||||||||||||||||||||||||||||
| 143 | pos => [Object], | ||||||||||||||||||||||||||||
| 144 | ); | ||||||||||||||||||||||||||||
| 145 | 0 | my ( $self, $node ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 146 | 0 | ▶ | return defined $node->childList ? true : false; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub write :method { # void ($os) | ||||||||||||||||||||||||||
|
Subroutine
write: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 150 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 151 | method => Object, | ||||||||||||||||||||||||||||
| 152 | pos => [Object], | ||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||
| 154 | 0 | my ( $self, $os ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 155 | 0 | $self->SUPER::write( $os ); | |||||||||||||||||||||||||||
| 156 | 0 | my $root = $self->root; | |||||||||||||||||||||||||||
| 157 | 0 | ▶ | $os->put( defined $root ? 1 : 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | $self->writeNode( $root, $os ) if defined $root; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | return; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | sub read :method { # $self ($is) | ||||||||||||||||||||||||||
|
Subroutine
read: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 163 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 164 | method => Object, | ||||||||||||||||||||||||||||
| 165 | pos => [Object], | ||||||||||||||||||||||||||||
| 166 | ); | ||||||||||||||||||||||||||||
| 167 | 0 | my ( $self, $is ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 168 | 0 | $self->SUPER::read( $is ); | |||||||||||||||||||||||||||
| 169 | 0 | my $hasRoot = $is->get(); | |||||||||||||||||||||||||||
| 170 | 0 | ▶ | $self->root( $hasRoot ? $self->readNode( $is ) : undef ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 0 | return $self; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | ▶ | sub writeNode { # void ($node, $os) | ||||||||||||||||||||||||||
|
Subroutine
writeNode: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 175 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 176 | method => Object, | ||||||||||||||||||||||||||||
| 177 | pos => [Object, Object], | ||||||||||||||||||||||||||||
| 178 | ); | ||||||||||||||||||||||||||||
| 179 | 0 | my ( $self, $node, $os ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | ▶ | my $more = defined $node->next ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | my $expand = $node->expanded ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 0 | $os->put( | |||||||||||||||||||||||||||
| 184 | $more, | ||||||||||||||||||||||||||||
| 185 | $expand, | ||||||||||||||||||||||||||||
| 186 | $self->getNumChildren( $node ), | ||||||||||||||||||||||||||||
| 187 | $node->text | ||||||||||||||||||||||||||||
| 188 | ); | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | ▶ | $self->writeNode( $node->childList, $os ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | if defined $node->childList; | ||||||||||||||||||||||||||||
| 192 | 0 | ▶ | $self->writeNode( $node->next, $os ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | if defined $node->next; | ||||||||||||||||||||||||||||
| 194 | 0 | return; | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | ▶ | sub readNode { # $node ($is) | ||||||||||||||||||||||||||
|
Subroutine
readNode: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 198 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 199 | method => Object, | ||||||||||||||||||||||||||||
| 200 | pos => [Object], | ||||||||||||||||||||||||||||
| 201 | ); | ||||||||||||||||||||||||||||
| 202 | 0 | my ( $self, $is ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | my $more = $is->get(); | |||||||||||||||||||||||||||
| 205 | 0 | ▶ | my $expand = $is->get() ? true : false; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | 0 | my $nChildren = $is->get(); | |||||||||||||||||||||||||||
| 207 | 0 | my $text = $is->get(); | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | ▶ | my $childList = $nChildren | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | ? $self->readNode( $is ) | ||||||||||||||||||||||||||||
| 211 | : undef; | ||||||||||||||||||||||||||||
| 212 | 0 | ▶ | my $next = $more | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | ? $self->readNode( $is ) | ||||||||||||||||||||||||||||
| 214 | : undef; | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 0 | return TNode->new( | |||||||||||||||||||||||||||
| 217 | text => $text, | ||||||||||||||||||||||||||||
| 218 | childList => $childList, | ||||||||||||||||||||||||||||
| 219 | next => $next, | ||||||||||||||||||||||||||||
| 220 | expanded => $expand, | ||||||||||||||||||||||||||||
| 221 | ); | ||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | ▶ | sub build { # $obj () | ||||||||||||||||||||||||||
|
Subroutine
build: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 225 | 0 | my ( $class ) = @_; | |||||||||||||||||||||||||||
| 226 | 0 | ▶ | assert ( @_ == 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 0 | ▶ | assert ( is_Str $class ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | 0 | ▶ | assert ( Storable::is_retrieving ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 0 | return $class->new( | |||||||||||||||||||||||||||
| 230 | bounds => TRect->new(), | ||||||||||||||||||||||||||||
| 231 | hScrollBar => undef, | ||||||||||||||||||||||||||||
| 232 | vScrollBar => undef, | ||||||||||||||||||||||||||||
| 233 | root => undef, | ||||||||||||||||||||||||||||
| 234 | ); | ||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 7 | 1; | |||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | __END__ | ||||||||||||||||||||||||||||