The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Anansi::Actor - A dynamic usage module definition

SYNOPSIS

    use Anansi::Actor;
    my $object = Anansi::Actor->new(
        PACKAGE => 'Anansi::Example',
    );
    $object->someSubroutine() if(defined($object));

    use Anansi::Actor;
    use Data::Dumper qw(Dumper);
    my %modules = Anansi::Actor->modules();
    if(defined($modules{DBI})) {
        Anansi::Actor->new(
            PACKAGE => 'DBI',
        );
        print Data::Dumper::Dumper(DBI->available_drivers());
    }

    use Anansi::Actor;
    use Data::Dumper qw(Dumper);
    if(1 == Anansi::Actor->modules(
        PACKAGE => 'DBI',
    )) {
        Anansi::Actor->new(
            PACKAGE => 'DBI',
        );
        print Data::Dumper::Dumper(DBI->available_drivers());
    }

DESCRIPTION

This is a dynamic usage module definition that manages the loading of a required namespace and blessing of an object of the namespace as required. Uses Fcntl, File::Find, File::Spec::Functions and FileHandle.

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. A virtual method.

new

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

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::Actor.

Anansi::Class

See Anansi::Class for Class. 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. Overridden by Anansi::Actor::new.

reinitialise

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

modules

    my %MODULES = $object->modules();

    use Anansi::Actor;
    my %MODULES = Anansi::Actor->modules(
        INTERVAL => 3600,
    );

    if(1 == $object->modules(
        PACKAGE => [
            'Some::Module::Namespace',
            'Another::Module::Namespace',
            'Yet::Another::Module::Namespace'
        ],
    )) {
        print 'The modules have been found.'."\n";
    }

    use Anansi::Actor;
    my $MODULE = 'Some::Module::Namespace';
    if(0 == Anansi::Actor->modules(
        PACKAGE => $MODULE,
        INTERVAL => 43200,
    )) {
        print 'The "'.$MODULE.'" module has not been found.'."\n";
    }
self (Blessed Hash, Required)

An object of this namespace.

parameters (Hash)

Named parameters.

INTERVAL (String, Optional)

Specifies a refresh interval in seconds. Defaults to 86400 seconds (1 day).

PACKAGE (Array or String, Optional)

An ARRAY of module namespaces or a module namespace to find on the operating system.

Builds a HASH of all the modules and their paths that are available on the operating system and either returns the module HASH or a 1 (one) on success and a 0 (zero) on failure when determining the existence of the modules that are specified in the PACKAGE parameter. A temporary file "Anansi-Actor.#" will be created if at all possible to improve the speed of this subroutine by storing the module HASH. The temporary file will automatically be updated when this subroutine is subsequently run when the number of seconds specified in the INTERVAL parameter or a full day has passed. Deleting the temporary file will also cause an update to occur.

new

    my $object = Anansi::Actor->new(
        PACKAGE => 'Anansi::Example',
    );
class (Blessed Hash or String, Required)

Either an object or a string of this namespace.

parameters (Hash)

Named parameters.

BLESS (String, Optional)

The name of the subroutine within the namespace that creates a blessed object of the namespace. Defaults to "new".

IMPORT (Array, Optional)

An array of the names to import from the loading module.

PACKAGE (String, Required)

The namespace of the module to load.

PARAMETERS (Array or Hash, Optional)

Either An array or a hash of the parameters to pass to the blessing subroutine.

Overrides (Anansi::Singleton::new). Instantiates an object instance of a dynamically loaded module.

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>