NAME

Synapse::CLI::Config::Object - base class for your configuration objects

SYNOPSIS

Step 1. Write one or more config 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__

Step 2. Write your application CLI accessor:

#!/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));

Step 3. Have fun on the CLI

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 

Class methods

Usage: cli type object-class object-method arg1 ... argN

$class->create ($name, $label);

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"

$class->new($name);

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.

$class->list();

Usage: cli type myclass list

Returns a list of object ids for this class.

$class->list_l();

Usage: cli type myclass list

Returns a list of object ids for this class, as well as the corresponding labels, separated with a CSV-style semicolumn.

$class->count();

usage: cli type myclass count

counts how many objects of myclass exist.

Instance methods

Usage: cli object-class object-id object-method arg1 ... argN

$self->set($attr, $stuff);

Usage: cli mytype myobject set foo "this is bar"

Sets $self->{foo} to "this is bar"

$self->del($attr);

Usage: cli mytype myobject del foo

Removes $self->{foo}

$self->list_push($attr, $stuff);

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.

$self->list_pop($attr)

Usage: cli mytype myobject list-pop foo

Makes $self->{foo} an empty list if not defined. Then pops the list.

$self->list_shift($attr)

Usage: cli mytype myobject list-shift foo

Makes $self->{foo} an empty list if not defined. Then shifts the list.

$self->list_unshift($attr, $stuff)

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".

$self->list_del($attr, $index)

Usage: cli mytype myobject list-del foo

Removes $self->{$attr}->{$index} from the list.

$self->list_add($attr, $index, $stuff)

Usage: cli mytype myobject list-add foo "this is stuff"

Adds "this is stuff" at position $index in $self->{$attr} list.

$self->set_add($attr, $stuff)

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.

$self->set_del($attr, $stuff)

Usage: cli mytype myobject set-del foo "this is stuff"

Removes "this is stuff" from the set.

$self->set_list($attr)

Usage: cli mytype myobject set-list foo

Lists all items in the set.

$self->label()

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.

$self->name()

Usage: cli mytype myobject name

Each object as a name. Returns it.

$self->show();

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.

$self->rename_to ($newname);

Usage: cli mytype foo rename-to bar

Changes the object 'name' attribute as well as file name on disk.

$self->copy_as ($newname);

Usage: cli mytype foo copy-as bar

Copies the object and names the copy $newname. Returns the newly copied object.

$self->remove();

Usage: cli mytype foo remove

Removes foo.

EXPORTS

none.

BUGS

Please report them to me. Patches always welcome...

AUTHOR

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.