Added D:R:P:Packages,pm. For experimentation only!
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / Packages.pm
1 # First cut at handling packages.
2 #
3 # doesn't work very well, and totally doesn't work with the wrap_as_sub
4 # stuff ;) For comments only really
5
6 package Devel::REPL::Plugin::Packages;
7
8 use Moose::Role;
9
10 has 'current_package' => (
11   isa      => 'Str',
12   is       => 'rw',
13   default  => 'main',
14   lazy     => 1
15 );
16
17 around 'eval' => sub {
18 # we don't call forward to $orig here, since the new sub-wrapped system
19 # doesn't work. We spot package declarations and retain the name so
20 # that we can reenter the package for each statement. Not sure the
21 # regex is bob on, but then it doesn't work anyway...
22   my $orig=shift;
23   my ($self, $line)=@_;
24
25   my @ret=("OOPS: ".__PACKAGE__.'$ret unset!');
26
27 #  $self->print("Line is: $line");
28   if($line=~/\s*package\s([\w:]*)/) {
29 #    $self->print("Recognised as a package switch");
30 #    $ret=$self->$orig($line);
31     @ret=eval $line;
32 #    $self->print("ret: @ret");
33     # should check for good return here
34     $self->current_package($1);
35 #    $self->print('curr pkg: '.$self->current_package);
36   } else {
37 #    $self->print("Not a package switch");
38     my $packaged_line='package ' . $self->current_package . '; '.$line;
39 #    $self->print("packaged line: $packaged_line");
40 #    @ret=$self->$orig($packaged_line);
41     @ret=eval $packaged_line;
42 #    $self->print("ret: @ret");
43   }
44   return @ret;
45 };
46
47 1;
48