| 1 | 1 | ▶ | use Moops; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | # PODNAME: MarpaX::Languages::M4::Impl::Input | ||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: M4 Input generic implementation | ||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | class MarpaX::Languages::M4::Impl::Input { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=1.4
| |||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = '0.020'; # VERSION | |||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our $AUTHORITY = 'cpan:JDDPAUSE'; # AUTHORITY | |||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use MarpaX::Languages::M4::Role::Input; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use MarpaX::Languages::M4::Type::Input -all; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use MooX::HandlesVia; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Types::Common::Numeric -all; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | has _name => ( | ||||||||||||||||||||||||||||||||||||||
| 19 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||
| 20 | isa => ArrayRef[Str], | ||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 22 | 1 | handles_via => 'Array', | |||||||||||||||||||||||||||||||||||||
| 23 | handles => { | ||||||||||||||||||||||||||||||||||||||
| 24 | _name_push => 'push', | ||||||||||||||||||||||||||||||||||||||
| 25 | _name_count => 'count', | ||||||||||||||||||||||||||||||||||||||
| 26 | _name_get => 'get', | ||||||||||||||||||||||||||||||||||||||
| 27 | _name_set => 'set', | ||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||
| 31 | has _cumulStartPos => ( | ||||||||||||||||||||||||||||||||||||||
| 32 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||
| 33 | isa => ArrayRef[Int], | ||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 35 | 1 | handles_via => 'Array', | |||||||||||||||||||||||||||||||||||||
| 36 | handles => { | ||||||||||||||||||||||||||||||||||||||
| 37 | _cumulStartPos_push => 'push', | ||||||||||||||||||||||||||||||||||||||
| 38 | _cumulStartPos_get => 'get', | ||||||||||||||||||||||||||||||||||||||
| 39 | _cumulStartPos_get => 'set' | ||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||
| 43 | has _cumulEndPos => ( | ||||||||||||||||||||||||||||||||||||||
| 44 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||
| 45 | isa => ArrayRef[Int], | ||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 47 | 1 | handles_via => 'Array', | |||||||||||||||||||||||||||||||||||||
| 48 | handles => { | ||||||||||||||||||||||||||||||||||||||
| 49 | _cumulEndPos_push => 'push', | ||||||||||||||||||||||||||||||||||||||
| 50 | _cumulEndPos_get => 'get', | ||||||||||||||||||||||||||||||||||||||
| 51 | _cumulEndPos_set => 'set' | ||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||
| 55 | 1 | has _idx => ( | |||||||||||||||||||||||||||||||||||||
| 56 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||
| 57 | isa => PositiveOrZeroInt, | ||||||||||||||||||||||||||||||||||||||
| 58 | default => -1, | ||||||||||||||||||||||||||||||||||||||
| 59 | handles_via => 'Number', | ||||||||||||||||||||||||||||||||||||||
| 60 | handles => { | ||||||||||||||||||||||||||||||||||||||
| 61 | _idx_add => 'add' | ||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | method input_rename(Str $name) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=3.2
Subroutine
BEGIN: called CC=1 SCAR=3.2
Subroutine
input_rename: not called CC=6 SCAR=30.0
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $self->_name_set(-1, $name); | |||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||
| 69 | # | ||||||||||||||||||||||||||||||||||||||
| 70 | # Change size of current input (i.e. the one at _idx). | ||||||||||||||||||||||||||||||||||||||
| 71 | # Should (ahem MUST) be used only when original input is unknown (i.e. stdin). | ||||||||||||||||||||||||||||||||||||||
| 72 | # Only a positive or zero number is possible (while original can be negative) | ||||||||||||||||||||||||||||||||||||||
| 73 | # | ||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | method input_resize(PositiveOrZeroInt $size) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=3.2
Subroutine
BEGIN: called CC=1 SCAR=3.2
Subroutine
input_resize: not called CC=7 SCAR=33.7
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $self->_cumulEndPos_set($self->_idx, $self->_cumulStartPos_get($self->_idx) + $size); | |||||||||||||||||||||||||||||||||||||
| 76 | 0 | foreach ($self->_idx + 1 .. $self->_name_count - 1) { | |||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $originalSize = $self->_cumulEndPos_get($_) - $self->_cumulStartPos_get($_); | |||||||||||||||||||||||||||||||||||||
| 78 | 0 | $self->_cumulStartPos_set($_, $self->_cumulEndPos_get($_ - 1) + 1); | |||||||||||||||||||||||||||||||||||||
| 79 | 0 | $self->_cumulEndPos_set($_, $self->_cumulStartPos_get($_) + $originalSize); | |||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||
| 83 | # | ||||||||||||||||||||||||||||||||||||||
| 84 | # Unknown size should be a negative number (i.e. stdin) | ||||||||||||||||||||||||||||||||||||||
| 85 | # | ||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | method input_push(Str $name, Int $size) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=3.4
Subroutine
BEGIN: called CC=1 SCAR=3.4
Subroutine
BEGIN: called CC=1 SCAR=3.4
Subroutine
input_push: not called CC=10 SCAR=40.9
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $self->_name_push($name); | |||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ($self->_idx < 0) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 89 | # | ||||||||||||||||||||||||||||||||||||||
| 90 | # Very first input | ||||||||||||||||||||||||||||||||||||||
| 91 | # | ||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $self->_cumulStartPos_push(0); | |||||||||||||||||||||||||||||||||||||
| 93 | 0 | $self->_cumulEndPos_push($size); | |||||||||||||||||||||||||||||||||||||
| 94 | 0 | $self->_set__idx(0); | |||||||||||||||||||||||||||||||||||||
| 95 | } else { | ||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $self->_cumulStartPos_push($self->_cumulEndPos_get(-1) + 1); | |||||||||||||||||||||||||||||||||||||
| 97 | # | ||||||||||||||||||||||||||||||||||||||
| 98 | # If size is < 0, end will be < start, which is ok | ||||||||||||||||||||||||||||||||||||||
| 99 | # | ||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $self->_cumulEndPos_push($self->_cumulStartPos_get(-1) + $size); | |||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | # | ||||||||||||||||||||||||||||||||||||||
| 105 | # We will have the internal of Perl for a number. | ||||||||||||||||||||||||||||||||||||||
| 106 | # And I barely think this will always be enough. | ||||||||||||||||||||||||||||||||||||||
| 107 | # If this is not the case, synchronization lines | ||||||||||||||||||||||||||||||||||||||
| 108 | # will be affected. | ||||||||||||||||||||||||||||||||||||||
| 109 | # | ||||||||||||||||||||||||||||||||||||||
| 110 | 1 | has _consumed => ( | |||||||||||||||||||||||||||||||||||||
| 111 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||
| 112 | isa => PositiveOrZeroInt, | ||||||||||||||||||||||||||||||||||||||
| 113 | default => 0, | ||||||||||||||||||||||||||||||||||||||
| 114 | handles_via => 'Number', | ||||||||||||||||||||||||||||||||||||||
| 115 | handles => { | ||||||||||||||||||||||||||||||||||||||
| 116 | _consumed_add => 'add' | ||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||
| 118 | ); | ||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||
| 120 | # | ||||||||||||||||||||||||||||||||||||||
| 121 | # This method will return true of a synchronisation information | ||||||||||||||||||||||||||||||||||||||
| 122 | # should be printed out | ||||||||||||||||||||||||||||||||||||||
| 123 | # | ||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | method input_consumed(Str $consumed, Str $produced --> Bool) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=3.4
Subroutine
BEGIN: called CC=1 SCAR=3.4
Subroutine
BEGIN: called CC=1 SCAR=3.4
Subroutine
input_consumed: not called CC=11 SCAR=42.3
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $self->_consumed_add(length($consumed)); | |||||||||||||||||||||||||||||||||||||
| 126 | # | ||||||||||||||||||||||||||||||||||||||
| 127 | # Adjust current index in the input array | ||||||||||||||||||||||||||||||||||||||
| 128 | # | ||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if ($self->_consumed > $self->_cumulEndPos($self->_idx)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 130 | # | ||||||||||||||||||||||||||||||||||||||
| 131 | # If current input has end position < start position, its real size | ||||||||||||||||||||||||||||||||||||||
| 132 | # is unknown, therefore any consumption belongs to it (i.e. stdin) | ||||||||||||||||||||||||||||||||||||||
| 133 | # | ||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if ($self->_cumulEndPos($self->_idx) < $self->_cumulStartPos($self->_idx)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 135 | } else { | ||||||||||||||||||||||||||||||||||||||
| 136 | # | ||||||||||||||||||||||||||||||||||||||
| 137 | # Scan the remaining start positions | ||||||||||||||||||||||||||||||||||||||
| 138 | # | ||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||
| 143 | 1 | with 'MarpaX::Languages::M4::Role::Input'; | |||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||
| 146 | 1 | 1; | |||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||
| 148 | __END__ | ||||||||||||||||||||||||||||||||||||||