Kevin Treleaven > Anansi-ComponentManager-0.10 > Anansi::ComponentManager

Download:
Anansi-ComponentManager-0.10.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.10   Source  

NAME ^

Anansi::ComponentManager - A base module definition for related process management.

SYNOPSIS ^

    package Anansi::ComponentManagerExample;

    use base qw(Anansi::ComponentManager);

    sub doSomethingElse {
        my ($self, $channel, %parameters) = @_;
    }

    Anansi::ComponentManager::addChannel(
        'Anansi::ComponentManagerExample',
        'SOME_MANAGER_CHANNEL' => Anansi::ComponentManagerExample->doSomethingElse
    );

    1;

    package Anansi::ComponentManagerExample::ComponentExample;

    use base qw(Anansi::Component);

    sub priority {
        my ($self, $channel, %parameters) = @_;
        my $PRIORITY = {
            'Anansi::ComponentManagerExample::AnotherComponentExample' => 'HIGHER',
            'Anansi::ComponentManagerExample::YetAnotherComponentExample' => 'LOWER',
            'Anansi::ComponentManagerExample::SomeOtherComponentExample' => 'SAME',
            'Anansi::ComponentManagerExample::ADifferentComponentExample' => 1,
            'Anansi::ComponentManagerExample::EtcComponentExample' => 0,
            'Anansi::ComponentManagerExample::AndSoOnComponentExample' => -1,
        };
        return $PRIORITY;
    }

    sub validate {
        my ($self, $channel, %parameters) = @_;
        return 1;
    }

    sub doSomething {
        my ($self, $channel, %parameters) = @_;
    }

    Anansi::Component::addChannel(
        'Anansi::ComponentManagerExample::ComponentExample',
        'PRIORITY_OF_VALIDATE' => Anansi::ComponentManagerExample::ComponentExample->priority
    );
    Anansi::Component::addChannel(
        'Anansi::ComponentManagerExample::ComponentExample',
        'VALIDATE_AS_APPROPRIATE' => Anansi::ComponentManagerExample::ComponentExample->validate
    );
    Anansi::Component::addChannel(
        'Anansi::ComponentManagerExample::ComponentExample',
        'SOME_COMPONENT_CHANNEL' => Anansi::ComponentManagerExample::ComponentExample->doSomething
    );

    1;

    package main;

    use Anansi::ComponentManagerExample;

    my $object = Anansi::ComponentManagerExample->new();
    my $component = $object->addComponent();
    my $result = $object->channel(
        $component,
        'SOME_COMPONENT_CHANNEL',
        someParameter => 'some data',
        anotherParameter => 'some more data',
    );

    my $another = Anansi::ComponentManagerExample->new(
        IDENTIFICATION => 'Another component',
    );
    $result = $object->channel(
        'Another component',
        'SOME_COMPONENT_CHANNEL',
        aParameter => 'more data?',
    );

    1;

DESCRIPTION ^

This is a base module definition for the management of modules that deal with related functionality. This management module provides the mechanism to handle multiple related functionality modules at the same time, loading and creating an object of the most appropriate module to handle each situation by using the VALIDATE_AS_APPROPRIATE and PRIORITY_OF_VALIDATE component channels. In order to simplify the recognition of related Anansi::Component modules, each component is required to have the same base namespace as it's manager.

METHODS ^

Anansi::Class

See Anansi::Class for details. A parent module of Anansi::Singleton.

DESTROY

See Anansi::Class::DESTROY for details. Overridden by Anansi::Singleton::DESTROY.

finalise

See Anansi::Class::finalise for details. A virtual method.

implicate

See Anansi::Class::implicate for details. A virtual method.

import

See Anansi::Class::import for details.

initialise

See Anansi::Class::initialise for details. Overridden by Anansi::ComponentManager::initialise. A virtual method.

new

See Anansi::Class::new for details.

old

See Anansi::Class::old for details.

used

See Anansi::Class::used for details.

uses

See Anansi::Class::uses for details.

using

See Anansi::Class::using for details.

Anansi::Singleton

See Anansi::Singleton for details. A parent module of Anansi::ComponentManager.

Anansi::Class

See Anansi::Class for details. A parent module of Anansi::Singleton.

DESTROY

See Anansi::Singleton::DESTROY for details. Overrides Anansi::Class::DESTROY.

fixate

See Anansi::Singleton::fixate for details. A virtual method.

new

See Anansi::Singleton::new for details. Overrides Anansi::Class::new.

reinitialise

See Anansi::Singleton::reinitialise for details. Overridden by Anansi::ComponentManager::reinitialise. A virtual method.

addChannel

    if(1 == Anansi::ComponentManager->addChannel(
        someChannel => 'Some::subroutine',
        anotherChannel => Some::subroutine,
        yetAnotherChannel => $AN_OBJECT->someSubroutine,
        etcChannel => sub {
            my $self = shift(@_);
        }
    ));

    if(1 == $OBJECT->addChannel(
        someChannel => 'Some::subroutine',
        anotherChannel => Some::subroutine,
        yetAnotherChannel => $AN_OBJECT->someSubroutine,
        etcChannel => sub {
            my $self = shift(@_);
        }
    ));
self (Blessed Hash or String, Required)

Either an object or a string of this namespace.

parameters (Hash, Required)

Named parameters where the key is the name of the channel and the value is either a namespace string or code reference to an existing subroutine or an anonymous subroutine definition.

Defines the responding subroutine for the named component manager channels.

addComponent

    my $identification = Anansi::ComponentManager->addComponent(
        undef,
        someParameter => 'some value'
    );
    if(defined($identification));

    my $identification = $OBJECT->addComponent(
        undef,
        someParameter => 'some value'
    );
    if(defined($identification));

    my $identification = Anansi::ComponentManager->addComponent(
        'some identifier',
        someParameter => 'some value'
    );
    if(defined($identification));

    my $identification = $OBJECT->addComponent(
        'some identifier',
        someParameter => 'some value'
    );
    if(defined($identification));
self (Blessed Hash or String, Required)

An object or string of this namespace.

identification (String, Required)

The name to associate with the component.

parameters (Scalar or Array, Optional)

The list of parameters to pass to the VALIDATE_AS_APPROPRIATE channel of every component module found on the system.

Creates a new component object and stores the object for indirect interaction by the implementer of the component manager. A unique identifier for the object may either be supplied or automatically generated and is returned as a means of referencing the object.

Note: The process of selecting the component to use requires each component to validate it's own appropriateness. Therefore this process makes use of a VALIDATE_AS_APPROPRIATE component channel which is expected to return either a 1 (one) or a 0 (zero) representing appropriate or inappropriate. If this component channel does not exist it is assumed that the component is not designed to be implemented in this way. A component may also provide a PRIORITY_OF_VALIDATE component channel to aid in validating where multiple components may be appropriate to different degrees. If this component channel does not exist it is assumed that the component has the lowest priority.

channel

    Anansi::ComponentManager->channel('Anansi::ComponentManager::Example');

    $OBJECT->channel();

    Anansi::ComponentManager->channel(
        'Anansi::ComponentManager::Example',
        'someChannel',
        someParameter => 'something'
    );

    $OBJECT->channel('someChannel', someParameter => 'something');
self (Blessed Hash or String, Required)

An object or string of this namespace.

channel (String, Optional)

The name that is associated with the component's channel.

parameters (Scalar or Array, Optional)

The list of parameters to pass to the component's channel.

Either returns an array of the available channels or passes the supplied parameters to the named channel. Returns undef on error.

component

    my $returned;
    my $channels = Anansi::ComponentManager->component($component);
    if(defined($channels)) {
        foreach my $channel (@{$channels}) {
            next if('SOME_CHANNEL' ne $channel);
            $returned = Anansi::ComponentManager->component(
                $component,
                $channel,
                anotherParameter => 'another value'
            );
        }
    }

    my @returned;
    $OBJECT->addComponent(undef, someParameter => 'some value');
    my $components = $OBJECT->component();
    if(defined($components)) {
        foreach my $component (@{$components}) {
            my $channels = $OBJECT->component($component);
            if(defined($channels)) {
                foreach my $channel (@{$channels}) {
                    next if('SOME_CHANNEL' ne $channel);
                    push(@returned, $OBJECT->component(
                        $component,
                        $channel,
                        anotherParameter => 'another value'
                    ));
                }
            }
        }
    }
self (Blessed Hash or String, Required)

An object or string of this namespace.

identification (String, Optional)

The name associated with the component.

channel (String, Optional)

The name that is associated with the component's channel.

parameters (Scalar or Array, Optional)

The list of parameters to pass to the component's channel.

Either returns an array of all of the available components or an array of all of the channels available through an identified component or interacts with an identified component using one of it's channels. Returns an undef on failure.

componentIdentification

    my $identification = Anansi::ComponentManager->componentIdentification();

    my $alias = 'An identifying phrase';
    my $identification = $OBJECT->componentIdentification($alias);
    if(defined($identification)) {
        print 'The "'.$alias.'" component already exists with the "'.$identification.'" identification.'."\n";
    }
self (Blessed Hash, Required)

An object of this namespace.

identification (String, Optional)

A component identification.

Either generates a volatile 20 (twenty) digit identification string that is unique within the executing script or determines whether a component exists with the specified identification. Returns the unique identification string on success or an undef on failure.

components

    my $components = Anansi::ComponentManager->components();
    if(ref($components) =~ /^ARRAY$/i) {
        foreach my $component (@{$components}) {
        }
    }

    my $components = Anansi::ComponentManager::components('Some::Namespace');
    if(ref($components) =~ /^ARRAY$/i) {
        foreach my $component (@{$components}) {
        }
    }

    my $components = $OBJECT->components();
    if(ref($components) =~ /^ARRAY$/i) {
        foreach my $component (@{$components}) {
        }
    }
self (Blessed Hash or String, Required)

An object or string of this namespace.

Either returns an array of all of the available components or an array containing the current component manager's components.

initialise

Overrides Anansi::Class::initialise.

self (Blessed Hash, Required)

An object of this namespace.

parameters (Hash, Optional)

Named parameters supplied to the Anansi::Singleton::new method.

IDENTIFICATION (String, Optional)

A unique component identification.

Enables the conglomeration of Anansi::Singleton::new and Anansi::ComponentManager::addComponent through a specified IDENTIFICATION parameter. Called just after module instance object creation.

priorities

    my $priorities = $self->priorities();
    if(defined($priorities)) {
        for(my $priority = $priorities; -1 < $priority; $priority--) {
            my $components = $self->priorities(
                PRIORITY => $priority,
            );
            next if(!defined($components));
            foreach my $component (@{$components}) {
            }
        }
    }
self (Blessed Hash or String, Required)

An object or string of this namespace.

parameters (Hash, Optional)

Named parameters.

PARAMETERS (Array or Scalar, Optional)

An array or single value containing the parameters to pass to the PRIORITY_OF_VALIDATE component channel.

PRIORITY (String, Optional)

Either a component namespace or a priority value of 0 (zero) or greater where 0 (zero) represents the lowest priority.

Either returns the highest component priority, the list of all the component namespaces that have the component priority supplied as the PRIORITY parameter or the component priority of the component given it's namespace supplied as the PRIORITY parameter.

reinitialise

Overrides Anansi::Singleton::reinitialise.

self (Blessed Hash, Required)

An object of this namespace.

parameters (Hash, Optional)

Named parameters supplied to the Anansi::Singleton::new method.

IDENTIFICATION (String, Optional)

A unique component identification.

Enables the conglomeration of Anansi::Singleton::new and Anansi::ComponentManager::addComponent through a specified IDENTIFICATION parameter. Called just after module instance object creation.

removeChannel

    if(1 == Anansi::ComponentManager::removeChannel(
        'Anansi::ComponentManagerExample',
        'someChannel',
        'anotherChannel',
        'yetAnotherChannel',
        'etcChannel'
    ));

    if(1 == $OBJECT->removeChannel(
        'someChannel',
        'anotherChannel',
        'yetAnotherChannel',
        'etcChannel'
    ));
self (Blessed Hash or String, Required)

An object or string of this namespace.

parameters (Scalar or Array, Required)

The channels to remove.

Undefines the responding subroutine for the named component manager's channels.

removeComponent

    if(1 == Anansi::ComponentManager::removeComponent(
        'Anansi::ComponentManagerExample',
        'someComponent',
        'anotherComponent',
        'yetAnotherComponent',
        'etcComponent'
    ));

    if(1 == $OBJECT->removeComponent(
        'someComponent',
        'anotherComponent',
        'yetAnotherComponent',
        'etcComponent'
    ));
self (Blessed Hash or String, Required)

An object or string of this namespace.

parameters (Array, Required)

A string or array of strings containing the name of a component.

Releases a named component instance for garbage collection. Returns a 1 (one) or a 0 (zero) representing success or failure.

NOTES ^

This module is designed to make it simple, easy and quite fast to code your design in perl. If for any reason you feel that it doesn't achieve these goals then please let me know. I am here to help. All constructive criticisms are also welcomed.

AUTHOR ^

Kevin Treleaven <kevin AT treleaven DOT net>

syntax highlighting: