PDL-Perldl2-2.002/0000755000175000017500000000000014721234343013367 5ustar osboxesosboxesPDL-Perldl2-2.002/Plugin/0000755000175000017500000000000014721234343014625 5ustar osboxesosboxesPDL-Perldl2-2.002/Plugin/CleanErrors.pm0000644000175000017500000000260214721231116017375 0ustar osboxesosboxespackage PDL::Perldl2::Plugin::CleanErrors; use strict; use warnings; use Devel::REPL::Plugin; use namespace::clean -except => [ 'meta' ]; around 'error_return' => sub { my ($orig, $self) = (shift, shift); my ($type, $error) = @_; return $orig->($self, $type, clean_error_string($error)); }; # filter out the Devel::REPL, Class::MOP, ... from pdl2 errors sub clean_error_string { my $bigerr = $_[0]; $bigerr =~ s/^\s+Devel::REPL.*$//ms; $bigerr =~ s/^\s+Class::MOP.*$//ms; $bigerr =~ s/^\s+Lexical::Persistence.*$//ms; $bigerr =~ s/^\s+main::.*$//ms; $bigerr =~ s/^\s+eval \{.*$//ms; $bigerr =~ s/^\s+PDL::Core::barf.*$//ms; return $bigerr; } 1; __END__ =head1 NAME PDL::Perldl2::Plugin::CleanErrors - filter out Moose cruft =head1 DESCRIPTION Runtime errors in pdl2 are extremely verbose since they include the entire call chain from the start of the interactive Devel::REPL shell, through the Moose and Class::MOP stuff and including Lexical::Persistence as well. This plugin, which is loaded by default, strips out the non-PDL stuff to make the error messages much more concise. =head1 SEE ALSO C =head1 AUTHOR Chris Marshall, C<< >> =head1 COPYRIGHT AND LICENSE Copyright (C) 2011 by Christopher Marshall This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut PDL-Perldl2-2.002/Plugin/PrintControl.pm0000644000175000017500000000430214721231116017612 0ustar osboxesosboxespackage 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 which can be used to toggle the print default on or off. =head1 METHODS =head2 print_by_default By default, the C plugin sets C to 0 (false), which disables automatic printing of results. Call the print_by_default accessor with a 1 (true value) to enable default printing. =head2 do_print This is a convenience accessor for the print_by_default attribute. If you call this method without a value, it toggles the current setting. Otherwise, it just sets print_by_default to the value. It is also available in the C shell as the do_print sub with the same operation but with an implicit use of C<$_REPL>. =head1 SEE ALSO C =head1 AUTHOR Chris Marshall, C<< >> =head1 COPYRIGHT AND LICENSE Copyright (C) 2010 by Christopher Marshall This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut PDL-Perldl2-2.002/Plugin/PDLCommands.pm0000644000175000017500000000561614721231116017267 0ustar osboxesosboxespackage PDL::Perldl2::Plugin::PDLCommands; use strict; use warnings; use Devel::REPL::Plugin; use namespace::clean -except => [ 'meta' ]; # The atomic option---need to deconflict Turtle command injection # using qr{\#} and perldl's usage for command escapes. Just # exclude for now to get things working excludes 'Turtles'; around 'read' => sub { my $orig = shift; my ($self, @args) = @_; # using $lines here because that is the usage from perldl # and I want to cut and paste existing code if possible my $lines = $self->$orig(@args); # Execute the list of auto-code (TODO) ## for my $c (@PERLDL::AUTO) { ## my $mess = eval_and_report($c); ## warn $mess if $mess; ## } # Filter out PDL shell prefixes from cut-n-pasted lines if ( defined($lines) and $lines =~ s/$PERLDL::PREFIX_RE// ) { if ($PERLDL::TERM->can('GetHistory') and $PERLDL::TERM->can('SetHistory')) { my @hist = $PERLDL::TERM->GetHistory(); foreach my $entry (@hist) { $entry =~ s/$PERLDL::PREFIX_RE//; } $PERLDL::TERM->SetHistory(@hist); } } return $lines unless defined $lines; # print STDERR "PDLCommands: got '$lines'\n"; if ( lc $lines eq 'q' || lc $lines eq 'x' || lc $lines eq 'exit' ) { return "quit"; }; $lines =~ s/^\s*\?\?\s*/apropos /; # Make '??' = 'apropos' $lines =~ s/^\s*\?\s*/help /; # Make lone '?' = 'help' if ( $lines =~ /^\s*(help|usage|apropos|sig|badinfo|demo)\s+/) { # Allow help foo (no quotes) my @t = split(/\s+/,$lines); my $x; foreach $x(@t) { $x=~s/^["']+//; $x=~s/['"]+$//; }; $t[1] = "'".$t[1]."'" if ($#t == 1 && !($t[1] =~ /^\$/)); $lines = join(' ',@t); } $PERLDL::ESCAPE = $PERLDL::ESCAPE if defined $PERLDL::ESCAPE; if (substr($lines,0,1) eq substr($PERLDL::ESCAPE,0,1) and substr($lines,0,2) ne '#!') { # Allow escapes, avoid shebang my @lines = split /\n/, $lines; system(substr(shift @lines,1)); # Shell escape $lines = join("\n",@lines); } return $lines; }; 1; __END__ =head1 NAME PDL::Perldl2::Plugin::PDLCommands - implement perldl aliases/escapes =head1 DESCRIPTION This plugin implements the various convenience features of the perldl shell which correspond, roughly, to aliases and some structured pre-processing of the command line entered: =over 4 =item q|x|exit|quit as shortcuts to quit the shell =item ?? as an alias for apropos =item ? as an alias for help =item Autoquoting for arguments to help|usage|apropos|sig|badinfo|demo =item C<$PERLDL::ESCAPE> at the start of a command line to escape to the shell, defaults to C<#> =back =head1 SEE ALSO C, C =head1 AUTHOR Chris Marshall, C<< >> =head1 COPYRIGHT AND LICENSE Copyright (C) 2010 by Christopher Marshall This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut PDL-Perldl2-2.002/Plugin/NiceSlice.pm0000644000175000017500000000265314721231116017022 0ustar osboxesosboxespackage PDL::Perldl2::Plugin::NiceSlice; use strict; use warnings; 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__ =head1 NAME PDL::Perldl2::Plugin::NiceSlice - enable PDL NiceSlice syntax =head1 DESCRIPTION This plugin enables one to use the PDL::NiceSlice syntax in an instance of C such as the new Perldl2 shell, C. Without the plugin, array slicing looks like this: pdl> use PDL; pdl> $x = sequence(10); $PDL1 = [0 1 2 3 4 5 6 7 8 9]; pdl> $x->slice("2:9:2"); $PDL1 = [2 4 6 8]; After the NiceSlice plugin has been loaded, you can use this: pdl> $x(2:9:2) $PDL1 = [2 4 6 8]; =head1 CAVEATS C uses Perl source preprocessing. If you need 100% pure Perl compatibility, use the slice method instead. =head1 SEE ALSO C, C, C =head1 AUTHOR Chris Marshall, C<< >> =head1 COPYRIGHT AND LICENSE Copyright (C) 2010 by Christopher Marshall This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut PDL-Perldl2-2.002/Plugin/Makefile.PL0000644000175000017500000000066114721231116016575 0ustar osboxesosboxesuse strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'PDL::Perldl2::Plugin', 'VERSION' => '2.001', 'PM' => { 'CleanErrors.pm' => '$(INST_LIBDIR)/Plugin/CleanErrors.pm', 'NiceSlice.pm' => '$(INST_LIBDIR)/Plugin/NiceSlice.pm', 'PDLCommands.pm' => '$(INST_LIBDIR)/Plugin/PDLCommands.pm', 'PrintControl.pm' => '$(INST_LIBDIR)/Plugin/PrintControl.pm', }, NO_MYMETA => 1, ); PDL-Perldl2-2.002/META.json0000644000175000017500000000270214721234343015011 0ustar osboxesosboxes{ "abstract" : "unknown", "author" : [ "Chris Marshall " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "PDL-Perldl2", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "7.14" } }, "runtime" : { "requires" : { "Devel::REPL" : "0", "Devel::REPL::Plugin" : "0", "Moose" : "0", "PDL" : "2.095", "namespace::clean" : "0", "perl" : "5.016" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/PDLPorters/PDL-Perldl2/issues" }, "homepage" : "http://pdl.perl.org/", "repository" : { "type" : "git", "url" : "git://github.com/PDLPorters/PDL-Perldl2.git", "web" : "https://github.com/PDLPorters/PDL-Perldl2" }, "x_IRC" : "irc://irc.perl.org/#pdl" }, "version" : "2.002", "x_serialization_backend" : "JSON::PP version 4.04" } PDL-Perldl2-2.002/logo3d.pdl0000755000175000017500000001055114721231116015257 0ustar osboxesosboxes#!/usr/bin/perl # # Created on: Tue 20 Jul 2010 08:50:58 AM # Last saved: Mon 13 Sep 2010 03:47:39 PM # # This is a test script to generate the 3D PDL sphere # logo using TriD. I think it would be very cool to # have a logo3d routine to generate the image as an # animated splash screen for example.... use PDL; use PDL::NiceSlice; use PDL::Graphics::TriD; $scale = 0.3; $alpha = 0.5; $pcolor = pdl(float,0,1,0,$alpha); # green $dcolor = pdl(float,1,0,0,$alpha); # red $lcolor = pdl(float,0,0,1,$alpha); # blue $gcolor = pdl(float,1,0,0,$alpha); # red for grid color # I think this was from testing grayscale logos # $pcolor = $dcolor = $lcolor = $gcolor = black; # draw the 3D grid of lines foreach my $i ( 0..3 ) { foreach my $j ( 0..6 ) { print "draw line from ($i,$j,0) to ($i,$j,4)\n" if $verbose; } } foreach my $i ( 0..3 ) { foreach my $k ( 0,2,4 ) { print "draw line from ($i,0,$k) to ($i,6,$k)\n" if $verbose; } } foreach my $j ( 0..6 ) { foreach my $k ( 0,2,4 ) { print "draw line from (0,$j,$k) to (3,$j,$k)\n" if $verbose; } } # The letters are on a 4x7 grid # $P = pdl [ [1,1,1,0], [1,0,0,1], [1,0,0,1], [1,1,1,0], [1,0,0,0], [1,0,0,0], [1,0,0,0], ]; $D = pdl [ [0,0,0,1], [0,0,0,1], [0,0,0,1], [0,1,1,1], [1,0,0,1], [1,0,0,1], [0,1,1,1], ]; $L = pdl [ [0,0,0,1], [0,0,0,1], [0,0,0,1], [0,0,0,1], [0,0,0,1], [0,0,0,1], [0,0,0,1], ]; # Assign the bitmaps to the 3D layout, might be clearer to just # generate the $logomask ndarray with a single constructor call # since the mask assignments are a bit obtuse # $logomask = $P->dummy(2,5)->zeros; $logomask(:,:,(4)) .= $P(:,-1:0); $logomask(:,:,(2)) .= $D(:,-1:0); $logomask(:,:,(0)) .= $L(:,-1:0); # Now to extract the sphere coordinates for each letter # $logomask ...starts as 4x7x5 ndarray # ->ndcoords ...produces 3 x 4x7x5 ndarrays of coords # ->where( ...select values with set pixels # $logomask(*3) ...need conforming 3x4x7x5 mask array # )->splitdim(0,3); ...1D result needs to get dim(0) back # and all together we get: # $logoxyz = $logomask->ndcoords->where($logomask(*3))->splitdim(0,3); # Need to have the ability to hide/toggle the axes so they # don't interfere with the image view *and* would like to # control the viewing direction rather than enabling user # twiddling of the display axes. spheres3d $logoxyz; ## draw(shift(0,0,4)*scale(s,s,s)*unitsphere, pcolor); ## draw(shift(0,1,4)*scale(s,s,s)*unitsphere, pcolor); ## draw(shift(0,2,4)*scale(s,s,s)*unitsphere, pcolor); ## draw(shift(0,3,4)*scale(s,s,s)*unitsphere, pcolor); ## draw(shift(0,4,4)*scale(s,s,s)*unitsphere, pcolor); ## draw(shift(0,5,4)*scale(s,s,s)*unitsphere, pcolor); ## draw(shift(0,6,4)*scale(s,s,s)*unitsphere, pcolor); ## draw(shift(1,6,4)*scale(s,s,s)*unitsphere, pcolor); ## draw(shift(2,6,4)*scale(s,s,s)*unitsphere, pcolor); ## draw(shift(3,5,4)*scale(s,s,s)*unitsphere, pcolor); ## draw(shift(3,4,4)*scale(s,s,s)*unitsphere, pcolor); ## draw(shift(2,3,4)*scale(s,s,s)*unitsphere, pcolor); ## draw(shift(1,3,4)*scale(s,s,s)*unitsphere, pcolor); ## ## draw(shift(3,6,2)*scale(s,s,s)*unitsphere, dcolor); ## draw(shift(3,5,2)*scale(s,s,s)*unitsphere, dcolor); ## draw(shift(3,4,2)*scale(s,s,s)*unitsphere, dcolor); ## draw(shift(3,3,2)*scale(s,s,s)*unitsphere, dcolor); ## draw(shift(3,2,2)*scale(s,s,s)*unitsphere, dcolor); ## draw(shift(3,1,2)*scale(s,s,s)*unitsphere, dcolor); ## draw(shift(3,0,2)*scale(s,s,s)*unitsphere, dcolor); ## draw(shift(2,0,2)*scale(s,s,s)*unitsphere, dcolor); ## draw(shift(1,0,2)*scale(s,s,s)*unitsphere, dcolor); ## draw(shift(0,1,2)*scale(s,s,s)*unitsphere, dcolor); ## draw(shift(0,2,2)*scale(s,s,s)*unitsphere, dcolor); ## draw(shift(1,3,2)*scale(s,s,s)*unitsphere, dcolor); ## draw(shift(2,3,2)*scale(s,s,s)*unitsphere, dcolor); ## ## draw(shift(3,6,0)*scale(s,s,s)*unitsphere, lcolor); ## draw(shift(3,5,0)*scale(s,s,s)*unitsphere, lcolor); ## draw(shift(3,4,0)*scale(s,s,s)*unitsphere, lcolor); ## draw(shift(3,3,0)*scale(s,s,s)*unitsphere, lcolor); ## draw(shift(3,2,0)*scale(s,s,s)*unitsphere, lcolor); ## draw(shift(3,1,0)*scale(s,s,s)*unitsphere, lcolor); ## draw(shift(3,0,0)*scale(s,s,s)*unitsphere, lcolor); PDL-Perldl2-2.002/pdl20000755000175000017500000000607514721231116014161 0ustar osboxesosboxes#!/usr/bin/perl BEGIN { $ENV{DEVEL_REPL_PROFILE} = 'PDL::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 ($perldl) = $0; $perldl =~ s/pdl2\.bat$/perldl.bat/; $perldl =~ s/pdl2$/perldl/; warn "pdl2: Devel::REPL version $minversion not found, running '$perldl' instead...\n"; do $perldl; warn "pdl2: could not 'do $perldl'\n"; $perldl =~ s{^[^/\\]*[/\\]}{}; do $perldl; die "pdl2: could not 'do $perldl'\n"; } } use PDL::Perldl2::Script 'run'; __END__ =head1 NAME pdl2 - Simple shell (version 2) for PDL =head1 SYNOPSIS Use PDL interactively: %> pdl2 pdl> $x = sequence(10) # or any other perl or PDL command pdl> print "\$x = $x\n"; $x = [0 1 2 3 4 5 6 7 8 9] pdl> with_time { print +($A->matmult($B))->info, "\n" } for 1..5; =head1 DESCRIPTION The C program, also known as the Perldl2 shell, is a second generation version of the original C interactive PDL 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 shell. If you have L version 1.003011 or later, then C will start with full functionality. If L is not installed or found then C will print a warning and run the legacy C shell command instead. By default, command lines beginning with the default prompt of either C or C (one of 'pdl> ', 'PDL> ', or 'perldl> ') will have the prefix string and surrounding whitespace stripped. This allows for easy cut-and-paste from sample PDL shell sessions or other examples into another PDL shell session. For shell-like C handling, you need L installed. =head1 FUNCTIONS =head2 do_print =for ref Toggle print-by-default on and off (default value: off) By default, C 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 operation. The C routine allows you to toggle between the default "quiet" operation and a full Read, Evaluate, Loop style. =for example pdl> $x = pdl(3,2) pdl> do_print 1 pdl> $x = pdl(3,2) $PDL1 = [3 2]; pdl> do_print pdl> $x = pdl(3,2) =head1 VARIABLES =over 4 =item $PDL::toolongtoprint The maximal size pdls to print (defaults to 10000 elements). This is not just a C or C variable but it is something that is usually needed in an interactive debugging session. =back =head1 SEE ALSO L, L =cut PDL-Perldl2-2.002/Profile/0000755000175000017500000000000014721234343014767 5ustar osboxesosboxesPDL-Perldl2-2.002/Profile/Perldl2.pm0000644000175000017500000002034614721231116016631 0ustar osboxesosboxespackage PDL::Perldl2::Profile::Perldl2; use strict; use warnings; use Moose; use namespace::clean -except => [ 'meta' ]; our $VERSION = 0.008; $PERLDL::PROMPT = $PERLDL::PROMPT; # suppress warning with 'Devel::REPL::Profile'; my %plugin2deps = ( 'Completion' => [qw(PPI)], 'CompletionDriver::INC' => [qw(File::Next)], 'CompletionDriver::Keywords' => [qw(B::Keywords)], 'CompletionDriver::LexEnv' => [qw(Lexical::Persistence)], 'DDS' => [qw(Data::Dump::Streamer)], 'Interrupt' => [qw(Sys::SigAction)], 'LexEnv' => [qw(Lexical::Persistence)], 'MultiLine::PPI' => [qw(PPI)], ); sub plugins { qw( CleanErrors Commands Completion CompletionDriver::INC CompletionDriver::Keywords CompletionDriver::LexEnv CompletionDriver::Methods DDS History Interrupt LexEnv MultiLine::PPI Packages NiceSlice PrintControl ReadLineHistory PDLCommands ); # CompletionDriver::Globals } sub apply_profile { my ($self, $repl) = @_; # check for Term::ReadLine::Stub if ($repl->term->ReadLine =~ /Stub/) { $repl->print("WARNING:\n Term::ReadLine::Stub does not support pdl2 features.\n"); $repl->print(" Please install either Term::ReadLine::Perl or Term::ReadLine::Gnu.\n"); $repl->print(" Falling back to perldl in the meantime...\n"); $repl->print("------------------------------------------\n\n"); exec 'perldl'; } # add PDL::Perldl2 for plugin search push @{$repl->_plugin_app_ns}, 'PDL::Perldl2'; foreach my $plug ($self->plugins) { if (my $deps = $plugin2deps{$plug}) { next if grep !eval "require $_; 1", @$deps; } $repl->load_plugin($plug); } # enable Term::ReadLine file expansion by default $repl->do_readline_filename_completion(1) if $repl->can('do_readline_filename_completion'); # do perldl stuff here $repl->eval('package main'); $repl->eval('use PDL'); $repl->eval('use PDL::Dbg'); $repl->eval('use PDL::Doc::Perldl'); $repl->eval('use PDL::IO::Dumper'); $repl->eval('use PDL::IO::FlexRaw'); $repl->eval('use PDL::IO::Pic'); $repl->eval('use PDL::Image2D'); $repl->eval('use PDL::AutoLoader'); $repl->eval('no strict qw(vars)'); # declare PERLDL package variables # most are not used but they are here if needed $repl->eval( q[ @PERLDL::AUTO = (); # code string/refs to run after user enters a new line $PERLDL::ESCAPE = '#'; # Default shell escape character $PERLDL::HISTFILESIZE = $ENV{PERLREPL_HISTLEN}; # Number of lines to keep in history $PERLDL::MULTI = 1; # Enable multi-lines by default $PERLDL::NO_EOF = 1; # Enable EOF protection by default $PERLDL::PAGE = 0; $PERLDL::PAGER = ((exists $ENV{PAGER}) ? $ENV{PAGER} : 'more'); $PERLDL::PAGING = 0; $PERLDL::PROMPT = "pdl> "; # string or code reference $PERLDL::PREFIX_RE = qr(^\s*(?:pdl|perldl)>\s*); # RE for shell prompts $PERLDL::TERM = $_REPL->term; ] ); #autoflush STDOUT $repl->eval('$|=1;'); # p command (NOTE: this is not an alias for print) $repl->eval('sub p { local $, = " "; print @_,"\n" };'); # list history command $repl->eval('sub l { my $n = $#_ > -1 ? shift : 20; my @h = $_REPL->term->GetHistory(); my $min = $#h < $n-1 ? 0 : $#h-$n+1; map { printf "%d: %s\n", $_+1, $h[$_] } ($min..$#h); #map {print "$_: $h[$_]\n"} ($min..$#h); };'); $repl->eval( q{ sub with_time (&) { require Time::HiRes; my @t = Time::HiRes::gettimeofday(); &{$_[0]}(); printf "%g ms\n", Time::HiRes::tv_interval(\@t) * 1000; } } ); $repl->eval( q{ sub gv { my ($pdl, $file) = @_; my $format = (split '.', $file)[-1]; my $g = PDL::Core::pdumpgraph(PDL::Core::pdumphash($pdl)); require GraphViz2; my $gv = GraphViz2->from_graph(PDL::Core::pdumpgraphvizify($g)); $gv->run(format => $format, output_file => $file); } } ); $repl->eval( q{ sub x { require Data::Dumper; local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Terse = 1; print Data::Dumper::Dumper(@_); } } ); $repl->eval( q{ use PDL::Demos; sub demo { if (!$_[0]) { require List::Util; my @kw = sort grep $_ ne 'pdl', PDL::Demos->keywords; my $maxlen = List::Util::max(map length, @kw); print "Use:\n"; printf " demo %-${maxlen}s # %s\n", @$_[0,1] for map [PDL::Demos->info($_)], 'pdl', @kw; return; } no strict; PDL::Demos->init($_[0]); &{$_->[0]}($_->[1]) for PDL::Demos->demo($_[0]); PDL::Demos->done($_[0]); } } ); if ($repl->can('do_print')) { $repl->eval('sub do_print { $_REPL->do_print(@_) };'); } if ($repl->can('exit_repl')) { $repl->eval('sub quit { $_REPL->exit_repl(1) };'); } else { $repl->eval('sub quit { $_REPL->print("Use Ctrl-D or exit to quit" };'); } $repl->prompt($PERLDL::PROMPT); # new prompt if ( defined $ENV{TERM} and $ENV{TERM} eq 'dumb' ) { $repl->print("\n"); $repl->print("******************************************\n"); $repl->print("* Warning: TERM type is dumb! *\n"); $repl->print("* Limited ReadLine functionality will be *\n"); $repl->print("* available. Please unset TERM or use a *\n"); $repl->print("* different terminal type. *\n"); $repl->print("******************************************\n"); $repl->print("\n"); } $repl->print("Perldl2 Shell v$PDL::Perldl2::Profile::Perldl2::VERSION PDL comes with ABSOLUTELY NO WARRANTY. For details, see the file 'COPYING' in the PDL distribution. This is free software and you are welcome to redistribute it under certain conditions, see the same file for details.\n"); $repl->print("Loaded plugins:\n"); { my @plugins = (); foreach my $pl ( $repl->_plugin_locator->plugins ) { # print names of ones that have been loaded my $plug = $pl; $plug =~ s/^.*Plugin::/ /; push @plugins, $plug if $repl->does($pl); } # Need smarter display of plugins, fill out the line # and list CompletionDrivers under Completion $repl->print(join "\n", sort(@plugins)); $repl->print("\n"); } $repl->print("Type 'help' for online help\n"); $repl->print("Type Ctrl-D or quit to exit\n"); $repl->print("Loaded PDL v$PDL::VERSION\n"); } 1; __END__ =head1 NAME PDL::Perldl2::Profile::Perldl2 - profile for Perldl2 shell =head1 SYNOPSIS system> re.pl --profile=PDL::Perldl2::Profile::Perldl2 # unix-ish shell system> re --profile=PDL::Perldl2::Profile::Perldl2 # win32 CMD shell Perldl2 Shell v0.008 PDL comes with ABSOLUTELY NO WARRANTY. For details, see the file 'COPYING' in the PDL distribution. This is free software and you are welcome to redistribute it under certain conditions, see the same file for details. Loaded plugins: CleanErrors Commands Completion CompletionDriver::INC CompletionDriver::Keywords CompletionDriver::LexEnv CompletionDriver::Methods DDS FindVariable History Interrupt LexEnv MultiLine::PPI NiceSlice PDLCommands Packages PrintControl ReadLineHistory Type 'help' for online help Type Ctrl-D or quit to exit Loaded PDL v2.006 pdl> =head1 DESCRIPTION This profile is for development of the new PDL shell (version 2). The preferred method to start the new shell is via the C command. This documentation is provided for C coders that may wish to use this profile directly for their development. =head1 SEE ALSO C, C, and C. =head1 AUTHOR Chris Marshall, C<< >> =head1 COPYRIGHT AND LICENSE Copyright (C) 2010 by Christopher Marshall This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut PDL-Perldl2-2.002/Profile/Makefile.PL0000644000175000017500000000033414721231116016734 0ustar osboxesosboxesuse strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'PDL::Perldl2::Profile', 'VERSION' => '2.000', 'PM' => { 'Perldl2.pm' => '$(INST_LIBDIR)/Profile/Perldl2.pm' }, NO_MYMETA => 1, ); PDL-Perldl2-2.002/TODO0000644000175000017500000003065414721231116014062 0ustar osboxesosboxesCreated on: Thu 10 Dec 2009 10:32:58 PM Last saved: Tue 09 Jul 2013 09:05:18 AM +-------------------------------------------------------------------+ | TODO for Missing Perldl Functionality | +-------------------------------------------------------------------+ Set readline_name to 'PDL Shell' instead of the default 'Perl REPL' but need to figure how to do so first (override default term?). Add syntax highlighting to help ensure correct entries (e.g., in matlab keywords are blue, strings are purple, unterminated strings are maroon...) We could also specifically color ndarrays and objects from the current session space. Add "blink to matching delimiter" for input or even color highlight matching delimiters Add Colors plugin support to the pdl2 p command. Add enhanced filter support to remove leading prompt strings (or other text) from input lines. Need to be able to toggle on/off and set the regexp used. Allow Ctrl-C to interrupt a line but keep the entry in history for edit... Fix q alias for quit which broke as a side effect of a fix to the MultiLine::PPI handling. Perhaps using around continue_reading_if_necessary would do the trick. Need to sort out the Moose/Plugin/Roles issues and document. Implement ^C/^D to end PPI multiline if it makes sense. E.g., make sure that Ctrl-C can exit an incomplete block. Right now ^C does not interrupt a multiline entry. Need to see about implementing the Ctrl-D option to close all blocks as well. It would be nice to have the prompt display the matching delims as in perldl. Fix Term::ReadLine::Perl completion in win32 to use the appropriate path separator character. It appears to use / which is fine inside perl but not for system command escapes. Need to detect the two cases. Maybe we could autoquote the paths when using backslashes. Add auto-quoting/close quotes to Term::ReadLine::Perl expansion as does Term::ReadLine::Gnu. Fix Term::ReadLine::Perl completion to not append identifier characters on the inserted filenames: e.g. it is ok to list file.exe* in the possible completions part but the result should only insert file.exe (the actual file name). Fix Term::ReadLine::Perl TAB expansion for paths to work with win32 paths (i.e. backslashes). Add expansion to the pdl2 help/? command. Track pdl2 session variables for PDL, including: vars (global and lexical), subs that were defined, modules loaded, and plugins for the REPL. It should be possible to complete for these. Add tracking and expansion for all graphics windows that are open/active (PGPLOT, PLplot, Prima, GLUT/FreeGLUT...) windows for reference. It would be nice to have a list/table of currently active figures. IDEA: Associate metadata with image or figure windows (e.g., the commands that generated the figure). Add SIGINT handler for pdl2 for win32. Also need to add feature to ignore EOF to the read routine (around read modifier should work here---need to decide where to put it) Investigate why Ctrl-L on win32 is issuing a 'clear' command. ANSWER: readline.pm from Term::ReadLine::Perl is doing a qx{clear) to determine the escape sequence to clear the screen. This doesn't work on win32 since there is no clear command and the console does not support ANSI escape sequences. Plan to fix by calling the DOS cls command to clear the screen or by using Win32::Console and Win32::Console::ANSI to implement the missing ANSI support. Need to implement a routine readline::F_ClearScreen() to override the default function for win32 systems. Add runtime PDL module load list so you know what has been loaded with use/require. Maybe a pop-up info window would work here (curses based or GUI based). Override '*CORE::GLOBAL::use'? It would also be possible to use MOP features of Moose. Review and integrate $PERLDL::XX parameters. Some are not needed or useful for Perldl2. Others need code to tie in with the new framework. Implement perldl command line options: -M load module -m unload module -I Add to include path. -V print PDL version info (e.g. for a bug report) -f execute file before starting perldl -glut try to load OpenGL module (Enables readline event-loop processing). -tk try to load Tk module (Enables readline event-loop processing). -w run with warning messages turned-on - Following arguments are files for input. Add @PERLDL::AUTO processing to the PDLCommands plugin. Should be able to just run the code after the line is read but before it is eval'd. Add ability to run $PERLDL::PROMPT if it is a code reference and not a string. Use the same logic as in perldl but set the prompt with the $_REPL->prompt(&$code) instead of using $_REPL->prompt($string). Implement support for @PERLDL::PREPROCESS filters. Update perldl documentation to match Perldl2 capabilities. Any way to transparently select the correct docs at runtime? Fix the newline differences between new line handling for TR::Perl (on win32 and cygwin and unix) and TR::Gnu (on cygwin and unix). TR::Gnu seems to have an extra newline inserted per command. Is it possible to add support for Term::ReadLine::Zoid? It would be nice if the most possible could be done using the Term::ReadLine::Stub. Add MultiLine prompt with continuation character marking the open structures. (e.g. MultiLine::TextBalanced). Add generic event loop support to Term::ReadLine::Perl and Term::ReadLine::Gnu. Need to figure out a clean way to map this into the original modules. Skip command lines that are too short and don't put quit/q/x/exit in the history log. Maybe remove duplicate entries as well as list history commands. Don't put history !-syntax into the history, put the actual command that resulted. e.g., not !6 but 'p "Hello, world.\n"; Be sure to add a line to history if it closes out a multi-line block. This should not be an issue once we have multi-line history entries supported. It would be nice if history entries were by blocks with the ability to go by lines within if desired. Make !-syntax history more restrictive so that it does not conflict with perl usage for negation. Maybe it should only be good for completion? At least if it is the first char and do_print(0). Add !:p support to print history commands and fix the problem where the ! command is different then the one actually inserted by History... Add runtime control options for NiceSlice: i.e., report, trans, and notrans Add a CompletionDriver for Plugins for load_plugin() as well as the ability to toggle plugins on and off (or at least enable and disable them). Would it simplify PDL::NiceSlice if the implementation were migrated to Filter::Simple? Make pdl2 fall back cleanly to a basic Devel::REPL or even perldl if requirements to run are not installed. (falls back to perldl right now) Fix glob pattern completion display for shell escapes in pdl2 (e.g., file* will list out tab.a tab.b and tab.c if those are the valid expansions. It should act just like bash directly from the command line---ideally). Add documentation for the startup files for unix-en and win32 systems. Right now, the only doc is in the code. Add startup checks for the various Devel::REPL plugins loaded to be sure that they can run before the load_plugin call to avoid nasty compile error traces. Fix 'demo 3d' so that it shifts focus to the display window at the start and returns focus to the CMD or shell window at then end. This shouldn't be needed with GLUT event loop support in readline. Is there a way to fix the GNU readline where it doesn't process the Ctrl-C interrupt until after has been typed? There are some hooks in GNU readline for handling signals that may help here. Add option for quiet startup for use when piping to the shell or taking input from a file. Add INPUT and OUTPUT handle args for PDL shells. How do we add this to the default term from Devel::REPL? NOTE: Also need to fix perldl v.1.x not to use STDIN/STDOUT. Verify that input from terminal and/or files works correctly and consistently with perldl. NOTE: This should make it possible to implement some tests of the interactive shell from file input. It would be nice if variable completion followed by a method call would collapse the extra space. E.g., the first in line#1 completes to the $_REPL varible followed by a space as seen in line#2. Then typing the ->do_p in line#3 triggers a method completion to ->do_print followed by a space shown in line#4. #1 PDL> $_RE #2 PDL> $_REPL _ #3 PDL> $_REPL ->do_p #4 PDL> $_REPL ->do_print _ What we would like is the trailing space in line#2 to be collapsed once the -> is typed following the completion. Similarly, we would like the space at the end of line#4 to be collapsed once a '(' is typed to start the arglist. Enhance completion strategy for Perldl2: (1) sort and prioritze completions to remove long lists of useless options [see completion paper], (2) allow chained PDL method completions by recognizing that the output of many (all?) PDL methods is a pdl so we could do method completion again... Make Perldl2 fail/degrade gracefully if various files and configuration stuff is not available. Lines and lines of backtrace isn't a help to anyone! Improve the error returns from evaluations in pdl2 as they seem to cut off the root error line for failures which makes it very difficult to debug things, e.g. I was getting errors from Core.pm instead of in my routine that had the failure. When I looked at the entire call stack in the debugger, I got the actual line with the bad code---of course I had to give up the nice pdl2 environment. Filter out error tracebacks from pdl2/perldl. It looks like these are internal to Devel::REPL and not the code being executed and could be filtered out: + eval {...} # both pdl2 and perldl + main::__ANON__ # both pdl2 and perldl | main::process_input # perldl | main::eval_and_report # perldl - main::BEGIN # pdl2 - Lexical::Persistence:: # pdl2 - Devel::REPL:: # pdl2 - Class::MOP:: # pdl2 +-------------------------------------------------------------------+ | Features perldl pdl2 | +-------------------------------------------------------------------+ preproc_add/del yes TBD ?,?? aliases yes yes quit,x,exit aliases yes yes User AUTO commands yes TBD Autoquoting doc commands yes yes Load user startup file yes yes Load local.perldlrc yes yes $_ preserved by line/block by session User extendable rewrite/hard plugins/easy History save/recall yes yes !-history expansion yes/partial yes Lexical variables yes/1-command only yes Multiline expression entry yes/Text::Balanced yes/PPI based NiceSlice syntax yes yes package NAMESPACE support no yes Readline editing yes/partial yes TAB completion: @INC no yes TAB completion: filename yes yes TAB completion: globals no yes TAB completion: keyword no yes TAB completion: lexicals no yes TAB completion: methods no yes print p alias yes yes list history yes yes help vars (package) yes yes help vars (lexical) no TBD PDL-Perldl2-2.002/META.yml0000644000175000017500000000150014721234343014634 0ustar osboxesosboxes--- abstract: unknown author: - 'Chris Marshall ' build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '7.14' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: PDL-Perldl2 no_index: directory: - t - inc requires: Devel::REPL: '0' Devel::REPL::Plugin: '0' Moose: '0' PDL: '2.095' namespace::clean: '0' perl: '5.016' resources: IRC: irc://irc.perl.org/#pdl bugtracker: https://github.com/PDLPorters/PDL-Perldl2/issues homepage: http://pdl.perl.org/ repository: git://github.com/PDLPorters/PDL-Perldl2.git version: '2.002' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' PDL-Perldl2-2.002/Script.pm0000644000175000017500000000233014721234202015161 0ustar osboxesosboxespackage PDL::Perldl2::Script; use strict; use warnings; use Moose; use namespace::clean -except => [ qw(meta) ]; extends 'Devel::REPL::Script'; sub _startup_def { return "PDL/default.perldlrc"; } sub load_rcfile { my ($self, $rc_file) = @_; my $HOME = $ENV{HOME}; if ($^O =~ /win32/i and (! defined($HOME)) or (defined($HOME) and $HOME eq "")) { $HOME = $ENV{USERPROFILE}; $HOME =~ s/\\/\//g; } print STDERR "load_rcfile: got \$HOME = $HOME\n"; # get rc file name my $startup_file = _startup_def(); foreach my $startup_suffix (qw( .pdlrc .perldlrc )) { if ( -e "$HOME/$startup_suffix" ) { $startup_file = "$HOME/$startup_suffix"; last; } } print STDERR "load_rcfile: loading $startup_file\n"; $self->apply_script($startup_file); # load local.perldlrc if it exists foreach my $local_startup_file (qw( local.pdlrc local.perldlrc )) { if ( -e $local_startup_file ) { print STDERR "load_rcfile: loading $local_startup_file\n"; $self->apply_script($local_startup_file); last; } } } # Global and local startup # PAUSE insists this package be here, so: package PDL::Perldl2; our $VERSION = '2.002'; 1; PDL-Perldl2-2.002/Changes0000644000175000017500000000014414721234232014656 0ustar osboxesosboxes2.002 2024-11-26 - upload with "PDL::Perldl2" in a .pm 2.001 2024-11-26 - split out from PDL 2.095 PDL-Perldl2-2.002/README0000644000175000017500000001072114721231116014243 0ustar osboxesosboxesCreated on: Thu 10 Dec 2009 10:32:58 PM Last saved: Tue 09 Jul 2013 08:51:39 AM +-----------------------------------------------------------+ | OS/Platforms supported: ALL | +-----------------------------------------------------------+ This directory contains development efforts for a new and improved perldl shell (Perldl2). You need to install the version 1.003011 of Devel::REPL and have installed either Term::ReadLine::Perl or Term::ReadLine::Gnu in order to use the new Perldl2 shell capabilities. +-----------------------------------------------------------+ | CONTENTS | +-----------------------------------------------------------+ README This file TODO Development list for Perldl2 shell Makefile.PL Perl configuration/build script for Perldl2 Plugin/ Profile/ Script.pm Perl modules and directories with modules for Perldl2 pdl2 A perl script for starting the Perldl2 shell. (Falls back to the original perldl if either Devel::REPL or neither Term::ReadLine::Gnu nor Term::ReadLine::Perl are installed.) +-----------------------------------------------------------+ | INSTALLATION | +-----------------------------------------------------------+ By default, the Perldl2 shell is always built and the pdl2 script installed. You will need to install Devel::REPL version 1.003011 or greater and either of Term::ReadLine::Gnu or Term::ReadLine::Perl to access the new pdl2 capabilities. +-----------------------------------------------------------+ | USE | +-----------------------------------------------------------+ To use the Perldl2 shell, from the PDL build directory run the following: perl -Mblib Perldl2/pdl2 If you have installed the just built PDL, you should be able to run: pdl2 To exit the Perldl2 shell from the 'pdl> ' prompt, type Ctrl-D or quit, (q, x, and exit shortcuts are also available). If Devel::REPL is not installed (or you don't have either TR::Gnu or TR::Perl), pdl2 will use perldl instead but the new Perldl2 features will not be available. The idea is that one just uses pdl2 where you used to use perldl. At some point, the development will be complete and there will be only one PDL shell. +-----------------------------------------------------------+ | NOTES | +-----------------------------------------------------------+ Supported functionality from Devel::REPL and PDL: * DDS (pretty prints output using Data::Dump::Streamer) * History (redo commands with !-1 and ! syntax) * Interrupt (interrupt with Ctrl-C; not on MSWin32) * LexEnv (e.g., my $x = zeros(10) works) * MultiLine::PPI (handles multiline input like perldl) * NiceSlice (PDL::NiceSlice works too!) * Packages (keeps track of current user package) * PDLCommands (perldl shell v1 convenience routines) * ReadLineHistory * Save and restore command history to file * CompletionDrivers * Globals (completion for globals) * INC (completion for use module::name) * Keywords (completion for perl keywords) * LexEnv (completion for lexical vars) * Methods (completion of method names) Default PDL modules loaded: * PDL * PDL::Dbg * PDL::Doc::Perldl * PDL::IO::Dumper * PDL::IO::FlexRaw * PDL::IO::Pic * PDL::Image2D * PDL::AutoLoader ? and ?? are aliases for help and apropos Arguments to help|usage|apropos|sig|badinfo|demo are autoquoted Shell escapes start with $PERLDL::ESCAPE as the first character of a line ('#' by default). l prints the last lines of history, default 20. p prints the following args separated by space (i.e., $,=' ') demo as a command by itself lists the possible demos available. Otherwise it runs the specified demo. By default, leading patterns matching the pdl2 shell prompt ('pdl> ' with possible surrounding white space) are stripped from the input. That allows for easy cut-and-paste of pdl2 sessions from examples, demos, or docs. The Perldl2 shell, pdl2, loads/saves from the same history file as perldl. The Perldl2 shell, pdl2, loads your .perldlrc file from the same location as the perldl shell does. It also accepts .pdlrc as the name---looking forward to the new naming scheme for the interactive shell. A local.pdlrc or local.perldlrc are run if present as well. PDL-Perldl2-2.002/tctrl-c.pl0000644000175000017500000000076014721231116015272 0ustar osboxesosboxesuse strict; use warnings; use Term::ReadLine; $| = 1; my $cnt = 0; sub handler { print "Caught a SIG '$_[0]' - continuing\n"; die "Got three" if ++$cnt > 2; } $SIG{INT} = \&handler; my $term = Term::ReadLine->new('ProgramName'); while (1) { my $input = $term->readline('prompt> '); if (not defined $input) { print "EOF on input\n"; } elsif ($input eq 'q') { print "quitting\n"; exit; } else { printf "Got: '%s'\n", $input; } Win32::Sleep(1000); # stop runaway console } __END__ PDL-Perldl2-2.002/MANIFEST0000644000175000017500000000063414721234343014523 0ustar osboxesosboxesChanges logo3d.pdl Makefile.PL MANIFEST This list of files pdl2 Plugin/CleanErrors.pm Plugin/Makefile.PL Plugin/NiceSlice.pm Plugin/PDLCommands.pm Plugin/PrintControl.pm Profile/Makefile.PL Profile/Perldl2.pm README Script.pm tctrl-c.pl TODO META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) PDL-Perldl2-2.002/Makefile.PL0000644000175000017500000000227514721234266015353 0ustar osboxesosboxesuse strict; use warnings; use ExtUtils::MakeMaker; # Extra build target to build the doc database sub MY::postamble { <<"EOPS"; pdl2.pod : pdl2 \t\$(PERLRUN) -MPod::Select -e "podselect('pdl2');" > pdl2.pod EOPS } my @podpms = map { $_.".pod", '$(INST_LIBDIR)/' . $_ .".pod"} qw/pdl2/; WriteMakefile( NAME => 'PDL::Perldl2', VERSION_FROM => 'Script.pm', AUTHOR => "Chris Marshall ", LICENSE => 'perl', MIN_PERL_VERSION => '5.016', EXE_FILES => [ 'pdl2' ], PM => { 'Script.pm' => '$(INST_LIBDIR)/Perldl2/Script.pm', @podpms }, CONFIGURE_REQUIRES => { 'ExtUtils::MakeMaker' => '7.14', }, PREREQ_PM => { 'PDL' => '2.095', 'Moose' => 0, 'namespace::clean' => 0, 'Devel::REPL' => 0, 'Devel::REPL::Plugin' => 0, }, META_MERGE => { "meta-spec" => { version => 2 }, resources => { homepage => 'http://pdl.perl.org/', bugtracker => {web=>'https://github.com/PDLPorters/PDL-Perldl2/issues'}, repository => { url => 'git://github.com/PDLPorters/PDL-Perldl2.git', type => 'git', web => 'https://github.com/PDLPorters/PDL-Perldl2', }, x_IRC => 'irc://irc.perl.org/#pdl', }, }, );