PDL::Perldl2::Plugin::NiceSlice - enable PDL NiceSlice syntax


PDL documentation Contained in the PDL distribution.

Index


Code Index:

NAME

Top

PDL::Perldl2::Plugin::NiceSlice - enable PDL NiceSlice syntax

DESCRIPTION

Top

This plugin enables one to use the PDL::NiceSlice syntax in an instance of Devel::REPL such as the new Perldl2 shell, pdl2. Without the plugin, array slicing looks like this:

  pdl> use PDL;

  pdl> $a = sequence(10);
  $PDL1 = [0 1 2 3 4 5 6 7 8 9];

  pdl> $a->slice("2:9:2");
  $PDL1 = [2 4 6 8];

After the NiceSlice plugin has been loaded, you can use this:

  pdl> $a(2:9:2)
  $PDL1 = [2 4 6 8];

CAVEATS

Top

PDL::NiceSlice uses Perl source preprocessing. If you need 100% pure Perl compatibility, use the slice method instead.

SEE ALSO

Top

PDL::NiceSlice, Devel::REPL, PDL::Perldl

AUTHOR

Top

Chris Marshall, <chm at cpan dot org>

COPYRIGHT AND LICENSE

Top


PDL documentation Contained in the PDL distribution.

package PDL::Perldl2::Plugin::NiceSlice;

use Devel::REPL::Plugin;

use namespace::clean -except => [ 'meta' ];

use PDL::Lite;
use PDL::NiceSlice;

my $preproc = sub {
   my ($txt) = @_;
   my $new = PDL::NiceSlice::perldlpp('main',$txt);
   return $new;
};

around 'compile' => sub {

  my ($orig, $self) = (shift, shift);
  my ($lines, @args) = @_;

  no PDL::NiceSlice;
  $lines = $preproc->($lines);

  $self->$orig($lines, @args);
};

1;

__END__