Gabriel Horner > Fry-Shell-0.15 > Fry::Cmd



Annotate this POD


New  1
Open  0
View/Report Bugs


Fry::Cmd - Class for shell commands.


A command object has the following attributes:

        Attributes with a '*' next to them are always defined.

        *id($): Unique id which is usually the name of subroutine associated with it.
        a($): Command alias.
        d($): Description help for command.
        u($): Usage help for command.
        *_sub(\&): Coderef which points to subroutine to execute when command is
                run. If not explicitly set,it's set to a default of 'sub {$o->$cmd(@_) }'
                where $cmd is the command's id.
        arg($): Use this attribute if you want to validate the command's
                arguments. Describe expected input type with a data structure symbol and
                name. See Argument Checking below.

Argument Checking ^

To validate your command's arguments you define an arg attribute. This attribute describes the expected input with a symbol and a unique name for argument type. Currently valid symbols are $,%,@ to indicate scalar,hash and array data structures respectively. An expected hash of a type means that its keys must be of that type. Each input type must have a test subroutine of the name t_$name where $name is its name. Tests are called by the shell object. Tests that pass return a 1 and those that fail return 0.

For example, lets look at the command printVarObj in Fry::Lib::Default. This command has an arg value of '@var'. This means that the arguments are expected to be an array of type var. The var type's test subroutine is &t_var and it is via this test that printVarObj's arguments will be validated.

The arg attribute also offers the possibility to autocomplete a command's arguments with the plugin Fry::ReadLine::Gnu. For autocompletion to work you must have a subroutine named cmpl_$name where $name is the name of the user-defined type. The subroutine is called by the shell object and should return a list of possible completion values. The autocompletion subroutine for the previous subrouting would be cmpl_var.

You can turn off argument checking in the shell with the skiparg option.


        argAlias($cmd,$args): Aliases a command's arguments by modifying the given arguments
                reference with the subroutine specified in the 'aa' attribute.
        checkArgs($cmd,@args): If args attribute is defined runs tests on user-defined arguments.
                If tests don't pass then warning is thrown and command is skipped.
        runCmd($cmd,@args): Runs command with given arguments. Checks for aliases.


Me. Gabriel that is. I welcome feedback and bug reports to cldwalker AT chwhat DOT com . If you like using perl,linux,vim and databases to make your life easier (not lazier ;) check out my website at


Copyright (c) 2004, Gabriel Horner. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: