Context::Set - A Contextual preference/configuration holder.
Version 0.01
Context is a preference manager that aims at solving the problem of storing configuration properties accross an ever growing collection of contexts that often characterises enterprise systems.
For instance, you might want to have a 'page colour' setting that is global to your system, but allow users to choose their own if they want.
Additionally, you might want to allow your users to specifically define a page color when they view a specific 'list of stuff' in your system. Or allow the system to specify a page color for all lists, or a specific one to certain lists, but still allowing users to override that.
Multiplication of preferences and management of their priorities can cause a lot of confusion and headaches. This module is an attempt to help you to keep those things tidy and in control.
To use Context, the best way is probably to use a Context::Set::Manager that will keep your contexts tidy for you.
my $cm = Context::Set::Manager->new(); $cm->universe()->set_property('page.colour' , 'blue'); my $users = $cm->restrict('users'); $users->set_property('page.colour', 'green'); my $user1 = $cm->restrict('users' , 1); $user1->set_property('page.colour' , 'red'); $user1->get_property('page.colour'); # red my $user2 = $cm->restrict('users' , 2); $user2->get_property('page.colour') ; # green my $lists = $cm->restrict('lists'); my $list1 = $cm->restrict->($lists, 1); my $u1l1 = $cm->unite($user1, list1); $u1l1->set_property('page.colour', 'purple'); $u1l1->get_property('page.colour'); # purple my $u1l2 = $cm->unite($user1 , $cm->restrict('lists' , 2)); $u1l2->get_property('page.colour') ; # red
To make context properties persistent accross instances of your application, see Context::Set::Manager
Returns the fully qualified name of this context. The fullname of a context identifies the context in the UNIVERSE in a unique manner.
Returns the local name of this context. fullname is more useful.
Returns true if this storage is inside a context matching the given name.
Note that this excludes this Context::Set
Usage:
if( $this->is_inside('users') ){ ... }
Returns true if there is a property of this name in this context.
if( $this->has_property('pi') ){ ... }
Gets the property that goes by the given name. Dies if no property with the given name can be found.
my $pi = $this->get_property('pi');
Sets the given property to the given value. Never dies.
$this->set_property('pi' , 3.14159 ); $this->set_property('fibo', [ 1, 2, 3, 5, 8, 12, 20 ]);
Deletes the given property from this context. Dies if no property with this name exists.
Returns the current value of this property (so you have a chance to look at it a last time before it goes away).
my $deleted_value = $this->delete_property('pi');
Returns the context holding the given property or undef if none is found.
if( my $holder_context = $context->lookup('pi') ){ ## $holder_context is the first context holding this property. }
Returns the Context::Set::Union of this and the other context.
usage:
my $u = $this->unite($other_context);
Produces a new Context::Set::Restriction of this one.
## Restrict to all users. my $context = $this->restrict('users'); ## Further restriction to user 1 $context = $context->restrict('1');
Jerome Eteve, <jerome.eteve at gmail.com>
<jerome.eteve at gmail.com>
Please report any bugs or feature requests to bug-context at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Context::Set. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-context at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Context::Set
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Context::Set
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Context::Set
CPAN Ratings
http://cpanratings.perl.org/d/Context::Set
Search CPAN
http://search.cpan.org/dist/Context/
Copyright 2012 Jerome Eteve.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Context::Set, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Context::Set
CPAN shell
perl -MCPAN -e shell install Context::Set
For more information on module installation, please visit the detailed CPAN module installation guide.