Synapse::CLI::Config::Object - base class for your configuration objects
package My::Config::User; use base qw /Synapse::CLI::Config::User/; use Synapse::CLI::Config; use strict; use warnings; # optional code goes here 1; __END__
#!/usr/bin/perl # this is myapp-cli. It should be installed in /usr/local/bin/myapp-cli use Synapse::CLI::Config; use YAML::XS; use warning; use strict; $Synapse::CLI::Config::BASE_DIR = "/etc/myapp"; $Synapse::CLI::Config::ALIAS->{type} = 'Synapse::CLI::Config::Type'; $Synapse::CLI::Config::ALIAS->{user} = 'MyAPP::User'; print Dump (Synapse::CLI::Config::execute (@ARGV));
myapp-cli type user create c-hiver "Clementine Hiver" myapp-cli user chiver set password moncontenkite myapp-cli user chiver set-add permission watchtv myapp-cli user chiver set-add permission playoncomputer myapp-cli user chiver set-add permission readbooks myapp-cli user chiver show
Usage: cli type object-class object-method arg1 ... argN
Usage: cli type mytype create foo "This is a beautiful Foo"
Creates an object of type $class of name $name. $name will be the object file name on disk. Allowed names are /^[a-z0-9-_]+$/. If no 'name' is supplied, $class->create() provides one.
Optionally, sets label to "This is a beautiful Foo", which is shorter than doing:
cli type mytype create foo cli mytype foo set label "This is a beautiful Foo"
This is one of the few methods which is NOT to be used on the CLI (although you could since "cli myclass myid show" is logically equivalent to the less intuitive "cli type myclass new myid").
Builds and returns object of type $class with name $name.
Usage: cli type myclass list
Returns a list of object ids for this class.
Returns a list of object ids for this class, as well as the corresponding labels, separated with a CSV-style semicolumn.
usage: cli type myclass count
counts how many objects of myclass exist.
Usage: cli object-class object-id object-method arg1 ... argN
Usage: cli mytype myobject set foo "this is bar"
Sets $self->{foo} to "this is bar"
Usage: cli mytype myobject del foo
Removes $self->{foo}
Usage: cli mytype myobject list-push foo "this is bar"
Makes $self->{foo} an empty list if not defined. Adds "this is bar" to the list.
Usage: cli mytype myobject list-pop foo
Makes $self->{foo} an empty list if not defined. Then pops the list.
Usage: cli mytype myobject list-shift foo
Makes $self->{foo} an empty list if not defined. Then shifts the list.
Usage: cli mytype myobject list-unshift foo "this is bar"
Makes $self->{foo} an empty list if not defined. Then unshifts the list with "this is bar".
Usage: cli mytype myobject list-del foo
Removes $self->{$attr}->{$index} from the list.
Usage: cli mytype myobject list-add foo "this is stuff"
Adds "this is stuff" at position $index in $self->{$attr} list.
Usage: cli mytype myobject set-add foo "this is stuff"
Treats $self->{$attr} as a set (creating it if needed, using a hash ref), and adds "this is stuff" to the set.
Usage: cli mytype myobject set-del foo "this is stuff"
Removes "this is stuff" from the set.
Usage: cli mytype myobject set-list foo
Lists all items in the set.
Usage: cli mytype myobject label
Each object as an optional label associated with it, this method returns it. Returns name() is label is not defined.
Usage: cli mytype myobject name
Each object as a name. Returns it.
Usage: cli mytype myobject show
From Perl, this method is not very interesting since it just returns $self. But on the CLI, will display a YAML representation of $self, which is handy to view your objects.
Usage: cli mytype foo rename-to bar
Changes the object 'name' attribute as well as file name on disk.
Usage: cli mytype foo copy-as bar
Copies the object and names the copy $newname. Returns the newly copied object.
Usage: cli mytype foo remove
Removes foo.
none.
Please report them to me. Patches always welcome...
Jean-Michel Hiver, jhiver (at) synapse (dash) telecom (dot) com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Synapse::CLI::Config, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Synapse::CLI::Config
CPAN shell
perl -MCPAN -e shell install Synapse::CLI::Config
For more information on module installation, please visit the detailed CPAN module installation guide.