The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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 });
 ...

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