script/plsh.pl untested

filter: Statementstmt 0.0% 0 / 74 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 125 CC 3 SCAR 17.5
CC
3
Cov
0%
parse_plshrc
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 5.8
1 #!/usr/local/bin/perl
2  
3 use strict;
4 use warnings;
5 use Getopt::Long qw(:config no_ignore_case);
6 use Pod::Usage;
7  
8 use App::PerlShell;
9  
10 #use Text::ParseWords; # quotewords()
11  
12 my %opt;
13  
14 GetOptions(
15  
16 # '' => \$opt{interact}, # lonesome dash is interactive test from STDIN
17 'e|execute=s@' => \$opt{execute},
18 'E|exit!' => \$opt{exit},
19 'feature=s' => \$opt{feature},
20 'Include=s@' => \$opt{include},
21 'lexical!' => \$opt{lexical},
22 'P|package=s' => \$opt{package},
23 'p|prompt=s' => \$opt{prompt},
24 'session=s' => \$opt{session},
25 'V|verbose!' => \$opt{verbose},
26 # 'words!' => \$opt{words},
27 'help!' => \$opt{help},
28 'man!' => \$opt{man},
29 'versions!' => \$opt{versions}
30 ) or pod2usage( -verbose => 0 );
31  
32 pod2usage( -verbose => 1 ) if defined $opt{help};
33 pod2usage( -verbose => 2 ) if defined $opt{man};
34  
35 if ( defined $opt{versions} ) {
36 print
37 "\nModules, Perl, OS, Program info:\n",
38 " $0\n",
39 " Version $App::PerlShell::VERSION\n",
40 " strict $strict::VERSION\n",
41 " warnings $warnings::VERSION\n",
42 " Getopt::Long $Getopt::Long::VERSION\n",
43 " Pod::Usage $Pod::Usage::VERSION\n",
44 ##################################################
45 # Start Additional USE
46 ##################################################
47 # " Text::ParseWords $Text::ParseWords::VERSION\n",
48 ##################################################
49 # End Additional USE
50 ##################################################
51 " Perl version $]\n",
52 " Perl executable $^X\n",
53 " OS $^O\n",
54 "\n\n";
55 exit;
56 }
57  
58 my %params;
59 if ( defined $opt{include} ) {
60 my @temp;
61 for ( @{$opt{include}} ) {
62 push @temp, $_;
63 }
64 unshift @INC, @temp;
65 }
66  
67 # Must be here to `use package` BEFORE any -e args
68 if ( defined $opt{package} ) {
69 $params{package} = $opt{package};
70 $params{execute} = "use $params{package};\n";
71 }
72  
73 my $homedir = $ENV{HOME};
74 if ( $^O eq 'MSWin32' ) {
75 $homedir = $ENV{USERPROFILE};
76 }
77  
78 sub parse_plshrc {
79 my ($file) = @_;
80  
81 if ( -e "$file" ) {
82 open my $fh, '<', "$file"
83 or die "$0: cannot open `$file': $!";
84 my @lines = <$fh>;
85 close $fh;
86 for (@lines) {
87 chomp $_;
88 $params{execute} .= $_;
89 if ( $params{execute} !~ /;$/ ) {
90 $params{execute} .= ';';
91 }
92 $params{execute} .= "\n";
93 }
94 }
95 }
96  
97 parse_plshrc("$homedir/.plshrc");
98 parse_plshrc(".plshrc");
99  
100 if ( defined $opt{execute} ) {
101 for ( @{$opt{execute}} ) {
102 $params{execute} .= $_;
103 if ( $params{execute} !~ /;$/ ) {
104 $params{execute} .= ';';
105 }
106 $params{execute} .= "\n";
107 }
108 }
109  
110 if ( defined $opt{prompt} ) {
111 $params{prompt} = $opt{prompt};
112 $params{execute} .= "\$ENV{PERLSHELL_PROMPT}='$opt{prompt}';\n";
113 }
114  
115 # Must be here again to add to end of execute to override .plshrc setting
116 # of package with the command line -P if specified
117 if ( defined $opt{package} ) {
118 $params{execute} .= "\$ENV{PERLSHELL_PACKAGE}='$opt{package}';\n";
119 }
120  
121 if ( defined $opt{feature} ) {
122 $opt{feature} =~ s/^[v]//;
123 if ( $opt{feature} =~ /^\d\./ ) {
124 $opt{feature} = ":" . $opt{feature};
125 }
126  
127 # append direct set to end of execute to override .plshrc setting of
128 # feature with the command line -f if specified
129 $params{execute} .= "\$ENV{PERLSHELL_FEATURE}='$opt{feature}';\n";
130 } else {
131 $opt{feature} = ":default";
132 }
133 $params{feature} = $opt{feature};
134  
135 $params{execute} .= 'exit;' if defined $opt{exit};
136 $params{lexical} = 1 if defined $opt{lexical};
137 $params{session} = $opt{session} if defined $opt{session};
138 $params{verbose} = $opt{verbose} if defined $opt{verbose};
139  
140 # if ( defined $opt{interact} ) {
141 # my @temp;
142 # if ( defined $opt{words} ) {
143 # while (<STDIN>) {
144 # chomp $_;
145 # my @p = parse_line( '\s+', 0, $_ );
146 # push @temp, @p;
147 # }
148 # if ( !defined $temp[$#temp] ) {
149 # pop @temp;
150 # }
151 # } else {
152 # while (<STDIN>) {
153 # chomp $_;
154 # push @temp, $_;
155 # }
156 # }
157 # $params{argv} = \@temp;
158 # }
159  
160 my $shell = App::PerlShell->new( %params,
161 skipvars => [qw(%LexPersist:: %ModRefresh:: %Plugin:: $AUTOLOAD)] );
162 $shell->run();
163  
164 __END__