Jerome Eteve > Context-Set-0.02 > Context::Set::Manager

Download:
Context-Set-0.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

Context::Set::Manager - A manager for your Context::Sets

SYNOPSIS ^

  my $cm = Context::Set::Manager->new();

  my $users = $cm->restrict('users');
  $users->set_property('page.color' , 'blue');

  my $user1 = $cm->restrict('users' , 1 );

  ## OR

  $user1 = $users->restrict(1);

  $user1->set_property('page.color' , 'pink');

  $user1->get_property('page.color'); # pink.

  $cm->restrict('users' , 2)->get_property('page.color'); # blue

  ## OR

  $users->restrict(2)->get_property('page.color'); # blue

PERSISTENCE

Give your manager a Context::Set::Storage subclass at build time. So all managed context persist using this storage.

For example:

 my $cm = Context::Set::Manager->new({ storage => an instance of Context::Set::Storage::DBIC });
 ...

CONCURRENCY

If your manager lives in a process and a stored value is changed by another process, you can set this to autoreload the managed contexts on access. Use the option autoreload for that (Note that it only makes sense with a Persistent storage (see PERSISTENCE):

 my $cm = Context::Set::Manager->new({ storage => an instance of Context::Set::Storage::DBIC,
                                       autoreload => 1 });

Note: Performance might be impacted. This will be solved in the future by implementing cachable storages.

manage

Adds the given Context::Set to this manager (in case it was built outside).

Note that if a context with an identical fullname is already there, it will return it. This is to ensure the unicity of contexts within the manager.

Usage:

  $context = $cm->manage($context);

restrict

Builds a restriction of the universe or of the given context.

 Usage:

  my $users = $cm->restrict('users'); ## This restricts the UNIVERSE
  my $user1 = $cm->restrict($users, 1); ## This restricts the users.
  my $user1 = $cm->restrict('users' , 1); ## Same thing
  my $user1 = $cm->restruct('UNIVERSE/users' , 1); ## Same thing.

unite

Returns the union of the given Context::Sets. You need to give at least two contexts.

Context::Sets can be given by name or by references.

Usage:

  my $ctx = $this->unite('context1' , $context2);
  my $ctx = $this->unite($context1, 'context2', $context3);

find

Finds one context by the given name (local or full). Returns undef if nothing is found.

If the name only match a local name and there's more that one Context::Set with this name, the latest one will be returned.

Usage:

 if( my $context = $this->find('a_name') ){

 $this->find('UNIVERSE/name1/name2');

 if( $this->find($a_context) ){ ## Is this context in this manager
syntax highlighting: