View on
MetaCPAN
Matthew Simon Cavalletto > Term-ShellKit-1.002 > ShellKit/LineBuffer.pm

Download:
Term-ShellKit-1.002.tar.gz

Annotate this POD

View/Report Bugs
Source  

EXAMPLES ^

Declaring a subroutine

In the below, I use the << notation to enter a multi-line block of Perl, terminated by a control-D.

You can then call any subroutines you've defined on the shell prompt line.

  ~> perl lib/Shell/Shell.pm
  Term::ShellKit: Starting interactive shell
  Term::ShellKit> <<
  
  sub count {
    my $count = shift;
    join(', ', ( 0 .. $count ) )
  }
  ^D
  
  Term::ShellKit> count(3)
  count(3): 0, 1, 2, 3
  Term::ShellKit> count(5)
  count(5): 0, 1, 2, 3, 4, 5

Declaring a shell command

To create a new shell command, define a function using the above << syntax.

You can then call those functions with space-separated arguments on the shell prompt line. These commands can use existing shell methods for further interaction with the user.

  ~> perl lib/Shell/Shell.pm
  Term::ShellKit: Starting interactive shell
  Term::ShellKit> <<
  
  sub do_count {
    my $count = shift || $Term::ShellKitInput->( 'do_count to: ' );
    $shell->shell_out_lines( join(', ', ( 0 .. $count ) ) );
  }
  ^D
  
  Term::ShellKit> do_count 3
  0, 1, 2, 3

  Term::ShellKit> do_count  
  do_count to: 3
  0, 1, 2, 3
syntax highlighting: