blib/lib/App/Asciio/stripes/exec_box.pm untested

filter: Statementstmt 0.0% 0 / 76 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 134 CC 9 SCAR 30.8
CC
9
Cov
0%
set_text
56.0
new
6.0
edit
6.0
CRAP 21.7
1  
2 package App::Asciio::stripes::exec_box ;
3 use parent qw/App::Asciio::stripes::editable_box2/ ;
4  
5 use strict;
6 use warnings;
7 use utf8;
8 use Encode;
9  
10 use List::Util qw(min max) ;
11 use Readonly ;
12 use Clone ;
13  
14 #-----------------------------------------------------------------------------
15  
16 Readonly my $DEFAULT_BOX_TYPE =>
17 [
18 [1, 'top', '.', '-', '.', 1, ],
19 [0, 'title separator', '|', '-', '|', 1, ],
20 [1, 'body separator', '| ', '|', ' |', 1, ],
21 [1, 'bottom', '\'', '-', '\'', 1, ],
22 [1, 'fill-character', '', ' ', '', 1, ],
23 ] ;
24  
25 Readonly my $NO_BORDER =>
26 [
27 [0, 'top', '.', '-', '.', 1, ],
28 [0, 'title separator', '|', '-', '|', 1, ],
29 [0, 'body separator', '| ', '|', ' |', 1, ],
30 [0, 'bottom', '\'', '-', '\'', 1, ],
31 [0, 'fill-character', '', ' ', '', 1, ],
32 ] ;
33  
34 sub new
35 {
36 my ($class, $element_definition) = @_ ;
37  
38 my $self = bless {}, __PACKAGE__ ;
39  
40 my $box = $element_definition->{NO_BORDER} ? Clone::clone($NO_BORDER) : $element_definition->{BOX_TYPE} // Clone::clone($DEFAULT_BOX_TYPE) ;
41  
42 App::Asciio::stripes::editable_box2::setup
43 (
44 $self,
45 $element_definition->{TEXT_ONLY},
46 $element_definition->{TITLE},
47 $box,
48 1, 1,
49 $element_definition->{RESIZABLE},
50 $element_definition->{EDITABLE},
51 $element_definition->{AUTO_SHRINK},
52 ) ;
53  
54 $self->{RUN_VERBATIM} = $element_definition->{RUN_VERBATIM} // 0 ;
55 $self->{VERBATIM_COMMAND} = $element_definition->{VERBATIM_COMMAND} // '' ;
56 $self->{RUN_ONCE} = $element_definition->{RUN_ONCE} // 0 ;
57  
58 return $self ;
59 }
60  
61 #-----------------------------------------------------------------------------
62  
63 sub set_text
64 {
65 my ($self, $asciio, $title, $text) = @_ ;
66  
67 my $command = $self->{COMMAND} = $text ;
68 my $output = 'command failed' ;
69  
70 if($self->{RUN_DONE})
71 {
72 $output = $text ;
73 }
74 else
75 {
76 if(defined $command && $command ne '')
77 {
78 my $command_stderr_redirected ;
79
80 if($self->{RUN_VERBATIM})
81 {
82 $command_stderr_redirected = $command ;
83 }
84 else
85 {
86 ($command_stderr_redirected = $command) =~ s/$/ 2>&1/gsm ;
87 }
88
89 $output = `timeout 2 $command_stderr_redirected` ;
90
91 if($?)
92 {
93 $output = '' unless defined $output ;
94 $output = "Can't execute '$command':\noutput:\n$output\nerror:\n$! [$?]" ;
95 }
96 else
97 {
98 if($self->{RUN_ONCE})
99 {
100 $self->{RUN_DONE}++ ;
101 $self->{COMMAND} = $output ;
102 }
103 }
104 }
105 else
106 {
107 $output = 'no command' ;
108 }
109
110 $output = decode("utf-8", $output) ;
111 $output =~ s/\r//g;
112 $output =~ s/\t/$asciio->{TAB_AS_SPACES}/g;
113 }
114  
115 App::Asciio::stripes::editable_box2::setup
116 (
117 $self,
118 $output,
119 $title,
120 $self->{BOX_TYPE},
121 $self->{WIDTH},
122 $self->{HEIGHT},
123 $self->{RESIZABLE},
124 $self->{EDITABLE},
125 $self->{AUTO_SHRINK},
126 ) ;
127 }
128  
129 #-----------------------------------------------------------------------------
130  
131 sub edit
132 {
133 my ($self, $asciio) = @_ ;
134  
135 return unless $self->{EDITABLE} ;
136  
137 my $text = $self->{TEXT_ONLY} ;
138  
139 ($text, my $title) = $self->display_box_edit_dialog($self->{TITLE}, $self->{COMMAND} // $self->{VERBATIM_COMMAND} // '', $asciio) ;
140  
141 my $tab_as_space = $asciio->{TAB_AS_SPACES} ;
142  
143 $text =~ s/\t/$tab_as_space/g ;
144 $title=~ s/\t/$tab_as_space/g ;
145  
146 $self->set_text($asciio, $title, $text) ;
147 }
148  
149 #-----------------------------------------------------------------------------
150  
151 sub rotate_text { ; }
152  
153 #-----------------------------------------------------------------------------
154  
155 1 ;