| App-Context documentation | Contained in the App-Context distribution. |
App::ValueDomain - Interface for sharing data between processes
use App;
$context = App->context();
$dom = $context->service("ValueDomain");
$dom = $context->value_domain();
A ValueDomain service represents a single hash in which scalars or deep references may be stored (basically an MLDBM).
The following classes might be a part of the ValueDomain Class Group.
A ValueDomain service represents an array of values and the labels by which those values may be displayed.
* Throws: App::Exception::ValueDomain * Since: 0.01
* Signature: $values = $dom->values();
* Signature: $values = $dom->values($values_string);
* Param: $values_string string
* Return: $values HASH
* Throws: App::Exception::ValueDomain
* Since: 0.01
Sample Usage:
$context = App->context();
$dom = $context->value_domain("product_type");
$values = $dom->values();
print @$values, "\n";
* Signature: $labels = $dom->labels();
* Signature: $labels = $dom->labels($values_string);
* Param: $values_string string
* Return: $labels HASH
* Throws: App::Exception::ValueDomain
* Since: 0.01
Sample Usage:
$context = App->context();
$dom = $context->value_domain("product_type");
$labels = $dom->labels();
print %$labels, "\n";
* Signature: ($values, $labels) = $dom->values_labels();
* Signature: ($values, $labels) = $dom->values_labels($values_string);
* Param: $values_string string
* Return: $values HASH
* Return: $labels HASH
* Throws: App::Exception::ValueDomain
* Since: 0.01
Sample Usage:
$context = App->context();
$dom = $context->value_domain("product_type");
($values, $labels) = $dom->values_labels();
foreach $value (@$values) {
print "$value => $labels->{$value}\n";
}
* Signature: $label = $dom->get_label($value);
* Param: $value string
* Return: $label string
Sample Usage:
$context = App->context();
$dom = $context->value_domain("product_type");
$label = $dom->get_label($value);
The _load() method is called to get the list of valid values in a data domain and the labels that should be used to represent these values to a user.
* Signature: $self->_load()
* Signature: $self->_load($values_string)
* Param: $values_string string
* Return: void
* Throws: App::Exception
* Since: 0.01
Sample Usage:
$self->_load();
Returns 'ValueDomain';
* Signature: $service_type = App::ValueDomain->service_type();
* Param: void
* Return: $service_type string
* Since: 0.01
$service_type = $sdata->service_type();
* Author: Stephen Adkins <spadkins@gmail.com> * License: This is free software. It is licensed under the same terms as Perl itself.
App::Context|App::Context,
App::Service|App::Service
| App-Context documentation | Contained in the App-Context distribution. |
############################################################################# ## $Id: ValueDomain.pm 12574 2009-03-06 17:21:06Z spadkins $ ############################################################################# package App::ValueDomain; $VERSION = (q$Revision: 12574 $ =~ /(\d[\d\.]*)/)[0]; # VERSION numbers generated by svn use App; use App::Service; @ISA = ( "App::Service" ); use strict;
############################################################################# # CLASS GROUP #############################################################################
############################################################################# # CLASS #############################################################################
############################################################################# # PUBLIC METHODS #############################################################################
############################################################################# # values() #############################################################################
sub values { &App::sub_entry if ($App::trace); my ($self, $values_string) = @_; $self->_load($values_string); &App::sub_exit($self->{values}) if ($App::trace); return($self->{values}); } ############################################################################# # labels() #############################################################################
sub labels { my ($self, $values_string) = @_; &App::sub_entry if ($App::trace); $self->_load($values_string); &App::sub_exit($self->{labels}) if ($App::trace); return($self->{labels}); } ############################################################################# # values_labels() #############################################################################
sub values_labels { my ($self, $values_string) = @_; &App::sub_entry if ($App::trace); $self->_load($values_string); &App::sub_exit($self->{values}, $self->{labels}) if ($App::trace); return($self->{values}, $self->{labels}); } ############################################################################# # get_label() #############################################################################
sub get_label { my ($self, $value) = @_; &App::sub_entry if ($App::trace); $self->_load() if (!$self->{labels}); my $labels = $self->{labels}; my ($label); if (exists $labels->{$value}) { $label = $labels->{$value} || $value; } else { $label = $self->_load_label($value); $labels->{$value} = $label; } &App::sub_exit($label) if ($App::trace); return($label); } ############################################################################# # _load() #############################################################################
sub _load { &App::sub_entry if ($App::trace); my ($self, $values_string) = @_; $self->{values} = [] if (!$self->{values}); my $values = $self->{values}; $self->{labels} = {} if (!$self->{labels}); my $labels = $self->{labels}; foreach my $value (@$values) { $labels->{$value} = $value if (!defined $labels->{$value}); } &App::sub_exit() if ($App::trace); } sub _load_label { my ($self, $value) = @_; &App::sub_entry if ($App::trace); my $label = undef; &App::sub_exit($label) if ($App::trace); return($label); } sub unload { &App::sub_entry if ($App::trace); my ($self) = @_; my $class = ref($self); if ($class ne "App::ValueDomain") { delete $self->{values}; delete $self->{labels}; delete $self->{values_string}; } &App::sub_exit() if ($App::trace); } ############################################################################# # PROTECTED METHODS #############################################################################
############################################################################# # Method: service_type() #############################################################################
sub service_type () { 'ValueDomain'; }
1;