PDL-Perldl2

 view release on metacpan or  search on metacpan

lib/PDL/Perldl2/Plugin/PrintControl.pm  view on Meta::CPAN

package PDL::Perldl2::Plugin::PrintControl;

use strict;
use warnings;
use Devel::REPL::Plugin;

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

has 'print_by_default' => (
             is  => 'rw',
             default => 0,
         );

around 'format_result' => sub {

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

  return $self->print_by_default ? $orig->($self, @_) : ();

};

# convenience method to set/toggle print default settings
# sets like accessor if given a value, otherwise toggles status
sub do_print {
   my ($repl, $value) = @_;
   $value = (defined $value) ? $value : ! $repl->print_by_default;
   return $repl->print_by_default($value);
}

1;

__END__

=head1 NAME

PDL::Perldl2::Plugin::PrintControl - disable default print output

=head1 SYNOPSIS

  pdl> $x = 3;
  3
  pdl> $_REPL->load_plugin('PDL::Perldl2::Plugin::PrintControl');

  pdl> $x;

  pdl> $_REPL->print_by_default(1);
  1
  pdl> $x;
  3

=head1 DESCRIPTION

By default the Devel::REPL always prints the results of its
evaluation.  This is fine for small objects but for things
like large data objects (e.g. a 100x100 matrix in PDL) the
result can be hundreds of lines of output for each command.

This plugin disables the default print output and adds an
attribute with accessor method C<print_by_default> which can be
used to toggle the print default on or off.

=head1 METHODS

=head2 print_by_default



( run in 0.384 second using v1.01-cache-2.11-cpan-71847e10f99 )