#!perl use strict; use warnings; use Data::Dumper; $|++; use Term::Readline; #thanks http://perlmonks.org/?node_id=940134 $ENV{TERM} =''; my $term = Term::ReadLine->new('Package explorator'); my %cmds = ( 'pkg' => sub { print "Enter a package name:\n"; my $pkg = ; chomp $pkg; print "Enter some code in package $pkg.\nAt the end insert CRTL-Z on a empty line.\n"; my @in = ; my $to_eval = "package $pkg {\n".(join "\n\t",@in)."}\n"; print "DEBUG:\n$to_eval\n\n"; { local $@; eval "$to_eval"; print "\n\nERROR:$@\n" if $@; } dump_symbols_of_package($pkg); }, 'dump' => sub { my $pkg = shift; dump_symbols_of_package($pkg); }, 'inspect' => sub { my ($pkg,$name,$slot) = @_; unless ($pkg && $name && $slot){ print "Please feed a package, a name and a slot.\n"; return; } inspect_slot ($pkg,$name,$slot); }, ); &user_input; ################################################################################ sub user_input { $term->Attribs->{completion_function} = sub { my $txt = shift; return grep { /^$txt/i } sort keys %cmds; }; my $in; while ( defined( $in = $term->readline('Package Explorer>') ) ) { chomp($in); $in =~ s/^\s+//; my ( $cmd, @arg ) = split /\s+/, $in; next if !$cmd; ## if ( $cmd eq 'q' or $cmd eq 'x' ) { exit } #? #elsif ($in eq 'r'or $in eq 'b') {bench} elsif ( exists $cmds{$cmd} ) { $cmds{$cmd}->(@arg) } else { print "WARNING Command '$in' not recognized.\n"; next; } } }