#!/usr/bin/env perl

BEGIN {
   $ENV{DEVEL_REPL_PROFILE} = 'PDLA::Perldl2::Profile::Perldl2';

   # This should be based on 
   $HOME = $ENV{HOME};             # Useful in shell
   if ($^O =~ /win32/i and
      (! defined($HOME)) or
      (defined($HOME) and $HOME eq "")) {
      $HOME = $ENV{USERPROFILE};
      $HOME =~ s/\\/\//g;
   }

   $ENV{PERLREPL_HISTFILE} = "$HOME/.perldl_hist";
   $ENV{PERLREPL_HISTLEN} = 500;
}

BEGIN {
   my $minversion = "1.003011";
   eval " use Devel::REPL $minversion ";
   if ($@) {
      my ($perldla) = $0;
      $perldla =~ s/pdla2\.bat$/perldla\.bat/;
      $perldla =~ s/pdla2$/perldla/;
      warn "pdla2: Devel::REPL version $minversion not found, running '$perldla' instead...\n";
      do $perldla;
      warn "pdla2: could not 'do $perldla'\n";
      $perldla =~ s{^[^/\\]*[/\\]}{};
      do $perldla;
      die "pdla2: could not 'do $perldla'\n";
   }
}

use PDLA::Perldl2::Script 'run';

__END__

=head1 NAME

pdla2 - Simple shell (version 2) for PDLA

=head1 SYNOPSIS

Use PDLA interactively:

  %> pdla2

  pdla> $a = sequence(10)  # or any other perl or PDLA command
  
  pdla> print "\$a = $a\n"; 
  $a = [0 1 2 3 4 5 6 7 8 9]

=head1 DESCRIPTION

The C<pdla2> program, also known as the Perldl2 shell, is a second
generation version of the original C<perldla> interactive PDLA shell.
It attempts to be backward compatible in usage while providing
improved features, better support for Perl syntax, and an more
easily extended framework based on the L<Devel::REPL|Devel::REPL> shell.

If you have L<Devel::REPL|Devel::REPL> version 1.003011 or later, then C<pdla2>
will start with full functionality.  If L<Devel::REPL|Devel::REPL> is not
installed or found then C<pdla2> will print a warning and run
the legacy C<perldla> shell command instead.

By default, command lines beginning with the default prompt
of either C<pdla2> or C<perldla> (one of 'pdla> ', 'PDLA> ', or
'perldla> ') will have the prefix string and surrounding
whitespace stripped.  This allows for easy cut-and-paste
from sample PDLA shell sessions or other examples into another
PDLA shell session.

=head1 FUNCTIONS

=head2 do_print

=for ref

Toggle print-by-default on and off (default value: off)

By default, C<pdla2> does not print the results of operations
since the results can be very large (e.g., a small 640x480
RGBA image is still more than 1_000_000 elements).  However,
for experimenting and debugging more complex structures,
it helps to see the results of I<every> operation.  The
C<do_print> routine allows you to toggle between the default
"quiet" operation and a full Read, Evaluate, Loop style.

=for example

  pdla> $a = pdl(3,2)

  pdla> do_print
  1
  pdla> $a = pdl(3,2)
  $PDLA1 = [3 2];
  pdla> do_print

  pdla> $a = pdl(3,2)

=head1 VARIABLES

=over 4

=item $PDLA::toolongtoprint

The maximal size pdls to print (defaults to 10000 elements).
This is not just a C<perldla> or C<pdla2> variable but it is
something that is usually needed in an interactive debugging
session.

=back

=head1 SEE ALSO

L<perldla>, L<Devel::REPL>

=cut