blib/lib/App/Asciio/Undo.pm

filter: Statementstmt 27.4% 17 / 62 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 5 / 10 Podpod 0.0% 0 / 5 totaltotal 23.1% 22 / 95 CC 9 SCAR 23.6
CC
9
Cov
22%
undo
20.0
do
20.0
pop_undo_buffer
6.0
CRAP 10.6
« blib/lib/App/Asciio/Actions/Unsorted.pm ↑ Summary blib/lib/App/Asciio/Actions/Git.pm »
1  
2 package App::Asciio ;
3  
4 4 $|++ ;
5  
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 ▶use File::Slurp ;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Compress::Bzip2 qw(:all :utilities :gzip);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Sereal qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 get_sereal_decoder
13 get_sereal_encoder
14 clear_sereal_object_cache
15
16 encode_sereal
17 decode_sereal
18 4 ) ;
19  
20 #-----------------------------------------------------------------------------
21  
22 sub pop_undo_buffer
23 0 ▶{
Subroutine pop_undo_buffer: not called CC=2 SCAR=17.9
Pod undocumented
24 0 my ($self, $number_of_steps) = @_;
25  
26 0 pop @{$self->{DO_STACK}} for(1 .. $number_of_steps) ;
27 }
28  
29 #-----------------------------------------------------------------------------
30  
31 sub redo
32 0 ▶{
Subroutine redo: not called CC=2 SCAR=17.9
Pod undocumented
33 0 my ($self, $number_of_steps) = @_;
34  
35 0 $self->{DO_STACK_POINTER} += $number_of_steps ;
36  
37 0 ▶if($self->{DO_STACK_POINTER} >= @{$self->{DO_STACK}})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DO_STACK_POINTER"} >= @{$self->{"DO_STACK"};}) 0 0 0
38 {
39 0 $self->{DO_STACK_POINTER} = @{$self->{DO_STACK}} - 1 ;
40 }
41  
42 0 $self->do($self->{DO_STACK_POINTER}) ;
43 }
44  
45 #-----------------------------------------------------------------------------
46  
47 sub undo
48 0 ▶{
Subroutine undo: not called CC=4 SCAR=30.0
Pod undocumented
49 0 my ($self, $number_of_steps) = @_;
50  
51 0 (my $new_stack_pointer = $self->{DO_STACK_POINTER}) -= $number_of_steps ;
52  
53 0 ▶$new_stack_pointer = 0 if $new_stack_pointer < 0 ;
Branch: 1 branch
BranchTrueFalseTotal
if $new_stack_pointer < 0 0 0 0
54  
55 0 ▶$self->{DO_STACK} //= [] ;
Condition0%0/2
$self->{"DO_STACK"} //= []
l!l
00
MC/DC0%0/1
$self->{"DO_STACK"} //= []
$self->{"DO_STACK"}
Truth table0%0/2
A
A= $self->{"DO_STACK"}
Aresult
11
00
56  
57 0 ▶if($self->{DO_STACK_POINTER} == @{$self->{DO_STACK}})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DO_STACK_POINTER"} == @{$self->{"DO_STACK"};}) 0 0 0
58 {
59 0 $self->create_undo_snapshot() ;
60 }
61  
62 0 $self->{DO_STACK_POINTER} = $new_stack_pointer ;
63  
64 0 $self->do($new_stack_pointer) ;
65 }
66  
67 #-----------------------------------------------------------------------------
68  
69 sub do
70 0 ▶{
Subroutine do: not called CC=4 SCAR=30.0
Pod undocumented
71 0 my ($self, $stack_pointer) = @_;
72  
73 0 my $new_self = $self->{DO_STACK}[$stack_pointer] ;
74  
75 0 ▶if(defined $new_self)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new_self) { } 0 0 0
76 {
77 0 my ($do_stack_pointer, $do_stack) = ($self->{DO_STACK_POINTER}, $self->{DO_STACK}) ;
78
79 0 ▶ $self->{CACHE}{DECODER} = my $decoder = $self->{CACHE}{DECODER} // get_sereal_decoder() ;
Condition0%0/3
$self->{"CACHE"}{"DECODER"} // get_sereal_decoder()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"CACHE"}{"DECODER"} // get_sereal_decoder()
$self->{"CACHE"}{"DECODER"} get_sereal_decoder()
Truth table0%0/3
A // B
A= $self->{"CACHE"}{"DECODER"}B= get_sereal_decoder()
ABresult
1X1
011
000
80
81 0 my $saved_self = $decoder->decode($new_self) ;
82
83 0 ▶ if($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
84 {
85 0 write_file('undo_error.pl', {binmode => ':utf8'}, $saved_self) ;
86 0 die "Can't undo! $@\n" ;
87 }
88 else
89 {
90 0 $self->load_self($saved_self) ;
91 0 ($self->{DO_STACK_POINTER}, $self->{DO_STACK}) = ($do_stack_pointer, $do_stack) ;
92 0 $self->set_modified_state(1) ;
93
94 0 $self->update_display() ;
95 }
96 }
97 else
98 {
99 0 $self->set_modified_state(0) ;
100 }
101 }
102  
103 #-----------------------------------------------------------------------------
104  
105 sub create_undo_snapshot
106 0 ▶{
Subroutine create_undo_snapshot: not called CC=1 SCAR=6.9
Pod undocumented
107 0 my ($self) = @_;
108 0 my $serialized_self ;
109  
110 {
111 0 local $self->{DO_STACK} = undef ;
112 0 $serialized_self = $self->serialize_self() ;
113 }
114  
115 0 splice(@{$self->{DO_STACK}}, min($self->{DO_STACK_POINTER}, scalar(@{$self->{DO_STACK}}))) ; # new do branch
116  
117 0 push @{$self->{DO_STACK}}, $serialized_self ;
118 0 $self->{DO_STACK_POINTER} = @{$self->{DO_STACK}} ;
119 }
120  
121 #-----------------------------------------------------------------------------
122  
123 4 1 ;
124  
« blib/lib/App/Asciio/Actions/Unsorted.pm ↑ Summary blib/lib/App/Asciio/Actions/Git.pm »