| 1 | package Text::Snippet::TabStop::Cursor; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 10 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | $Text::Snippet::TabStop::Cursor::VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Provides a bi-directional iterator interface for moving from one tab-stop to it's siblings | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use Class::XSAccessor getters => {snippet => 'snippet'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use Scalar::Util qw(blessed refaddr); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | my %args = (i => -1, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | croak "snippet must be ISA Text::Snippet" unless blessed $args{snippet} eq 'Text::Snippet'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | return bless \%args, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | ▶ | sub has_prev { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_prev: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | my $stops = $self->snippet->tab_stops; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | ▶ | return @$stops && $self->{i} > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
@$stops && $self->{'i'} > 0
MC/DC0%0/2
@$stops && $self->{'i'} > 0
@$stops
$self->{'i'} > 0
Truth table33%1/3
A && B
A= @$stopsB= $self->{'i'} > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | ▶ | sub prev { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prev: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 5 | ▶ | return $self->has_prev ? $self->snippet->tab_stops->[ --$self->{i} ] : (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 20 | ▶ | sub has_next { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_next: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 20 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 20 | my $stops = $self->snippet->tab_stops; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 20 | ▶ | return @$stops && $self->{i} < $#{$stops}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
@$stops && $self->{'i'} < $#{$stops;}
MC/DC50%1/2
@$stops && $self->{'i'} < $#{$stops;}
@$stops
$self->{'i'} < $#{$stops;}
Truth table66%2/3
A && B
A= @$stopsB= $self->{'i'} < $#{$stops;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 12 | ▶ | sub next { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 12 | ▶ | return $self->has_next ? $self->snippet->tab_stops->[ ++$self->{i} ] : (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 102 | ▶ | sub current { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
current: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 102 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 102 | ▶ | return unless($self->{i} >= 0); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 100 | my $stops = $self->snippet->tab_stops; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 100 | ▶ | if ( exists( $stops->[ $self->{i} ] ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 100 | return $stops->[ $self->{i} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 82 | ▶ | sub _is_current { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_current: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 82 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 82 | my $current = $self->current; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 82 | my $tab_stop = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 82 | ▶ | return blessed($tab_stop) && (refaddr($tab_stop) == refaddr($current) || ($tab_stop->has_parent && refaddr($tab_stop->parent) == refaddr($current))); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition77%7/9
builtin::blessed($tab_stop) && (builtin::refaddr($tab_stop) == builtin::refaddr($current) || $tab_stop->has_parent && builtin::refaddr($tab_stop->parent) == builtin::refaddr($current))
builtin::refaddr($tab_stop) == builtin::refaddr($current) or $tab_stop->has_parent and builtin::refaddr($tab_stop->parent) == builtin::refaddr($current)
$tab_stop->has_parent and builtin::refaddr($tab_stop->parent) == builtin::refaddr($current)
MC/DC50%2/4
builtin::blessed($tab_stop) && (builtin::refaddr($tab_stop) == builtin::refaddr($current) || $tab_stop->has_parent && builtin::refaddr($tab_stop->parent) == builtin::refaddr($current))
builtin::blessed($tab_stop)
builtin::refaddr($tab_stop) == builtin::refaddr($current)
$tab_stop->has_parent
builtin::refaddr($tab_stop->parent) == builtin::refaddr($current)
Truth table80%4/5
A && B or C and D
A= builtin::blessed($tab_stop)B= builtin::refaddr($tab_stop) == builtin::refaddr($current)C= $tab_stop->has_parentD= builtin::refaddr($tab_stop->parent) == builtin::refaddr($current)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 8 | ▶ | sub current_position { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
current_position: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 8 | my $current = $self->current; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 8 | my ($line, $column) = (0,0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 8 | ▶ | return [$line,$column] if ! defined $current; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 7 | foreach my $c(@{ $self->snippet->chunks }){ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 41 | ▶ | last if($self->_is_current($c)); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 34 | ▶ | my $text = blessed($c) && $c->can('to_string') ? $c->to_string || '': "$c"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
builtin::blessed($c) and $c->can("to_string")
$c->to_string or ""
MC/DC50%1/2
builtin::blessed($c) and $c->can("to_string")
builtin::blessed($c)
$c->can("to_string")
MC/DC100%1/1
$c->to_string or ""
$c->to_string
Truth table66%2/3
A and B
A= builtin::blessed($c)B= $c->can("to_string")
Truth table100%2/2
A
A= $c->to_string
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 34 | foreach my $char(split(/(\n)/,$text)){ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 40 | ▶ | if($char eq "\n"){ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 8 | $line++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 8 | $column = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 32 | $column += length($char); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 7 | return [$line,$column]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 8 | ▶ | sub current_char_position { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
current_char_position: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 8 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 8 | my $current = $self->current; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 8 | ▶ | return $pos if ! defined $current; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 7 | foreach my $c( @{ $self->snippet->chunks } ){ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 41 | ▶ | last if($self->_is_current($c)); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 34 | ▶ | my $text = blessed($c) && $c->can('to_string') ? $c->to_string || '': "$c"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
builtin::blessed($c) and $c->can("to_string")
$c->to_string or ""
MC/DC50%1/2
builtin::blessed($c) and $c->can("to_string")
builtin::blessed($c)
$c->can("to_string")
MC/DC100%1/1
$c->to_string or ""
$c->to_string
Truth table66%2/3
A and B
A= builtin::blessed($c)B= $c->can("to_string")
Truth table100%2/2
A
A= $c->to_string
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 34 | $pos += length($text); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 7 | return $pos; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | ▶ | sub is_terminal { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_terminal: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | ▶ | return if(!defined$self->current); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | return $self->current->index == 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||