line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::PerlShell; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
######################################################## |
4
|
|
|
|
|
|
|
# AUTHOR = Michael Vincent |
5
|
|
|
|
|
|
|
# www.VinsWorld.com |
6
|
|
|
|
|
|
|
######################################################## |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
59114
|
use strict; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
25
|
|
9
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
10
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
74
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = "1.09"; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
6
|
use Cwd; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
59
|
|
15
|
1
|
|
|
1
|
|
489
|
use Term::ReadLine; |
|
1
|
|
|
|
|
2377
|
|
|
1
|
|
|
|
|
27
|
|
16
|
1
|
|
|
1
|
|
547
|
use Data::Dumper; |
|
1
|
|
|
|
|
6044
|
|
|
1
|
|
|
|
|
116
|
|
17
|
|
|
|
|
|
|
$Data::Dumper::Sortkeys = 1; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $HAVE_LexPersist = 0; |
20
|
1
|
|
|
1
|
|
133
|
eval "use Lexical::Persistence 1.01 ()"; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
21
|
|
|
|
|
|
|
if ( !$@ ) { |
22
|
|
|
|
|
|
|
eval "use App::PerlShell::LexPersist"; |
23
|
|
|
|
|
|
|
$HAVE_LexPersist = 1; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
my $HAVE_ModRefresh = 0; |
26
|
1
|
|
|
1
|
|
134
|
eval "use Module::Refresh"; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
if ( !$@ ) { |
28
|
|
|
|
|
|
|
eval "use App::PerlShell::ModRefresh"; |
29
|
|
|
|
|
|
|
$HAVE_ModRefresh = 1; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my %COMMANDS_INTERNAL = ( |
33
|
|
|
|
|
|
|
debug => 'print command', |
34
|
|
|
|
|
|
|
exit => 'exit shell' |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
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
|
1
|
|
|
1
|
|
7
|
use Exporter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
741
|
|
56
|
|
|
|
|
|
|
our @EXPORT = sort ( keys ( %COMMANDS ) ); |
57
|
|
|
|
|
|
|
our @ISA = qw ( Exporter ); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _shellCommands { |
60
|
0
|
|
|
0
|
|
|
return ( %COMMANDS, %COMMANDS_INTERNAL ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub new { |
64
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
65
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Default parameters |
68
|
|
|
|
|
|
|
my %params = ( |
69
|
|
|
|
|
|
|
homedir => ( $^O eq "MSWin32" ) ? $ENV{USERPROFILE} : $ENV{HOME}, |
70
|
0
|
0
|
|
|
|
|
package => __PACKAGE__, |
71
|
|
|
|
|
|
|
prompt => 'Perl> ' |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $lex = 0; |
75
|
0
|
|
|
|
|
|
my $verbose = 0; |
76
|
0
|
0
|
|
|
|
|
if ( @_ == 1 ) { |
77
|
0
|
|
|
|
|
|
croak("Insufficient number of args - @_"); |
78
|
|
|
|
|
|
|
} else { |
79
|
0
|
|
|
|
|
|
my %cfg = @_; |
80
|
0
|
|
|
|
|
|
for ( keys(%cfg) ) { |
81
|
0
|
0
|
|
|
|
|
if (/^-?homedir$/i) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
if ( -d $cfg{$_} ) { |
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
|
0
|
|
|
|
|
if ( ref $cfg{$_} eq 'ARRAY' ) { |
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
|
0
|
|
|
|
|
if ($lex) { |
115
|
0
|
0
|
|
|
|
|
if ($HAVE_LexPersist) { |
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
|
0
|
|
|
|
|
if ( defined $params{skipvars} ) { |
133
|
0
|
|
|
|
|
|
$ENV{PERLSHELL_SKIPVARS} = join ';', @{$params{skipvars}}; |
|
0
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
0
|
0
|
|
|
|
|
if ( $verbose ) { |
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
|
|
|
|
|
|
|
sub run { |
150
|
0
|
|
|
0
|
1
|
|
my $App_PerlShell_Shell = shift; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# handle session if requested |
153
|
0
|
0
|
|
|
|
|
if ( defined $App_PerlShell_Shell->{session} ) { |
154
|
0
|
0
|
|
|
|
|
if ( not defined session( $App_PerlShell_Shell->{session} ) ) { |
155
|
0
|
|
|
|
|
|
croak( |
156
|
|
|
|
|
|
|
"Cannot open session file `$App_PerlShell_Shell->{session}'"); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
0
|
0
|
|
|
|
|
if ( exists $App_PerlShell_Shell->{shellLexEnv} ) { |
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
|
1
|
|
|
1
|
|
7
|
no strict 'vars'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1226
|
|
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
|
0
|
|
|
|
|
if ( defined $App_PerlShell_Shell->{execute} ) { |
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
|
0
|
|
|
|
|
); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
chomp $App_PerlShell_Shell->{shellCmdLine}; |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
# nothing |
199
|
0
|
0
|
|
|
|
|
if ( $App_PerlShell_Shell->{shellCmdLine} =~ /^\s*$/ ) { |
200
|
0
|
|
|
|
|
|
undef $App_PerlShell_Shell->{shellCmdLine}; |
201
|
0
|
|
|
|
|
|
next; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# exit |
205
|
0
|
0
|
|
|
|
|
if ( $App_PerlShell_Shell->{shellCmdLine} =~ /^\s*exit\s*(;)?\s*$/ ) { |
206
|
0
|
0
|
|
|
|
|
if ( not defined $1 ) { |
207
|
0
|
|
|
|
|
|
$App_PerlShell_Shell->{shellCmdLine} .= ';'; |
208
|
|
|
|
|
|
|
} |
209
|
0
|
|
|
|
|
|
last; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
# debug multiline |
213
|
0
|
0
|
|
|
|
|
if ( $App_PerlShell_Shell->{shellCmdLine} =~ /\ndebug$/ ) { |
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
|
0
|
|
|
|
|
if ( exists $App_PerlShell_Shell->{shellLexEnv} ) { |
221
|
0
|
0
|
|
|
|
|
if ( $App_PerlShell_Shell->{shellCmdLine} |
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}} = ( |
|
0
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
'parenthesis' => 0, |
240
|
|
|
|
|
|
|
'bracket' => 0, |
241
|
|
|
|
|
|
|
'brace' => 0 |
242
|
|
|
|
|
|
|
); |
243
|
0
|
0
|
|
|
|
|
if ( my @c = ( $App_PerlShell_Shell->{shellCmdLine} =~ /\(/g ) ) { |
244
|
|
|
|
|
|
|
$App_PerlShell_Shell->{shellCmdComplete}->{parenthesis} |
245
|
0
|
|
|
|
|
|
+= scalar(@c); |
246
|
|
|
|
|
|
|
} |
247
|
0
|
0
|
|
|
|
|
if ( my @c = ( $App_PerlShell_Shell->{shellCmdLine} =~ /\)/g ) ) { |
248
|
|
|
|
|
|
|
$App_PerlShell_Shell->{shellCmdComplete}->{parenthesis} |
249
|
0
|
|
|
|
|
|
-= scalar(@c); |
250
|
|
|
|
|
|
|
} |
251
|
0
|
0
|
|
|
|
|
if ( my @c = ( $App_PerlShell_Shell->{shellCmdLine} =~ /\[/g ) ) { |
252
|
0
|
|
|
|
|
|
$App_PerlShell_Shell->{shellCmdComplete}->{bracket} += scalar(@c); |
253
|
|
|
|
|
|
|
} |
254
|
0
|
0
|
|
|
|
|
if ( my @c = ( $App_PerlShell_Shell->{shellCmdLine} =~ /\]/g ) ) { |
255
|
0
|
|
|
|
|
|
$App_PerlShell_Shell->{shellCmdComplete}->{bracket} -= scalar(@c); |
256
|
|
|
|
|
|
|
} |
257
|
0
|
0
|
|
|
|
|
if ( my @c = ( $App_PerlShell_Shell->{shellCmdLine} =~ /\{/g ) ) { |
258
|
0
|
|
|
|
|
|
$App_PerlShell_Shell->{shellCmdComplete}->{brace} += scalar(@c); |
259
|
|
|
|
|
|
|
} |
260
|
0
|
0
|
|
|
|
|
if ( my @c = ( $App_PerlShell_Shell->{shellCmdLine} =~ /\}/g ) ) { |
261
|
0
|
|
|
|
|
|
$App_PerlShell_Shell->{shellCmdComplete}->{brace} -= scalar(@c); |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
0
|
0
|
0
|
|
|
|
if ( ( $App_PerlShell_Shell->{shellCmdLine} =~ /,\s*$/ ) |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
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
|
0
|
|
|
|
|
if ( $App_PerlShell_Shell->{shellCmdLine} !~ /\n;$/ ) { |
270
|
0
|
|
|
|
|
|
$App_PerlShell_Shell->{shellCmdLine} .= "\n"; |
271
|
0
|
|
|
|
|
|
next; |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
# if all groupings are closed |
276
|
0
|
0
|
0
|
|
|
|
if ( ( $App_PerlShell_Shell->{shellCmdComplete}->{parenthesis} == 0 ) |
|
|
|
0
|
|
|
|
|
277
|
|
|
|
|
|
|
and ( $App_PerlShell_Shell->{shellCmdComplete}->{bracket} == 0 ) |
278
|
|
|
|
|
|
|
and ( $App_PerlShell_Shell->{shellCmdComplete}->{brace} == 0 ) |
279
|
|
|
|
|
|
|
) { |
280
|
|
|
|
|
|
|
# valid endings are ; or } |
281
|
0
|
0
|
|
|
|
|
if ( $App_PerlShell_Shell->{shellCmdLine} !~ /(;|\})\s*$/ ) { |
282
|
|
|
|
|
|
|
# unless PERLSHELL_SEMIOFF, we can add it and continue |
283
|
0
|
0
|
|
|
|
|
if ( $ENV{PERLSHELL_SEMIOFF} ) { |
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
|
0
|
|
|
|
|
if ( exists $App_PerlShell_Shell->{shellLexEnv} ) { |
296
|
0
|
0
|
|
|
|
|
if ( $App_PerlShell_Shell->{shellLexEnv}->get_package() ne |
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
|
0
|
|
|
|
|
if ($HAVE_ModRefresh) { |
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
|
0
|
|
|
|
|
if ( $ENV{PERLSHELL_PACKAGE} ne __PACKAGE__ ) { |
317
|
0
|
|
|
|
|
|
my $sp = $ENV{PERLSHELL_PACKAGE}; |
318
|
0
|
|
|
|
|
|
my $p = __PACKAGE__; |
319
|
0
|
|
|
|
|
|
eval "package $sp; $p->import;"; |
320
|
0
|
0
|
|
|
|
|
if ($HAVE_ModRefresh) { |
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
|
0
|
|
|
|
|
warn $@ if ($@); |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
# logging if requested and no error |
338
|
0
|
0
|
0
|
|
|
|
if ( defined( $ENV{PERLSHELL_SESSION} ) and !$@ ) { |
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
|
0
|
|
|
|
|
if ( $App_PerlShell_Shell->{shellCmdLine} ne '' ); |
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
|
|
|
|
|
|
|
sub cd { |
369
|
0
|
|
|
0
|
1
|
|
my ($arg) = @_; |
370
|
|
|
|
|
|
|
|
371
|
0
|
|
|
|
|
|
my $ret = getcwd; |
372
|
0
|
0
|
|
|
|
|
if ( not defined $arg ) { |
373
|
0
|
|
|
|
|
|
chdir $ENV{PERLSHELL_HOME}; |
374
|
|
|
|
|
|
|
} else { |
375
|
0
|
0
|
|
|
|
|
if ( -e $arg ) { |
376
|
0
|
|
|
|
|
|
chdir $arg; |
377
|
|
|
|
|
|
|
} else { |
378
|
0
|
|
|
|
|
|
print "Cannot find directory `$arg'\n"; |
379
|
|
|
|
|
|
|
} |
380
|
|
|
|
|
|
|
} |
381
|
0
|
0
|
|
|
|
|
if ( defined wantarray ) { |
382
|
0
|
|
|
|
|
|
return $ret; |
383
|
|
|
|
|
|
|
} |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
sub cls { |
387
|
0
|
|
|
0
|
1
|
|
return clear(); |
388
|
|
|
|
|
|
|
} |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
sub clear { |
391
|
0
|
0
|
|
0
|
1
|
|
if ( $^O eq "MSWin32" ) { |
392
|
0
|
|
|
|
|
|
system('cls'); |
393
|
|
|
|
|
|
|
} else { |
394
|
0
|
|
|
|
|
|
system('clear'); |
395
|
|
|
|
|
|
|
} |
396
|
|
|
|
|
|
|
} |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
sub commands { |
399
|
0
|
|
|
0
|
1
|
|
my ($arg) = @_; |
400
|
|
|
|
|
|
|
|
401
|
0
|
|
|
|
|
|
my @rets; |
402
|
0
|
|
|
|
|
|
my $retType = wantarray; |
403
|
|
|
|
|
|
|
|
404
|
0
|
|
|
|
|
|
my $stash = $ENV{PERLSHELL_PACKAGE} . '::'; |
405
|
|
|
|
|
|
|
|
406
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
222
|
|
407
|
|
|
|
|
|
|
|
408
|
0
|
|
|
|
|
|
my $regex = qr/^.*$/; |
409
|
0
|
0
|
|
|
|
|
if ( defined($arg) ) { |
410
|
0
|
|
|
|
|
|
$regex = qr/$arg/; |
411
|
|
|
|
|
|
|
} |
412
|
|
|
|
|
|
|
|
413
|
0
|
|
|
|
|
|
for my $name ( sort( keys( %{$stash} ) ) ) { |
|
0
|
|
|
|
|
|
|
414
|
0
|
0
|
|
|
|
|
next if ( $name =~ /^_/ ); |
415
|
|
|
|
|
|
|
|
416
|
0
|
|
|
|
|
|
my $sub = *{"${stash}${name}"}{CODE}; |
|
0
|
|
|
|
|
|
|
417
|
0
|
0
|
|
|
|
|
next unless defined $sub; |
418
|
|
|
|
|
|
|
|
419
|
0
|
|
|
|
|
|
my $proto = prototype($sub); |
420
|
0
|
0
|
0
|
|
|
|
next if defined $proto and length($proto) == 0; |
421
|
|
|
|
|
|
|
|
422
|
0
|
0
|
|
|
|
|
if ( $name =~ /$regex/ ) { |
423
|
0
|
|
|
|
|
|
push @rets, $name; |
424
|
|
|
|
|
|
|
} |
425
|
|
|
|
|
|
|
} |
426
|
|
|
|
|
|
|
|
427
|
0
|
0
|
|
|
|
|
if ( not defined $retType ) { |
|
|
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
|
|
|
|
|
|
|
sub dumper { |
439
|
0
|
|
|
0
|
1
|
|
my (@dump) = @_; |
440
|
|
|
|
|
|
|
|
441
|
1
|
|
|
1
|
|
10
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1231
|
|
442
|
0
|
|
|
|
|
|
$Data::Dumper::Sortkeys = 1; |
443
|
0
|
|
|
|
|
|
print Dumper @dump; |
444
|
|
|
|
|
|
|
} |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
sub env { |
447
|
0
|
|
|
0
|
1
|
|
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
|
0
|
|
|
|
|
if ( defined $arg ) { |
455
|
0
|
0
|
|
|
|
|
if ( $env =~ /$arg/ ) { |
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
|
0
|
|
|
|
|
if ( !$FOUND ) { |
466
|
0
|
0
|
|
|
|
|
printf "Environment variable(s) not found%s", |
467
|
|
|
|
|
|
|
( defined $arg ) ? " - `$arg'\n" : "\n"; |
468
|
|
|
|
|
|
|
} |
469
|
|
|
|
|
|
|
|
470
|
0
|
0
|
|
|
|
|
if ( not defined $retType ) { |
|
|
0
|
|
|
|
|
|
471
|
0
|
|
|
|
|
|
for my $env ( sort( keys(%rets) ) ) { |
472
|
|
|
|
|
|
|
printf "$env=%s\n", |
473
|
0
|
0
|
|
|
|
|
( defined $rets{$env} ) ? $rets{$env} : ""; |
474
|
|
|
|
|
|
|
} |
475
|
|
|
|
|
|
|
} elsif ($retType) { |
476
|
0
|
|
|
|
|
|
return %rets; |
477
|
|
|
|
|
|
|
} else { |
478
|
0
|
|
|
|
|
|
return \%rets; |
479
|
|
|
|
|
|
|
} |
480
|
|
|
|
|
|
|
} |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
sub help { |
483
|
0
|
|
|
0
|
1
|
|
my %cmds = _shellCommands(); |
484
|
0
|
|
|
|
|
|
for my $h ( sort( keys(%cmds) ) ) { |
485
|
0
|
|
|
|
|
|
printf "%-15s %s\n", $h, $cmds{$h}; |
486
|
|
|
|
|
|
|
} |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
sub dir { |
490
|
0
|
|
|
0
|
1
|
|
return ls(@_); |
491
|
|
|
|
|
|
|
} |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
sub ls { |
494
|
0
|
|
|
0
|
1
|
|
my (@args) = @_; |
495
|
|
|
|
|
|
|
|
496
|
0
|
|
|
|
|
|
my $dircmd = 'ls'; |
497
|
0
|
0
|
|
|
|
|
if ( $^O eq "MSWin32" ) { |
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
|
0
|
|
|
|
|
if ( not defined $retType ) { |
511
|
0
|
|
|
|
|
|
system( $dircmd, @args ); |
512
|
|
|
|
|
|
|
} else { |
513
|
0
|
|
|
|
|
|
@ret = `$dircmd @args`; |
514
|
0
|
0
|
|
|
|
|
if ($retType) { |
515
|
0
|
|
|
|
|
|
return @ret; |
516
|
|
|
|
|
|
|
} else { |
517
|
0
|
|
|
|
|
|
return \@ret; |
518
|
|
|
|
|
|
|
} |
519
|
|
|
|
|
|
|
} |
520
|
|
|
|
|
|
|
} |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
sub modules { |
523
|
0
|
|
|
0
|
1
|
|
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
|
0
|
|
|
|
|
if ( defined $arg ) { |
535
|
0
|
0
|
|
|
|
|
if ( $module =~ /$arg/ ) { |
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
|
0
|
|
|
|
|
if ( !$FOUND ) { |
546
|
0
|
0
|
|
|
|
|
printf "Module(s) not found%s", |
547
|
|
|
|
|
|
|
( defined $arg ) ? " - `$arg'\n" : "\n"; |
548
|
|
|
|
|
|
|
} |
549
|
|
|
|
|
|
|
|
550
|
0
|
0
|
|
|
|
|
if ( not defined $retType ) { |
|
|
0
|
|
|
|
|
|
551
|
0
|
|
|
|
|
|
for my $module ( sort( keys(%rets) ) ) { |
552
|
|
|
|
|
|
|
printf "$module %s\n", |
553
|
0
|
0
|
|
|
|
|
( defined $rets{$module} ) ? $rets{$module} : "[NOT LOADED]"; |
554
|
|
|
|
|
|
|
} |
555
|
|
|
|
|
|
|
} elsif ($retType) { |
556
|
0
|
|
|
|
|
|
return %rets; |
557
|
|
|
|
|
|
|
} else { |
558
|
0
|
|
|
|
|
|
return \%rets; |
559
|
|
|
|
|
|
|
} |
560
|
|
|
|
|
|
|
} |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
sub perldoc { |
563
|
0
|
|
|
0
|
1
|
|
my (@args) = @_; |
564
|
|
|
|
|
|
|
|
565
|
0
|
0
|
|
|
|
|
if ( $#args == -1 ) { |
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
|
0
|
|
|
|
|
if ( $args[0] =~ /^::/ ) { |
577
|
0
|
|
|
|
|
|
$args[0] = $ENV{PERLSHELL_PACKAGE} . $args[0]; |
578
|
|
|
|
|
|
|
} |
579
|
|
|
|
|
|
|
|
580
|
0
|
|
|
|
|
|
system( $ENV{PERLSHELL_PERLDOC}, @args ); |
581
|
|
|
|
|
|
|
} |
582
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
sub pwd { |
584
|
0
|
0
|
|
0
|
1
|
|
if ( not defined wantarray ) { |
585
|
0
|
|
|
|
|
|
print getcwd; |
586
|
|
|
|
|
|
|
} else { |
587
|
0
|
|
|
|
|
|
return getcwd; |
588
|
|
|
|
|
|
|
} |
589
|
|
|
|
|
|
|
} |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
sub session { |
592
|
0
|
|
|
0
|
1
|
|
my ($arg) = @_; |
593
|
|
|
|
|
|
|
|
594
|
0
|
0
|
|
|
|
|
if ( not defined $arg ) { |
595
|
0
|
0
|
|
|
|
|
if ( defined $ENV{PERLSHELL_SESSION} ) { |
596
|
0
|
0
|
|
|
|
|
if ( not defined wantarray ) { |
597
|
0
|
|
|
|
|
|
print $ENV{PERLSHELL_SESSION} . "\n"; |
598
|
|
|
|
|
|
|
} |
599
|
0
|
|
|
|
|
|
return $ENV{PERLSHELL_SESSION}; |
600
|
|
|
|
|
|
|
} else { |
601
|
0
|
0
|
|
|
|
|
if ( not defined wantarray ) { |
602
|
0
|
|
|
|
|
|
print "No current session file\n"; |
603
|
|
|
|
|
|
|
} |
604
|
0
|
|
|
|
|
|
return undef; |
605
|
|
|
|
|
|
|
} |
606
|
|
|
|
|
|
|
} |
607
|
|
|
|
|
|
|
|
608
|
0
|
0
|
|
|
|
|
if ( $arg eq ":close" ) { |
609
|
0
|
0
|
|
|
|
|
if ( defined $ENV{PERLSHELL_SESSION} ) { |
610
|
0
|
0
|
|
|
|
|
if ( not defined wantarray ) { |
611
|
0
|
|
|
|
|
|
print "$ENV{PERLSHELL_SESSION} closed\n"; |
612
|
|
|
|
|
|
|
} |
613
|
0
|
|
|
|
|
|
$ENV{PERLSHELL_SESSION} = undef; |
614
|
0
|
|
|
|
|
|
return; |
615
|
|
|
|
|
|
|
} else { |
616
|
0
|
0
|
|
|
|
|
if ( not defined wantarray ) { |
617
|
0
|
|
|
|
|
|
print "No current session file\n"; |
618
|
|
|
|
|
|
|
} |
619
|
0
|
|
|
|
|
|
return undef; |
620
|
|
|
|
|
|
|
} |
621
|
|
|
|
|
|
|
} |
622
|
|
|
|
|
|
|
|
623
|
0
|
0
|
|
|
|
|
if ( not defined $ENV{PERLSHELL_SESSION} ) { |
624
|
0
|
0
|
|
|
|
|
if ( -e $arg ) { |
625
|
0
|
0
|
|
|
|
|
if ( not defined wantarray ) { |
626
|
0
|
|
|
|
|
|
print "File `$arg' exists - will append\n"; |
627
|
|
|
|
|
|
|
} |
628
|
|
|
|
|
|
|
} |
629
|
|
|
|
|
|
|
|
630
|
0
|
0
|
|
|
|
|
if ( open( my $fh, '>>', $arg ) ) { |
631
|
0
|
|
|
|
|
|
close $fh; |
632
|
0
|
|
|
|
|
|
$ENV{PERLSHELL_SESSION} = $arg; |
633
|
0
|
0
|
|
|
|
|
if ( not defined wantarray ) { |
634
|
0
|
|
|
|
|
|
print $ENV{PERLSHELL_SESSION} . "\n"; |
635
|
|
|
|
|
|
|
} |
636
|
0
|
|
|
|
|
|
return $ENV{PERLSHELL_SESSION}; |
637
|
|
|
|
|
|
|
} else { |
638
|
0
|
0
|
|
|
|
|
if ( not defined wantarray ) { |
639
|
0
|
|
|
|
|
|
print "Cannot open file `$arg' for writing\n"; |
640
|
|
|
|
|
|
|
} |
641
|
0
|
|
|
|
|
|
return undef; |
642
|
|
|
|
|
|
|
} |
643
|
|
|
|
|
|
|
} else { |
644
|
0
|
0
|
|
|
|
|
if ( not defined wantarray ) { |
645
|
0
|
|
|
|
|
|
print "Session file already open - `$ENV{PERLSHELL_SESSION}'\n"; |
646
|
|
|
|
|
|
|
} |
647
|
0
|
|
|
|
|
|
return; |
648
|
|
|
|
|
|
|
} |
649
|
|
|
|
|
|
|
} |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
sub variables { |
652
|
|
|
|
|
|
|
|
653
|
0
|
|
|
0
|
1
|
|
my %SKIP = ( |
654
|
|
|
|
|
|
|
'$VERSION' => 1, |
655
|
|
|
|
|
|
|
'@ISA' => 1, |
656
|
|
|
|
|
|
|
'@EXPORT' => 1 |
657
|
|
|
|
|
|
|
); |
658
|
|
|
|
|
|
|
|
659
|
0
|
0
|
|
|
|
|
if ( !exists $ENV{PERLSHELL_PACKAGE} ) { |
660
|
0
|
|
|
|
|
|
print "In -lexical mode, try again on line by iteslf\n"; |
661
|
0
|
|
|
|
|
|
return; |
662
|
|
|
|
|
|
|
} |
663
|
|
|
|
|
|
|
|
664
|
0
|
0
|
|
|
|
|
if ( defined $ENV{PERLSHELL_SKIPVARS} ) { |
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
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
284
|
|
674
|
0
|
|
|
|
|
|
for my $var ( sort( keys( %{$ENV{PERLSHELL_PACKAGE} . '::'} ) ) ) { |
|
0
|
|
|
|
|
|
|
675
|
0
|
0
|
0
|
|
|
|
if ( defined( ${$ENV{PERLSHELL_PACKAGE} . "::$var"} ) |
|
0
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
676
|
|
|
|
|
|
|
and not defined( $SKIP{'$' . $var} ) ) { |
677
|
0
|
|
|
|
|
|
push @rets, "\$$var"; |
678
|
0
|
|
|
|
|
|
} elsif ( @{$ENV{PERLSHELL_PACKAGE} . "::$var"} |
679
|
|
|
|
|
|
|
and not defined( $SKIP{'@' . $var} ) ) { |
680
|
0
|
|
|
|
|
|
push @rets, "\@$var"; |
681
|
0
|
|
|
|
|
|
} elsif ( %{$ENV{PERLSHELL_PACKAGE} . "::$var"} |
682
|
|
|
|
|
|
|
and not defined( $SKIP{'%' . $var} ) ) { |
683
|
0
|
|
|
|
|
|
push @rets, "\%$var"; |
684
|
|
|
|
|
|
|
} |
685
|
|
|
|
|
|
|
} |
686
|
|
|
|
|
|
|
|
687
|
0
|
0
|
|
|
|
|
if ( not defined $retType ) { |
|
|
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
|
|
|
|
|
|
|
sub version { |
699
|
0
|
|
|
0
|
1
|
|
print Cwd::abs_path($0) . "\n" . |
700
|
|
|
|
|
|
|
"Perl = $]\n" . |
701
|
|
|
|
|
|
|
"App::PerlShell = $VERSION\n"; |
702
|
|
|
|
|
|
|
} |
703
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
1; |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
__END__ |