Matthew Simon Cavalletto > Term-ShellKit-1.002 > Term::ShellKit::Commands

Download:
Term-ShellKit-1.002.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

Term::ShellKit::Commands - Basic shell functions

SYNOPSIS ^

  > perl -Iblib/lib -MTerm::ShellKit -eshell "kit Dev"
  Term::ShellKit: Starting interactive shell; commands include help, exit.
  Activating Term::ShellKit::Commands
  Activating Term::ShellKit::Dev
  
  Term::ShellKit> require MyClass
  MyClass
  
  Term::ShellKit> show_package MyClass
  Package Stash for MyClass
  Subs:
    sub smee = "CODE(0x73fa4)"
    sub twiddle = "CODE(0xc8530)"

COMMANDS ^

The following commands are available.

require

Load a Perl module or library.

reload

Reload any Perl modules which have changed since they were last loaded.

You can use the shell reload command to read in changes to your modules while continuing to work in the same environment.

Start with the following code in MyObject.pm:

  package MyObject;
  
  sub new {
    my $class = shift;
    bless { }, $class;
  }

  1;

Then start your shell and load your module:

  ~> perl lib/Shell/Shell.pm
  Term::ShellKit: Starting interactive shell
  Term::ShellKit> require MyObject

You can now start creating instances of your class:

  Term::ShellKit> $example = MyObject->new()
  $example = MyObject->new(): MyObject=HASH(0x1e5118)

Your class doesn't do anything else yet, so trying to call other methods on your new object will result in an error:

  Term::ShellKit> $example->twiddle
  $example->twiddle: Failed.
    shell_cmd_method: 
    shell_cmd_eval: Can't locate object method "twiddle" via package "MyObject" at (eval 12) line 1.

Let's define that method -- leave the shell running, and add the following method to your package:

  sub twiddle {
    my $self = shift;
    return "Song and dance goes here...";
  }

Then return to the shell and run the "reload" command to load your changes. You can now start calling your new method, even on objects that were created earlier:

  Term::ShellKit> reload
  Term::ShellKit: reload MyObject.pm 
  Term::ShellKit> $example->twiddle
  $example->twiddle: Song and dance goes here...

Subsequent additions or revisions to the module will be available the next time you run the "reload" command. (Note that if you remove a method from your module code, it will not be deleted from the live workspace; you'll need to quit and restart the shell to achieve this.)

If there's an error in your code, you'll get a message similar to this when you try to reload:

  Term::ShellKit> reload
  reload: Failed.
    shell_cmd_method: Type of arg 1 to shift must be array (not return)
  at /tmp/MyObject.pm line 10, near ""Song and dance goes here...";"

To view the problematic line, you can copy and paste in the file and line number, taking advantage of the default alias that maps "at" to "show_file":

  Term::ShellKit> at /tmp/MyObject.pm line 10 
              > show_file /tmp/MyObject.pm line 10
              > show_file /tmp/MyObject.pm window 2 line 10

      my $self = shift
      return "Song and dance goes here...";
    }

If you need to see more of the code you can re-run the show_file command with a window argument that's larger than the default of 2, but that's generally enough to spot errors like semicolon missing from the above.

show_package

  > perl -Iblib/lib -MTerm::ShellKit -eshell "kit Dev"
  Term::ShellKit: Starting interactive shell; commands include help, exit.
  Activating Term::ShellKit::Commands
  Activating Term::ShellKit::Dev
  
  Term::ShellKit> show_package Carp
  Package Stash for Carp
  Scalars:
    $CarpLevel = "0"
    $MaxArgLen = "64"
    $MaxArgNums = "8"
    $MaxEvalLen = "0"
    $Verbose = "0"
  Arrays:
    @EXPORT = "confess, croak, carp"
    @EXPORT_FAIL = "verbose"
    @EXPORT_OK = "cluck, verbose"
    @ISA = "Exporter"
  Hashes:
    %EXPORT = "carp => 1, cluck => 1, confess => 1, croak => 1, verbose => 1"
    %EXPORT_FAIL = "&verbose => 1, verbose => 1"
  Subs:
    sub carp = "CODEREF"
    sub cluck = "CODEREF"
    sub confess = "CODEREF"
    sub croak = "CODEREF"
    sub export_fail = "CODEREF"
    sub longmess = "CODEREF"
    sub shortmess = "CODEREF"

  Term::ShellKit> exit

SEE ALSO ^

Term::ShellKit

syntax highlighting: