blib/lib/PDL/Perldl2/Plugin/PDLCommands.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 18 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 2 Podpod n/a totaltotal 0.0% 0 / 74 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package PDL::Perldl2::Plugin::PDLCommands;
2  
3 use Devel::REPL::Plugin;
4  
5 use namespace::clean -except => [ 'meta' ];
6  
7 # The atomic option---need to deconflict Turtle command injection
8 # using qr{\#} and perldl's usage for command escapes. Just
9 # exclude for now to get things working
10 excludes 'Turtles';
11  
12 around 'read' => sub {
13  
14 my $orig = shift;
15 my ($self, @args) = @_;
16  
17 # using $lines here because that is the usage from perldl
18 # and I want to cut and paste existing code if possible
19 my $lines = $self->$orig(@args);
20  
21 # Execute the list of auto-code (TODO)
22 ## for my $c (@PERLDL::AUTO) {
23 ## my $mess = eval_and_report($c);
24 ## warn $mess if $mess;
25 ## }
26  
27 # Filter out PDL shell prefixes from cut-n-pasted lines
28 if ( defined($lines) and $lines =~ s/$PERLDL::PREFIX_RE// ) {
29 if ($PERLDL::TERM->can('GetHistory') and $PERLDL::TERM->can('SetHistory')) {
30 my @hist = $PERLDL::TERM->GetHistory();
31 foreach my $entry (@hist) { $entry =~ s/$PERLDL::PREFIX_RE//; }
32 $PERLDL::TERM->SetHistory(@hist);
33 }
34 }
35  
36 return $lines unless defined $lines;
37  
38 # print STDERR "PDLCommands: got '$lines'\n";
39 if ( lc $lines eq 'q' || lc $lines eq 'x' || lc $lines eq 'exit' ) { return "quit"; };
40  
41 $lines =~ s/^\s*\?\?\s*/apropos /; # Make '??' = 'apropos'
42 $lines =~ s/^\s*\?\s*/help /; # Make lone '?' = 'help'
43  
44 if ( $lines =~ /^\s*(help|usage|apropos|sig|badinfo|demo)\s+/) { # Allow help foo (no quotes)
45 my @t = split(/\s+/,$lines);
46 my $a;
47 foreach $a(@t) { $a=~s/^["']+//; $a=~s/['"]+$//; };
48 $t[1] = "'".$t[1]."'" if ($#t == 1 && !($t[1] =~ /^\$/));
49 $lines = join(' ',@t);
50 }
51  
52 $PERLDL::ESCAPE = $PERLDL::ESCAPE if defined $PERLDL::ESCAPE;
53 if (substr($lines,0,1) eq substr($PERLDL::ESCAPE,0,1) and
54 substr($lines,0,2) ne '#!') { # Allow escapes, avoid shebang
55 my @lines = split /\n/, $lines;
56 system(substr(shift @lines,1)); # Shell escape
57 $lines = join("\n",@lines);
58 }
59  
60 return $lines;
61 };
62  
63 1;
64  
65 __END__