Connector
view release on metacpan or search on metacpan
lib/Connector.pm view on Meta::CPAN
=head2 get
Basic method to obtain a scalar value at the leaf of the config tree.
my $value = $connector->get('smartcard.owners.tokenid.bob');
Each implementation must also accept an arrayref as path. The path is
contructed from the elements. The default behaviour allows strings using
the delimiter character inside an array element. If you want each array
element to be parsed, you need to pass "RECURSEPATH => 1" to the constructor.
my $value = $connector->get( [ 'smartcard','owners','tokenid','bob.builder' ] );
Some implementations accept control parameters, which can be passed by
I<params>, which is a hash ref of key => value pairs.
my $value = $connector->get( 'smartcard.owners.tokenid.bob' , { version => 1 } );
=head2 get_list
This method is only valid if it is called on a "n-1" depth node representing
an ordered list of items (array). The return value is an array with all
values present below the node.
my @items = $connector->get_list( 'smartcard.owners.tokenid' );
=head2 get_size
This method is only valid if it is called on a "n-1" depth node representing
an ordered list of items (array). The return value is the number of elements
in this array (including undef elements if they are explicitly given).
my $count = $connector->get_size( 'smartcard.owners.tokens.bob' );
If the node does not exist, 0 is returned.
=head2 get_hash
This method is only valid if it is called on a "n-1" depth node representing
a key => value list (hash). The return value is a hash ref.
my %data = %{$connector->get_hash( 'smartcard.owners.tokens.bob' )};
=head2 get_keys
This method is only valid if it is called on a "n-1" depth node representing
a key => value list (hash). The return value is an array holding the
values of all keys (including undef elements if they are explicitly given).
my @keys = $connector->get_keys( 'smartcard.owners.tokens.bob' );
If the node does not exist, an empty list is returned.
=head2 get_reference [deprecated]
Rarely used, returns the value of a reference node. Currently used by
Connector::Multi in combination with Connector::Proxy::Config::Versioned
to create internal links and cascaded connectors. See Connector::Multi
for details.
=head2 set
The set method is a "all in one" implementation, that is used for either type
of value. If the value is not a scalar, it must be passed by reference.
$connector->set('smartcard.owners.tokenid.bob', $value, $params);
The I<value> parameter holds a scalar or ref to an array/hash with the data to
be written. I<params> is a hash ref which holds additional parameters for the
operation and can be undef if not needed.
=head1 STRUCTURAL METHODS
=head2 get_meta
This method returns some structural information about the current node as
hash ref. At minimum it must return the type of node at the current path.
Valid values are I<scalar, list, hash, reference>. The types match the
accessor methods given above (use C<get> for I<scalar>).
my $meta = $connector->get_meta( 'smartcard.owners' );
my $type = $meta->{TYPE};
When you call a proxy connector without sufficient arguments to perform the
query, you will receive a value of I<connector> for type. Running a get_*
method against such a node will cause the connector to die!
=head2 cleanup
Advise connectors to close, release or flush any open handle or sessions.
Should be called directly before the program terminates. Connectors might
be stale and not respond any longer after this was called.
=head1 IMPLEMENTATION GUIDELINES
You SHOULD use the _node_not_exists method if the requested path does not exist
or has an undefined value. This will internally take care of the I<die_on_undef>
setting and throw an exception or return undef. So you can just write:
if (path not exists || not defined val) {
return $self->_node_not_exists( pathspec );
}
As connectors are often used in eval constructs where the error messages
are swallowed you SHOULD log a verbose error before aborting with
die/confess. You can use the _log_and_die method for this purpose. It will
send a message to the logger on error level before calling "die $message".
=head2 path building
You should always pass the first parameter to the private C<_build_path>
method. This method converts any valid path spec representation to a valid
path. It takes care of the RECURSEPATH setting and returns the path
elements as list.
=head2 Supported methods
( run in 0.969 second using v1.01-cache-2.11-cpan-df04353d9ac )