lib/App/PerlShell.pm

filter: Statementstmt 13.3% 48 / 359 Branchbran 0.9% 2 / 204 Conditioncond 0.0% 0 / 33 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 41.9% 13 / 31 Podpod 100% 17 / 17 totaltotal 12.0% 80 / 663 CC 126 SCAR 61.4
CC
126
Cov
8%
run
1406.0
new
420.0
session
272.0
CRAP 464.1
↑ Summary lib/App/PerlShell/Plugin/File.pm »
1 package App::PerlShell;
2  
3 ########################################################
4 # AUTHOR = Michael Vincent
5 # www.VinsWorld.com
6 ########################################################
7  
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 our $VERSION = "1.09";
13  
14 2 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Term::ReadLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 $Data::Dumper::Sortkeys = 1;
18  
19 2 my $HAVE_LexPersist = 0;
20 0 ▶eval "use Lexical::Persistence 1.01 ()";
Subroutine BEGIN: called CC=1 SCAR=1.2
21 2 ▶if ( !$@ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 2 2
22 0 eval "use App::PerlShell::LexPersist";
23 0 $HAVE_LexPersist = 1;
24 }
25 2 my $HAVE_ModRefresh = 0;
26 0 ▶eval "use Module::Refresh";
Subroutine BEGIN: called CC=1 SCAR=1.2
27 2 ▶if ( !$@ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 2 2
28 0 eval "use App::PerlShell::ModRefresh";
29 0 $HAVE_ModRefresh = 1;
30 }
31  
32 2 my %COMMANDS_INTERNAL = (
33 debug => 'print command',
34 exit => 'exit shell'
35 );
36  
37 2 my %COMMANDS = (
38 'cd' => 'change directory',
39 'cls' => 'clear screen',
40 'clear' => 'clear screen',
41 'commands' => 'print available "commands" (sub)',
42 'dir' => 'directory listing',
43 'dumper' => 'use Data::Dumper to display variable',
44 'env' => 'list environment variables',
45 'help' => 'shell help - print this',
46 'ls' => 'directory listing',
47 'modules' => 'list used modules',
48 'perldoc' => 'perldoc for current package',
49 'pwd' => 'print working directory',
50 'session' => 'start / stop logging session',
51 'variables' => 'list defined variables',
52 'version' => 'print version information'
53 );
54  
55 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 2 our @EXPORT = sort ( keys ( %COMMANDS ) );
57 2 our @ISA = qw ( Exporter );
58  
59 0 ▶sub _shellCommands {
Subroutine _shellCommands: not called CC=1 SCAR=6.9
60 0 return ( %COMMANDS, %COMMANDS_INTERNAL );
61 }
62  
63 0 ▶sub new {
Subroutine new: not called CC=20 SCAR=60.4
Pod documented
64 0 my $self = shift;
65 0 ▶ my $class = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
66  
67 # Default parameters
68 my %params = (
69 homedir => ( $^O eq "MSWin32" ) ? $ENV{USERPROFILE} : $ENV{HOME},
70 0 ▶ package => __PACKAGE__,
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
71 prompt => 'Perl> '
72 );
73  
74 0 my $lex = 0;
75 0 my $verbose = 0;
76 0 ▶ if ( @_ == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
77 0 croak("Insufficient number of args - @_");
78 } else {
79 0 my %cfg = @_;
80 0 for ( keys(%cfg) ) {
81 0 ▶ if (/^-?homedir$/i) {
Branch: 9 branches
BranchTrueFalseTotal
if (/^-?homedir$/i) { } 0 0 0
elsif (/^-?execute$/i) { } 0 0 0
elsif (/^-?lex(?:ical)?$/i) { } 0 0 0
elsif (/^-?package$/i) { } 0 0 0
elsif (/^-?prompt$/i) { } 0 0 0
elsif (/^-?feature$/i) { } 0 0 0
elsif (/^-?session$/i) { } 0 0 0
elsif (/^-?skipvars$/i) { } 0 0 0
elsif (/^-?verbose$/i) { } 0 0 0
82 0 ▶ if ( -d $cfg{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $cfg{$_}) { } 0 0 0
83 0 $params{homedir} = $cfg{$_};
84 } else {
85 0 croak("Cannot find directory `$cfg{$_}'");
86 }
87 } elsif (/^-?execute$/i) {
88 0 $params{execute} = $cfg{$_};
89 } elsif (/^-?lex(?:ical)?$/i) {
90 0 $lex = 1;
91 } elsif (/^-?package$/i) {
92 0 $params{package} = $cfg{$_};
93 } elsif (/^-?prompt$/i) {
94 0 $params{prompt} = $cfg{$_};
95 } elsif (/^-?feature$/i) {
96 0 $params{feature} = $cfg{$_};
97 } elsif (/^-?session$/i) {
98 # assign, will test open in run()
99 0 $params{session} = $cfg{$_};
100 } elsif (/^-?skipvars$/i) {
101 0 ▶ if ( ref $cfg{$_} eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cfg{$_} eq 'ARRAY') { } 0 0 0
102 0 $params{skipvars} = $cfg{$_};
103 } else {
104 0 croak("Not array reference `$cfg{$_}'");
105 }
106 } elsif (/^-?verbose$/i) {
107 0 $verbose = 1;
108 } else {
109 0 croak("Unknown parameter `$_' => `$cfg{$_}'");
110 }
111 }
112 }
113  
114 0 ▶ if ($lex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lex) 0 0 0
115 0 ▶ if ($HAVE_LexPersist) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HAVE_LexPersist) { } 0 0 0
116 $params{shellLexEnv}
117 0 = App::PerlShell::LexPersist->new( $params{package} );
118 } else {
119 0 croak(
120 "-lexical specified, `Lexical::Persistence' required but not found"
121 );
122 }
123 }
124  
125 # Setup Environment Variables
126 0 $ENV{PERLSHELL_FEATURE} = $params{feature};
127 0 $ENV{PERLSHELL_HOME} = $params{homedir};
128 0 $ENV{PERLSHELL_PACKAGE} = $params{package};
129 0 $ENV{PERLSHELL_PERLDOC} = 'perldoc';
130 0 $ENV{PERLSHELL_PROMPT} = $params{prompt};
131 0 $ENV{PERLSHELL_SEMIOFF} = 0;
132 0 ▶ if ( defined $params{skipvars} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"skipvars"}) 0 0 0
133 0 $ENV{PERLSHELL_SKIPVARS} = join ';', @{$params{skipvars}};
134 }
135  
136 0 ▶ if ( $verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 0 0
137 0 print "$params{execute}\n";
138 }
139  
140 # clean up object
141 0 delete $params{feature};
142 0 delete $params{homedir};
143 0 delete $params{package};
144 0 delete $params{prompt};
145 0 delete $params{skipvars};
146 0 return bless \%params, $class;
147 }
148  
149 0 ▶sub run {
Subroutine run: not called CC=38 SCAR=72.5
Pod documented
150 0 my $App_PerlShell_Shell = shift;
151  
152 # handle session if requested
153 0 ▶ if ( defined $App_PerlShell_Shell->{session} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $App_PerlShell_Shell->{"session"}) 0 0 0
154 0 ▶ if ( not defined session( $App_PerlShell_Shell->{session} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined session($App_PerlShell_Shell->{"session"})) 0 0 0
155 0 croak(
156 "Cannot open session file `$App_PerlShell_Shell->{session}'");
157 }
158 }
159  
160 0 ▶ if ( exists $App_PerlShell_Shell->{shellLexEnv} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $App_PerlShell_Shell->{'shellLexEnv'}) { } 0 0 0
161 $App_PerlShell_Shell->{shell}
162 0 = $App_PerlShell_Shell->{shellLexEnv}->get_package();
163 } else {
164 0 $App_PerlShell_Shell->{shell} = $ENV{PERLSHELL_PACKAGE};
165 }
166 $App_PerlShell_Shell->{shell}
167 0 = Term::ReadLine->new( $App_PerlShell_Shell->{shell} );
168 0 $App_PerlShell_Shell->{shell}->ornaments(0);
169  
170 #'use strict' is not used to allow "$p=" instead of "my $p=" at the prompt
171 2 ▶ no strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
172  
173 # will always exeucte without readline first time through (do ... while)
174 0 while (1) {
175  
176 # do ... while loop won't support next and last
177 # First check then clear {execute} to autopopulate
178 # $App_PerlShell_Shell->{shellCmdLine}
179 # otherwise, just do the readline.
180  
181 0 ▶ if ( defined $App_PerlShell_Shell->{execute} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $App_PerlShell_Shell->{'execute'}) { } 0 0 0
182 $App_PerlShell_Shell->{shellCmdLine}
183 0 = $App_PerlShell_Shell->{execute};
184  
185 # clear - it will never happen again
186 0 delete $App_PerlShell_Shell->{execute};
187 } else {
188 $App_PerlShell_Shell->{shellCmdLine}
189 .= $App_PerlShell_Shell->{shell}->readline(
190 ( defined $App_PerlShell_Shell->{shellCmdLine} )
191 ? 'More? '
192 : $ENV{PERLSHELL_PROMPT}
193 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
defined $App_PerlShell_Shell->{'shellCmdLine'} ? : 0 0 0
194 }
195  
196 0 chomp $App_PerlShell_Shell->{shellCmdLine};
197  
198 # nothing
199 0 ▶ if ( $App_PerlShell_Shell->{shellCmdLine} =~ /^\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($App_PerlShell_Shell->{"shellCmdLine"} =~ /^\s*$/) 0 0 0
200 0 undef $App_PerlShell_Shell->{shellCmdLine};
201 0 next;
202 }
203  
204 # exit
205 0 ▶ if ( $App_PerlShell_Shell->{shellCmdLine} =~ /^\s*exit\s*(;)?\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($App_PerlShell_Shell->{"shellCmdLine"} =~ /^\s*exit\s*(;)?\s*$/) 0 0 0
206 0 ▶ if ( not defined $1 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $1) 0 0 0
207 0 $App_PerlShell_Shell->{shellCmdLine} .= ';';
208 }
209 0 last;
210 }
211  
212 # debug multiline
213 0 ▶ if ( $App_PerlShell_Shell->{shellCmdLine} =~ /\ndebug$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($App_PerlShell_Shell->{"shellCmdLine"} =~ /\ndebug$/) 0 0 0
214 0 $App_PerlShell_Shell->{shellCmdLine} =~ s/debug$//;
215 0 print Dumper $App_PerlShell_Shell;
216 0 next;
217 }
218  
219 # variables if in -lexical
220 0 ▶ if ( exists $App_PerlShell_Shell->{shellLexEnv} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $App_PerlShell_Shell->{"shellLexEnv"}) 0 0 0
221 0 ▶ if ( $App_PerlShell_Shell->{shellCmdLine}
Branch: 1 branch
BranchTrueFalseTotal
if ($App_PerlShell_Shell->{"shellCmdLine"} =~ /^\s*variables\s*;\s*$/) 0 0 0
222 =~ /^\s*variables\s*;\s*$/ ) {
223 0 for my $var (
224 sort( keys(
225 %{ $App_PerlShell_Shell->{shellLexEnv}
226 0 ->get_context('_')
227 }
228 ) )
229 ) {
230 0 print "$var\n";
231 }
232 0 undef $App_PerlShell_Shell->{shellCmdLine};
233 0 next;
234 }
235 }
236  
237 # Complete statement
238 0 %{$App_PerlShell_Shell->{shellCmdComplete}} = (
239 'parenthesis' => 0,
240 'bracket' => 0,
241 'brace' => 0
242 );
243 0 ▶ if ( my @c = ( $App_PerlShell_Shell->{shellCmdLine} =~ /\(/g ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@c) = $App_PerlShell_Shell->{"shellCmdLine"} =~ /\(/g) 0 0 0
244 $App_PerlShell_Shell->{shellCmdComplete}->{parenthesis}
245 0 += scalar(@c);
246 }
247 0 ▶ if ( my @c = ( $App_PerlShell_Shell->{shellCmdLine} =~ /\)/g ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@c) = $App_PerlShell_Shell->{"shellCmdLine"} =~ /\)/g) 0 0 0
248 $App_PerlShell_Shell->{shellCmdComplete}->{parenthesis}
249 0 -= scalar(@c);
250 }
251 0 ▶ if ( my @c = ( $App_PerlShell_Shell->{shellCmdLine} =~ /\[/g ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@c) = $App_PerlShell_Shell->{"shellCmdLine"} =~ /\[/g) 0 0 0
252 0 $App_PerlShell_Shell->{shellCmdComplete}->{bracket} += scalar(@c);
253 }
254 0 ▶ if ( my @c = ( $App_PerlShell_Shell->{shellCmdLine} =~ /\]/g ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@c) = $App_PerlShell_Shell->{"shellCmdLine"} =~ /\]/g) 0 0 0
255 0 $App_PerlShell_Shell->{shellCmdComplete}->{bracket} -= scalar(@c);
256 }
257 0 ▶ if ( my @c = ( $App_PerlShell_Shell->{shellCmdLine} =~ /\{/g ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@c) = $App_PerlShell_Shell->{"shellCmdLine"} =~ /\{/g) 0 0 0
258 0 $App_PerlShell_Shell->{shellCmdComplete}->{brace} += scalar(@c);
259 }
260 0 ▶ if ( my @c = ( $App_PerlShell_Shell->{shellCmdLine} =~ /\}/g ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@c) = $App_PerlShell_Shell->{"shellCmdLine"} =~ /\}/g) 0 0 0
261 0 $App_PerlShell_Shell->{shellCmdComplete}->{brace} -= scalar(@c);
262 }
263  
264 0 ▶ if ( ( $App_PerlShell_Shell->{shellCmdLine} =~ /,\s*$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($App_PerlShell_Shell->{"shellCmdLine"} =~ /,\s*$/ or $App_PerlShell_Shell->{"shellCmdComplete"}{"parenthesis"} != 0 or $App_PerlShell_Shell->{"shellCmdComplete"}{"bracket"} != 0 or $App_PerlShell_Shell->{"shellCmdComplete"}{"brace"} != 0) 0 0 0
Condition0%0/9
$App_PerlShell_Shell->{"shellCmdLine"} =~ /,\s*$/ or $App_PerlShell_Shell->{"shellCmdComplete"}{"parenthesis"} != 0 or $App_PerlShell_Shell->{"shellCmdComplete"}{"bracket"} != 0 or $App_PerlShell_Shell->{"shellCmdComplete"}{"brace"} != 0
l!l&&r!l&&!r
000
$App_PerlShell_Shell->{"shellCmdLine"} =~ /,\s*$/ or $App_PerlShell_Shell->{"shellCmdComplete"}{"parenthesis"} != 0 or $App_PerlShell_Shell->{"shellCmdComplete"}{"bracket"} != 0
l!l&&r!l&&!r
000
$App_PerlShell_Shell->{"shellCmdLine"} =~ /,\s*$/ or $App_PerlShell_Shell->{"shellCmdComplete"}{"parenthesis"} != 0
l!l&&r!l&&!r
000
MC/DC0%0/4
$App_PerlShell_Shell->{"shellCmdLine"} =~ /,\s*$/ or $App_PerlShell_Shell->{"shellCmdComplete"}{"parenthesis"} != 0 or $App_PerlShell_Shell->{"shellCmdComplete"}{"bracket"} != 0 or $App_PerlShell_Shell->{"shellCmdComplete"}{"brace"} != 0
$App_PerlShell_Shell->{"shellCmdLine"} =~ /,\s*$/ $App_PerlShell_Shell->{"shellCmdComplete"}{"parenthesis"} != 0 $App_PerlShell_Shell->{"shellCmdComplete"}{"bracket"} != 0 $App_PerlShell_Shell->{"shellCmdComplete"}{"brace"} != 0
Truth table0%0/5
A or B or C or D
A= $App_PerlShell_Shell->{"shellCmdLine"} =~ /,\s*$/B= $App_PerlShell_Shell->{"shellCmdComplete"}{"parenthesis"} != 0C= $App_PerlShell_Shell->{"shellCmdComplete"}{"bracket"} != 0D= $App_PerlShell_Shell->{"shellCmdComplete"}{"brace"} != 0
ABCDresult
1XXX1
01XX1
001X1
00011
00000
265 or ( $App_PerlShell_Shell->{shellCmdComplete}->{parenthesis} != 0 )
266 or ( $App_PerlShell_Shell->{shellCmdComplete}->{bracket} != 0 )
267 or ( $App_PerlShell_Shell->{shellCmdComplete}->{brace} != 0 )
268 ) {
269 0 ▶ if ( $App_PerlShell_Shell->{shellCmdLine} !~ /\n;$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($App_PerlShell_Shell->{"shellCmdLine"} =~ /\n;$/) 0 0 0
270 0 $App_PerlShell_Shell->{shellCmdLine} .= "\n";
271 0 next;
272 }
273 }
274  
275 # if all groupings are closed
276 0 ▶ if ( ( $App_PerlShell_Shell->{shellCmdComplete}->{parenthesis} == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($App_PerlShell_Shell->{"shellCmdComplete"}{"parenthesis"} == 0 and $App_PerlShell_Shell->{"shellCmdComplete"}{"bracket"} == 0 and $App_PerlShell_Shell->{"shellCmdComplete"}{"brace"} == 0) 0 0 0
Condition0%0/6
$App_PerlShell_Shell->{"shellCmdComplete"}{"parenthesis"} == 0 and $App_PerlShell_Shell->{"shellCmdComplete"}{"bracket"} == 0 and $App_PerlShell_Shell->{"shellCmdComplete"}{"brace"} == 0
!ll&&!rl&&r
000
$App_PerlShell_Shell->{"shellCmdComplete"}{"parenthesis"} == 0 and $App_PerlShell_Shell->{"shellCmdComplete"}{"bracket"} == 0
!ll&&!rl&&r
000
MC/DC0%0/3
$App_PerlShell_Shell->{"shellCmdComplete"}{"parenthesis"} == 0 and $App_PerlShell_Shell->{"shellCmdComplete"}{"bracket"} == 0 and $App_PerlShell_Shell->{"shellCmdComplete"}{"brace"} == 0
$App_PerlShell_Shell->{"shellCmdComplete"}{"parenthesis"} == 0 $App_PerlShell_Shell->{"shellCmdComplete"}{"bracket"} == 0 $App_PerlShell_Shell->{"shellCmdComplete"}{"brace"} == 0
Truth table0%0/4
A and B and C
A= $App_PerlShell_Shell->{"shellCmdComplete"}{"parenthesis"} == 0B= $App_PerlShell_Shell->{"shellCmdComplete"}{"bracket"} == 0C= $App_PerlShell_Shell->{"shellCmdComplete"}{"brace"} == 0
ABCresult
0XX0
10X0
1100
1111
277 and ( $App_PerlShell_Shell->{shellCmdComplete}->{bracket} == 0 )
278 and ( $App_PerlShell_Shell->{shellCmdComplete}->{brace} == 0 )
279 ) {
280 # valid endings are ; or }
281 0 ▶ if ( $App_PerlShell_Shell->{shellCmdLine} !~ /(;|\})\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($App_PerlShell_Shell->{"shellCmdLine"} =~ /(;|\})\s*$/) 0 0 0
282 # unless PERLSHELL_SEMIOFF, we can add it and continue
283 0 ▶ if ( $ENV{PERLSHELL_SEMIOFF} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'PERLSHELL_SEMIOFF'}) { } 0 0 0
284 0 $App_PerlShell_Shell->{shellCmdLine} .= ";";
285 } else {
286 0 $App_PerlShell_Shell->{shellCmdLine} .= "\n";
287 0 next;
288 }
289 }
290 }
291  
292 # import subs if not default package
293 # use redundant code in the if block so no variables are
294 # created at top level in case we're not using LexPersist
295 0 ▶ if ( exists $App_PerlShell_Shell->{shellLexEnv} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $App_PerlShell_Shell->{'shellLexEnv'}) { } 0 0 0
296 0 ▶ if ( $App_PerlShell_Shell->{shellLexEnv}->get_package() ne
Branch: 1 branch
BranchTrueFalseTotal
if ($App_PerlShell_Shell->{"shellLexEnv"}->get_package ne __PACKAGE__) 0 0 0
297 __PACKAGE__ ) {
298 0 my $sp = $App_PerlShell_Shell->{shellLexEnv}->get_package();
299 0 my $p = __PACKAGE__;
300 0 eval "package $sp; $p->import;";
301 0 ▶ if ($HAVE_ModRefresh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HAVE_ModRefresh) 0 0 0
302 0 App::PerlShell::ModRefresh->refresh($sp);
303 }
304 }
305  
306 $App_PerlShell_Shell->{shellCmdLine}
307 = "use feature qw(" . $ENV{PERLSHELL_FEATURE} . ");\n"
308 0 . $App_PerlShell_Shell->{shellCmdLine};
309  
310 # execute
311 0 eval {
312 $App_PerlShell_Shell->{shellLexEnv}
313 0 ->do( $App_PerlShell_Shell->{shellCmdLine} );
314 };
315 } else {
316 0 ▶ if ( $ENV{PERLSHELL_PACKAGE} ne __PACKAGE__ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"PERLSHELL_PACKAGE"} ne __PACKAGE__) 0 0 0
317 0 my $sp = $ENV{PERLSHELL_PACKAGE};
318 0 my $p = __PACKAGE__;
319 0 eval "package $sp; $p->import;";
320 0 ▶ if ($HAVE_ModRefresh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HAVE_ModRefresh) 0 0 0
321 0 App::PerlShell::ModRefresh->refresh($sp);
322 }
323 }
324 $App_PerlShell_Shell->{shellCmdLine}
325 = "package " . $ENV{PERLSHELL_PACKAGE} . ";\n"
326 . "use feature qw(" . $ENV{PERLSHELL_FEATURE} . ");\n"
327 . $App_PerlShell_Shell->{shellCmdLine}
328 0 . "\nBEGIN {\$ENV{PERLSHELL_PACKAGE} = __PACKAGE__}";
329  
330 # execute
331 0 eval $App_PerlShell_Shell->{shellCmdLine};
332 }
333  
334 # error from execute?
335 0 ▶ warn $@ if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
336  
337 # logging if requested and no error
338 0 ▶ if ( defined( $ENV{PERLSHELL_SESSION} ) and !$@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"PERLSHELL_SESSION"} and not $@) 0 0 0
Condition0%0/3
defined $ENV{"PERLSHELL_SESSION"} and not $@
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ENV{"PERLSHELL_SESSION"} and not $@
defined $ENV{"PERLSHELL_SESSION"} not $@
Truth table0%0/3
A and not(B)
A= defined $ENV{"PERLSHELL_SESSION"}B= not $@
ABresult
0X0
100
111
339  
340 # clean up command if we added stuff while not in -lex mode
341 0 $App_PerlShell_Shell->{shellCmdLine} =~ s/^package .*?;\n//;
342 0 $App_PerlShell_Shell->{shellCmdLine} =~ s/^use feature qw\(.*?\);\n//;
343  
344 # don't log session start command
345 0 $App_PerlShell_Shell->{shellCmdLine} =~ s/\s*session\s*.*//;
346  
347 $App_PerlShell_Shell->{shellCmdLine}
348 0 =~ s/(?:\n)?BEGIN \{\$ENV\{PERLSHELL_PACKAGE\} = __PACKAGE__\}//;
349  
350 0 open( my $OUT, '>>', $ENV{PERLSHELL_SESSION} );
351 print $OUT "$App_PerlShell_Shell->{shellCmdLine}\n"
352 0 ▶ if ( $App_PerlShell_Shell->{shellCmdLine} ne '' );
Branch: 1 branch
BranchTrueFalseTotal
if $App_PerlShell_Shell->{"shellCmdLine"} ne "" 0 0 0
353 0 close $OUT;
354 }
355  
356 # reset to normal before next input
357 $App_PerlShell_Shell->{shellLastCmd}
358 0 = $App_PerlShell_Shell->{shellCmdLine};
359 0 undef $App_PerlShell_Shell->{shellCmdLine};
360 0 print "\n";
361 }
362 }
363  
364 ########################################################
365 # commands
366 ########################################################
367  
368 0 ▶sub cd {
Subroutine cd: not called CC=4 SCAR=30.0
Pod documented
369 0 my ($arg) = @_;
370  
371 0 my $ret = getcwd;
372 0 ▶ if ( not defined $arg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $arg) { } 0 0 0
373 0 chdir $ENV{PERLSHELL_HOME};
374 } else {
375 0 ▶ if ( -e $arg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $arg) { } 0 0 0
376 0 chdir $arg;
377 } else {
378 0 print "Cannot find directory `$arg'\n";
379 }
380 }
381 0 ▶ if ( defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 0 0 0
382 0 return $ret;
383 }
384 }
385  
386 0 ▶sub cls {
Subroutine cls: not called CC=1 SCAR=6.9
Pod documented
387 0 return clear();
388 }
389  
390 0 ▶sub clear {
Subroutine clear: not called CC=2 SCAR=17.9
Pod documented
391 0 ▶ if ( $^O eq "MSWin32" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
392 0 system('cls');
393 } else {
394 0 system('clear');
395 }
396 }
397  
398 0 ▶sub commands {
Subroutine commands: not called CC=11 SCAR=46.8
Pod documented
399 0 my ($arg) = @_;
400  
401 0 my @rets;
402 0 my $retType = wantarray;
403  
404 0 my $stash = $ENV{PERLSHELL_PACKAGE} . '::';
405  
406 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
407  
408 0 my $regex = qr/^.*$/;
409 0 ▶ if ( defined($arg) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) 0 0 0
410 0 $regex = qr/$arg/;
411 }
412  
413 0 for my $name ( sort( keys( %{$stash} ) ) ) {
414 0 ▶ next if ( $name =~ /^_/ );
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /^_/ 0 0 0
415  
416 0 my $sub = *{"${stash}${name}"}{CODE};
417 0 ▶ next unless defined $sub;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sub 0 0 0
418  
419 0 my $proto = prototype($sub);
420 0 ▶ next if defined $proto and length($proto) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $proto and length $proto == 0 0 0 0
Condition0%0/3
defined $proto and length $proto == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $proto and length $proto == 0
defined $proto length $proto == 0
Truth table0%0/3
A and B
A= defined $protoB= length $proto == 0
ABresult
0X0
100
111
421  
422 0 ▶ if ( $name =~ /$regex/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /$regex/) 0 0 0
423 0 push @rets, $name;
424 }
425 }
426  
427 0 ▶ if ( not defined $retType ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $retType) { } 0 0 0
elsif ($retType) { } 0 0 0
428 0 for (@rets) {
429 0 print "$_\n";
430 }
431 } elsif ($retType) {
432 0 return @rets;
433 } else {
434 0 return \@rets;
435 }
436 }
437  
438 0 ▶sub dumper {
Subroutine dumper: not called CC=1 SCAR=1.2
Pod documented
439 0 my (@dump) = @_;
440  
441 2 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
442 0 $Data::Dumper::Sortkeys = 1;
443 0 print Dumper @dump;
444 }
445  
446 0 ▶sub env {
Subroutine env: not called CC=10 SCAR=47.0
Pod documented
447 0 my ($arg) = @_;
448  
449 0 my %rets;
450 0 my $retType = wantarray;
451  
452 0 my $FOUND = 0;
453 0 for my $env ( sort( keys(%ENV) ) ) {
454 0 ▶ if ( defined $arg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) { } 0 0 0
455 0 ▶ if ( $env =~ /$arg/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($env =~ /$arg/) 0 0 0
456 0 $rets{$env} = $ENV{$env};
457 0 $FOUND = 1;
458 }
459 } else {
460 0 $rets{$env} = $ENV{$env};
461 0 $FOUND = 1;
462 }
463 }
464  
465 0 ▶ if ( !$FOUND ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($FOUND) 0 0 0
466 0 ▶ printf "Environment variable(s) not found%s",
Branch: 1 branch
BranchTrueFalseTotal
defined $arg ? : 0 0 0
467 ( defined $arg ) ? " - `$arg'\n" : "\n";
468 }
469  
470 0 ▶ if ( not defined $retType ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $retType) { } 0 0 0
elsif ($retType) { } 0 0 0
471 0 for my $env ( sort( keys(%rets) ) ) {
472 printf "$env=%s\n",
473 0 ▶ ( defined $rets{$env} ) ? $rets{$env} : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $rets{$env} ? : 0 0 0
474 }
475 } elsif ($retType) {
476 0 return %rets;
477 } else {
478 0 return \%rets;
479 }
480 }
481  
482 0 ▶sub help {
Subroutine help: not called CC=2 SCAR=17.9
Pod documented
483 0 my %cmds = _shellCommands();
484 0 for my $h ( sort( keys(%cmds) ) ) {
485 0 printf "%-15s %s\n", $h, $cmds{$h};
486 }
487 }
488  
489 0 ▶sub dir {
Subroutine dir: not called CC=1 SCAR=6.9
Pod documented
490 0 return ls(@_);
491 }
492  
493 0 ▶sub ls {
Subroutine ls: not called CC=5 SCAR=34.0
Pod documented
494 0 my (@args) = @_;
495  
496 0 my $dircmd = 'ls';
497 0 ▶ if ( $^O eq "MSWin32" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 0 0
498 0 $dircmd = 'dir';
499 }
500  
501 0 my @allArgs;
502 0 for my $arg ( @args ) {
503 0 my @temp = split /\s+/, $arg;
504 0 push @allArgs, @temp;
505 }
506 0 @args = @allArgs;
507  
508 0 my @ret;
509 0 my $retType = wantarray;
510 0 ▶ if ( not defined $retType ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $retType) { } 0 0 0
511 0 system( $dircmd, @args );
512 } else {
513 0 @ret = `$dircmd @args`;
514 0 ▶ if ($retType) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retType) { } 0 0 0
515 0 return @ret;
516 } else {
517 0 return \@ret;
518 }
519 }
520 }
521  
522 0 ▶sub modules {
Subroutine modules: not called CC=10 SCAR=47.0
Pod documented
523 0 my ($arg) = @_;
524  
525 0 my %rets;
526 0 my $retType = wantarray;
527  
528 0 my $FOUND = 0;
529 0 for my $module ( sort( keys(%INC) ) ) {
530 0 my $path = $INC{$module};
531 0 $module =~ s/\//::/g;
532 0 $module =~ s/\.pm$//;
533  
534 0 ▶ if ( defined $arg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) { } 0 0 0
535 0 ▶ if ( $module =~ /$arg/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module =~ /$arg/) 0 0 0
536 0 $rets{$module} = $path;
537 0 $FOUND = 1;
538 }
539 } else {
540 0 $rets{$module} = $path;
541 0 $FOUND = 1;
542 }
543 }
544  
545 0 ▶ if ( !$FOUND ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($FOUND) 0 0 0
546 0 ▶ printf "Module(s) not found%s",
Branch: 1 branch
BranchTrueFalseTotal
defined $arg ? : 0 0 0
547 ( defined $arg ) ? " - `$arg'\n" : "\n";
548 }
549  
550 0 ▶ if ( not defined $retType ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $retType) { } 0 0 0
elsif ($retType) { } 0 0 0
551 0 for my $module ( sort( keys(%rets) ) ) {
552 printf "$module %s\n",
553 0 ▶ ( defined $rets{$module} ) ? $rets{$module} : "[NOT LOADED]";
Branch: 1 branch
BranchTrueFalseTotal
defined $rets{$module} ? : 0 0 0
554 }
555 } elsif ($retType) {
556 0 return %rets;
557 } else {
558 0 return \%rets;
559 }
560 }
561  
562 0 ▶sub perldoc {
Subroutine perldoc: not called CC=4 SCAR=30.0
Pod documented
563 0 my (@args) = @_;
564  
565 0 ▶ if ( $#args == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#args == -1) 0 0 0
566 0 push @args, $ENV{PERLSHELL_PACKAGE};
567 }
568  
569 0 my @allArgs;
570 0 for my $arg ( @args ) {
571 0 my @temp = split /\s+/, $arg;
572 0 push @allArgs, @temp;
573 }
574 0 @args = @allArgs;
575  
576 0 ▶ if ( $args[0] =~ /^::/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args[0] =~ /^::/) 0 0 0
577 0 $args[0] = $ENV{PERLSHELL_PACKAGE} . $args[0];
578 }
579  
580 0 system( $ENV{PERLSHELL_PERLDOC}, @args );
581 }
582  
583 0 ▶sub pwd {
Subroutine pwd: not called CC=2 SCAR=17.9
Pod documented
584 0 ▶ if ( not defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined wantarray) { } 0 0 0
585 0 print getcwd;
586 } else {
587 0 return getcwd;
588 }
589 }
590  
591 0 ▶sub session {
Subroutine session: not called CC=16 SCAR=56.1
Pod documented
592 0 my ($arg) = @_;
593  
594 0 ▶ if ( not defined $arg ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $arg) 0 0 0
595 0 ▶ if ( defined $ENV{PERLSHELL_SESSION} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{'PERLSHELL_SESSION'}) { } 0 0 0
596 0 ▶ if ( not defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
597 0 print $ENV{PERLSHELL_SESSION} . "\n";
598 }
599 0 return $ENV{PERLSHELL_SESSION};
600 } else {
601 0 ▶ if ( not defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
602 0 print "No current session file\n";
603 }
604 0 return undef;
605 }
606 }
607  
608 0 ▶ if ( $arg eq ":close" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq ":close") 0 0 0
609 0 ▶ if ( defined $ENV{PERLSHELL_SESSION} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{'PERLSHELL_SESSION'}) { } 0 0 0
610 0 ▶ if ( not defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
611 0 print "$ENV{PERLSHELL_SESSION} closed\n";
612 }
613 0 $ENV{PERLSHELL_SESSION} = undef;
614 0 return;
615 } else {
616 0 ▶ if ( not defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
617 0 print "No current session file\n";
618 }
619 0 return undef;
620 }
621 }
622  
623 0 ▶ if ( not defined $ENV{PERLSHELL_SESSION} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ENV{'PERLSHELL_SESSION'}) { } 0 0 0
624 0 ▶ if ( -e $arg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $arg) 0 0 0
625 0 ▶ if ( not defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
626 0 print "File `$arg' exists - will append\n";
627 }
628 }
629  
630 0 ▶ if ( open( my $fh, '>>', $arg ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, '>>', $arg) { } 0 0 0
631 0 close $fh;
632 0 $ENV{PERLSHELL_SESSION} = $arg;
633 0 ▶ if ( not defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
634 0 print $ENV{PERLSHELL_SESSION} . "\n";
635 }
636 0 return $ENV{PERLSHELL_SESSION};
637 } else {
638 0 ▶ if ( not defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
639 0 print "Cannot open file `$arg' for writing\n";
640 }
641 0 return undef;
642 }
643 } else {
644 0 ▶ if ( not defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
645 0 print "Session file already open - `$ENV{PERLSHELL_SESSION}'\n";
646 }
647 0 return;
648 }
649 }
650  
651 0 ▶sub variables {
Subroutine variables: not called CC=14 SCAR=51.7
Pod documented
652  
653 0 my %SKIP = (
654 '$VERSION' => 1,
655 '@ISA' => 1,
656 '@EXPORT' => 1
657 );
658  
659 0 ▶ if ( !exists $ENV{PERLSHELL_PACKAGE} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $ENV{"PERLSHELL_PACKAGE"}) 0 0 0
660 0 print "In -lexical mode, try again on line by iteslf\n";
661 0 return;
662 }
663  
664 0 ▶ if ( defined $ENV{PERLSHELL_SKIPVARS} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"PERLSHELL_SKIPVARS"}) 0 0 0
665 0 for ( split /;/, $ENV{PERLSHELL_SKIPVARS} ) {
666 0 $SKIP{"$_"} = 1;
667 }
668 }
669  
670 0 my @rets;
671 0 my $retType = wantarray;
672  
673 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
674 0 for my $var ( sort( keys( %{$ENV{PERLSHELL_PACKAGE} . '::'} ) ) ) {
675 0 ▶ if ( defined( ${$ENV{PERLSHELL_PACKAGE} . "::$var"} )
Branch: 3 branches
BranchTrueFalseTotal
if (defined ${$ENV{'PERLSHELL_PACKAGE'} . "::$var";} and not defined $SKIP{'$' . $var}) { } 0 0 0
elsif (@{$ENV{'PERLSHELL_PACKAGE'} . "::$var";} and not defined $SKIP{'@' . $var}) { } 0 0 0
elsif (%{$ENV{'PERLSHELL_PACKAGE'} . "::$var";} and not defined $SKIP{'%' . $var}) { } 0 0 0
Condition0%0/3
defined ${$ENV{"PERLSHELL_PACKAGE"} . "::$var";} and not defined $SKIP{'$' . $var}
!ll&&!rl&&r
000
MC/DC0%0/2
defined ${$ENV{"PERLSHELL_PACKAGE"} . "::$var";} and not defined $SKIP{'$' . $var}
defined ${$ENV{"PERLSHELL_PACKAGE"} . "::$var";} not defined $SKIP{'$' . $var}
Truth table0%0/3
A and not(B)
A= defined ${$ENV{"PERLSHELL_PACKAGE"} . "::$var";}B= not defined $SKIP{'$' . $var}
ABresult
0X0
100
111
676 and not defined( $SKIP{'$' . $var} ) ) {
677 0 push @rets, "\$$var";
678 0 ▶ } elsif ( @{$ENV{PERLSHELL_PACKAGE} . "::$var"}
Condition0%0/3
@{$ENV{"PERLSHELL_PACKAGE"} . "::$var";} and not defined $SKIP{'@' . $var}
!ll&&!rl&&r
000
MC/DC0%0/2
@{$ENV{"PERLSHELL_PACKAGE"} . "::$var";} and not defined $SKIP{'@' . $var}
@{$ENV{"PERLSHELL_PACKAGE"} . "::$var";} not defined $SKIP{'@' . $var}
Truth table0%0/3
A and not(B)
A= @{$ENV{"PERLSHELL_PACKAGE"} . "::$var";}B= not defined $SKIP{'@' . $var}
ABresult
0X0
100
111
679 and not defined( $SKIP{'@' . $var} ) ) {
680 0 push @rets, "\@$var";
681 0 ▶ } elsif ( %{$ENV{PERLSHELL_PACKAGE} . "::$var"}
Condition0%0/3
%{$ENV{"PERLSHELL_PACKAGE"} . "::$var";} and not defined $SKIP{'%' . $var}
!ll&&!rl&&r
000
MC/DC0%0/2
%{$ENV{"PERLSHELL_PACKAGE"} . "::$var";} and not defined $SKIP{'%' . $var}
%{$ENV{"PERLSHELL_PACKAGE"} . "::$var";} not defined $SKIP{'%' . $var}
Truth table0%0/3
A and not(B)
A= %{$ENV{"PERLSHELL_PACKAGE"} . "::$var";}B= not defined $SKIP{'%' . $var}
ABresult
0X0
100
111
682 and not defined( $SKIP{'%' . $var} ) ) {
683 0 push @rets, "\%$var";
684 }
685 }
686  
687 0 ▶ if ( not defined $retType ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $retType) { } 0 0 0
elsif ($retType) { } 0 0 0
688 0 for (@rets) {
689 0 print "$_\n";
690 }
691 } elsif ($retType) {
692 0 return @rets;
693 } else {
694 0 return \@rets;
695 }
696 }
697  
698 0 ▶sub version {
Subroutine version: not called CC=1 SCAR=6.9
Pod documented
699 0 print Cwd::abs_path($0) . "\n" .
700 "Perl = $]\n" .
701 "App::PerlShell = $VERSION\n";
702 }
703  
704 2 1;
705  
706 __END__
↑ Summary lib/App/PerlShell/Plugin/File.pm »